Node-RED nodes for hubitat

I am not sure if you can handle this with the request node, but here is something that might be useful. I use this bash script to backup my hubitat. I do that even though I have a username and password on the hub. Now the trick is that I have to make 2 calls. The first one is to the login page sending the username and password and then saving the cookie file, then the second goes to the download page passing the cookie file which then gets the second page because the cookie tells the hub that I am logged in. It works great with curl and this script and might be possible to adapt:

#!/bin/bash

# Main Ashmont Hub Info

he_login=Sample_UserName

he_passwd=Made_Up_Password

he_ipaddr=192.168.86.110

# storage location for Main Ashmont Hub

backupdir='/CSbackup/Ashmont/'

cookiefilename='HubitatCookie.txt'

cookiefile=$backupdir$cookiefilename

# Getting the cookie using the username and password (only needed because this hub is password protected)

curl -k -c $cookiefile -d username=$he_login -d password=$he_passwd https://$he_ipaddr/login

# Downloading the file

curl -k -sb $cookiefile https://$he_ipaddr/hub/backup | grep data-fileName | grep download | sed 's/<td class=\"mdl-data-table__cell--non-numeric\"><a class=\"download mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect\" href=\"#\"  data-fileName=\"/\ /' | sed 's/\">Download<\/a><\/td>/\ /' | sed 's/ //g' | tail -1 | xargs -I @ curl -k -sb $cookiefile https://$he_ipaddr/hub//backupDB?fileName=@ -o $backupdir$(date +%Y-%m-%d-%H%M)-extract-from-Main-of-@

# Remove the cookie in case it might cause confusion with the other hubs

rm $cookiefile
1 Like

Yep - I use a similar script but have converted it into a MacOS Automator app. I tried a couple of different ways in Nodered but could not figure out how to save the cookie file. I tried configuring the http request node with username/password and “keep session alive” checked but that did not work.

I must have missed - what kind of auth are you using? The http node can handle these:

I was trying with basic - not sure what Hubitat uses though.

So basic did not work with the HTTP Node?

Did you try the old:

username:password@yourhubitaturl/etc

1 Like

Hubitat uses that login to pull down a cookie, which is then used when navigating to other pages. You'll have to store that cookie and pass it with subsequent requests.

I haven't done it, but just using basic auth isn't going to work.

I am using node-red-contrib-alexa-remote2 to start playing music from my library as part of our good night routine. After a 90 min timer it is supposed to stop. I know the timer is working and I have it going into a Routine Stop Node, but this does not stop the music playing. Am I using this wrong?

Yep - it works with the curl script because it can store the cookie as it apparently has a "cookie engine" built in https://curl.haxx.se/docs/http-cookies.html.

Unless there is something like that in Node-red, I guess it's not going to work

Did not work - apparently need to store and use cookies :man_shrugging:t3:

1 Like

Here, check this out. Maybe this can help you.

1 Like

I'd actually found this before but I'd missed how the session cookies were used, so THANK YOU! I can now log in and Nodered gets the session ID!!

{"HUBSESSION":{"Path":"/","value":"node046d9yc33cfns1r5cdxwomfchw37.node0"}}

Now to figure out how to use it in the subsequent flows :thinking:

3 Likes

I am not sure what you are using to do your "Stop" but I think you should be using the Music Command --> Pause command. It seems to work for me.

I'm not sure that stop and pause are the same thing. If I tell alexa to play music it does. But telling it to pause is not the same as stop.

What are you trying to do though? Just stop the speaker from playing music or do something more? My understanding is that the only difference between stop and pause is that pause allows for resuming of the same song where stop generally does not.

I like this idea of testing that things actually work. Do you do a further test to make sure it's not a LAN problem, or do you basically make the assumption that your LAN is fine, and therefore the hub must have an issue?

I also ping it to try and trap a network issue.

1 Like

I finally got a Flow online after 3.6k posts! Making use of NR to replace the built-in HE zwave poller that I found out stops for no reason. Really weird.

Next is to try and replicate my webCoRE pistons.

What you'll find is that some (really, most in my opinion) things are super simple in Node-red, and others are a little more work (nothing is perfect for all needs/uses).

Iterative/looping logic for instance can take some thought to do in node-red. Perfectly doable, but because flows are linear in nature (in general) you sometimes have to think about how to pass values between iterations, etc.

Other things that seem to trip up new users is AND and OR logic. AND is easy to do with daisy chained device/switch nodes (or boolean logic nodes, or function nodes, or join nodes + switch/function node, if that is your thing), an OR is just independent device/switch nodes going to the same downstream node.

Anyway, good luck!

1 Like

Not sure if you know the answer but I'd ask anyway. The native poller registers the device response (or at least it registers in the device log), is there a way to do that with NR?

HE is doing it in a way that it is a lower priority on the radio than what we can do in NR, however, all of my polling is not time sensitive, so I do an inject every 5 minutes with a refresh on my old z-wave switches.

Any examples of logic so that flows can recover from hub reboots or NR restart?