Node-RED nodes for hubitat

I wanted to share a heads up on something that just about made me lose my mind trying to debug, but was just user error on my part.

I have had my hubitat and Node-Red connected for a long time and have been doing really useful automation this way. I also happen to have a second hubitat connected to the first via Hub mesh (also connected to Node-Red, but not relevant to the story. For reasons that don't matter to this circumstance, one of the 2 hubs has login security turned on and the other doesn't. I had a series of power outages (yes, I should have my systems on a UPS, but don't). I found that when my hubitat comes online before router comes online, it fails to get its reserved IP address via DHCP and so thinks of itself as having the default address of 168.... Interestingly enough by google wifi setup routes traffic to reserved IP address, but the mesh interface on the secured hub only accepts a mesh connection on the IP address that the hub thinks it is using. To overcome this, I assigned a static IP address to the hubitat. This fixed my mesh following a power outage problem.

Turns out, I had configured my hubitat node with a webhook set to reach my Node-Red using the device name, not the device's IP address. This worked without any problems before I changed the hub to a static IP address. After that change, I noticed flows were malfunctioning all over the place. Unfortunately, I didn't connect the change to the problems and so spent a lot of time on how I had misconfigured the webhook without realizing I had changed it. I did many changes trying to debug the self created mess. It turns out that when you configure hubitat with a static IP address, you must assign the address, the default gateway and the DNS server. The DNS server can be skipped as it has a default setting of 8.8.8.8 which is a google DSN server. This seemed easy enough.

I am sure the more savvy have already spotted the root of my problem. The Maker app was using the device name to send updates to my Node-Red, but because Google had no knowledge of my network it had no way to translate the hostname into the IP address. Once I recognized the problem, there was a very easy fix. Updated the hubitat DNS to my in home router as the DNS, Took all of 30 seconds to fix the problem after I spent a lot longer than that to figure out how I had broken it.

Bottom line. If you use the a LAN name for your Node-Red server and set up your Hubitat with a static IP address, use a DNS (typically your router) that is LAN name aware and not the default google DNS of 8.8.8.8.

This is new right for Node-RED 2.1.0-beta.1?

image

This is great for all of those obsessive/compulsives among us!

5 Likes

How is 2.0 working out for you? Haven't upgraded as yet but I'm wondering if you (or anyone else here) has upgraded the NR version with the pre-built Homebridge image. I have done v1 upgrades on my Homebridge instance but not sure how it will work from v1 to v2...

Just a quick heads up - IF you are running Node-RED v2.1.2 there seems to be some weirdness going on with the environmental variables (used as properties in subflows).. the properties show correctly when editing a specific node but when editing the subflow template only the first entry is shown... Things still work but you might end up messing up your vars if you edit and save the subflow.

V2.1.3 seems to resolve this issue.

5 Likes

My Node Red automations have slowed down and I am not sure why. If I restart, it works quickly for a while but then slows again.

Immediately after a restart:

I thought I could put a debug node after each step of my flow but the timestamp is only each second. Does anyone know if there is a way to see log timestamps to 2 or 3 decimals like the HE log?

It's all of my Node Red flows that are slow, not just this one. I don't know if getting that detailed of a timestamp will helo but I am at a loss of what could be causing the slowdown or what tools are available to debug.

The other weird thing is the the Node Red Log shows the button being pushed and the Office switch turning on 3 times and this is immediately after the restart. I have seen other cases where it gets to 4.

image

I created a Rule in HE to do the same as the flow and it was fast as expected so it is not an HE issue.

If it slows down over time, it could be a loop? Are you able to open up a logging window (on the node red device) and see if you have a loop somewhere? Or put a few debug nodes on the end of your flows, to determine if there is a loop?

Does anyone have a flow that ignores motion on an off if I've turned the lights on using Google ?

I don't use Google but in this flow, motion is ignored if the light is already on.

[{"id":"1dd1fb73.73e095","type":"group","z":"68be3b45.fb2464","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["a31667ea.aadf","abfe7e4a.c24058","cf39e458.37188","3bc1ae70.748552","1e93ab9d.366914","f2b43711.a4276","7a3b878.b36b1f8","80bc3b7d.29dca","aca11047.6fc428","6e9ab0d1.74682","cee08a62.a12318","a48fcf51.994c68","6dc1f51a.b9561c","fbae6e61.cf485","49ac679c.a688d","750e04e7.cd72ec"],"x":109.5,"y":3401.5,"w":1413.0000762939453,"h":271.5},{"id":"a31667ea.aadf","type":"hubitat device","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","deviceLabel":"Pantry Motion Sensor","name":"","server":"2e073620.1f85c2","deviceId":"712","attribute":"motion","sendEvent":true,"x":256.0000190734863,"y":3525.666799545288,"wires":[["abfe7e4a.c24058"]]},{"id":"abfe7e4a.c24058","type":"switch","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Motion (Y/N)?","property":"payload.currentValue","propertyType":"msg","rules":[{"t":"eq","v":"active","vt":"str"},{"t":"eq","v":"inactive","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":482.0000114440918,"y":3526.4167737960815,"wires":[["cf39e458.37188","3bc1ae70.748552"],["1e93ab9d.366914"]],"outputLabels":["Active","Inactive"]},{"id":"cf39e458.37188","type":"hubitat device","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","deviceLabel":"Pantry Light","name":"Pantry Light State","server":"2e073620.1f85c2","deviceId":"700","attribute":"switch","sendEvent":false,"x":883.2500343322754,"y":3518.666799545288,"wires":[["f2b43711.a4276"]]},{"id":"3bc1ae70.748552","type":"change","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Reset Delay","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":646.9999732971191,"y":3465.6667985916138,"wires":[["7a3b878.b36b1f8"]]},{"id":"1e93ab9d.366914","type":"delay","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Delay 1 minute","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":666.2500343322754,"y":3578.9168004989624,"wires":[["750e04e7.cd72ec"]]},{"id":"f2b43711.a4276","type":"switch","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Light Off?","property":"payload.currentValue","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1073.333293914795,"y":3518.4167985916138,"wires":[["6e9ab0d1.74682"]]},{"id":"7a3b878.b36b1f8","type":"link out","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Reset Delay (P) - Out","links":["80bc3b7d.29dca"],"x":847.4166603088379,"y":3465.6667985916138,"wires":[],"l":true},{"id":"80bc3b7d.29dca","type":"link in","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Reset Delay (P) - In","links":["7a3b878.b36b1f8"],"x":460.4166564941406,"y":3579.166748046875,"wires":[["1e93ab9d.366914"]],"l":true},{"id":"aca11047.6fc428","type":"link in","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Time Delay - In","links":["45f02297.6a5ad4"],"x":478.33331298828125,"y":3632,"wires":[["1e93ab9d.366914"]],"l":true},{"id":"6e9ab0d1.74682","type":"change","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Turn On","rules":[{"t":"set","p":"command","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1246.7500762939453,"y":3518.916748046875,"wires":[["cee08a62.a12318"]]},{"id":"cee08a62.a12318","type":"hubitat command","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","deviceLabel":"Pantry Light","name":"","server":"2e073620.1f85c2","deviceId":"700","command":"","commandArgs":"","x":1426.5000762939453,"y":3552.416748046875,"wires":[[]]},{"id":"a48fcf51.994c68","type":"change","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Turn Off","rules":[{"t":"set","p":"command","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1248.2500762939453,"y":3580.416748046875,"wires":[["cee08a62.a12318"]]},{"id":"6dc1f51a.b9561c","type":"switch","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Light On?","property":"payload.currentValue","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1076.7498321533203,"y":3579.75,"wires":[["a48fcf51.994c68"]]},{"id":"fbae6e61.cf485","type":"comment","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Pantry Light: Turn on/off if motion detected","info":"","x":305.5,"y":3442.5,"wires":[]},{"id":"49ac679c.a688d","type":"comment","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","name":"Change Log","info":"2021-08-26: Created\n2021-08-26: Separated logic for turning off/on based on motion. Also added link from light turning on with contact sensor\n2021-08-27: Changed motion delay off to 1 minute (2 mins was too long)","x":216.75,"y":3627.5,"wires":[]},{"id":"750e04e7.cd72ec","type":"hubitat device","z":"68be3b45.fb2464","g":"1dd1fb73.73e095","deviceLabel":"Pantry Light","name":"Pantry Light State","server":"2e073620.1f85c2","deviceId":"700","attribute":"switch","sendEvent":false,"x":887.6666870117188,"y":3579.33349609375,"wires":[["6dc1f51a.b9561c"]]},{"id":"2e073620.1f85c2","type":"hubitat config","name":"Hubitat_Prod","usetls":false,"host":"192.168.1.113","port":"80","appId":"225","nodeRedServer":"http://192.168.1.82:1880","webhookPath":"/hubitat/webhook_","autoRefresh":true,"useWebsocket":false}]

Hope this helps

2 Likes

Don't have a specific flow for this but here are some ideas:

  • Set up a virtual HE switch that flips on when you issue the command from google. Test for that switch during your motion sequence.

  • Test for msg.payload.type = 'digital' if your switch supports it. This will only distinguish between physical and digital switches not Google Home specifically. You can then set a global variable to test during your motion sequence.

You would still have to figure out how you want to reset the switch when you are done - either timeout or issue another Google command etc..

2 Likes

I turned up Node Red logging to Debug to see if I noticed anything that could be causing my slowdown and saw this in the logs that happens every 5-10 seconds. I am not saying this has anything to do with slowdown, just curious what is being "locked" as I have no actual locks.

It's only for debug purpose
To avoid spamming hub, I added a lock to limit number of requests. This log only show remaining slot available to do simultaneous requests

4 Likes

Cool! Thank you. I learn something new every day.

1 Like

I was updating the log level in the settings.js file and noticed this above the Log Settings:

It looks like if I were to change the "//paletteCategories: ['subflows..." to "paletteCategories: ['hubitat', 'subflows', ....." then the Hubitat palette would always be at the top of left column? Can someone confirm if that is correct?

EDIT: I took a chance and made the change and that is in fact what it does. I wish I would have known this at the beginning.

4 Likes

Oh thank you for sharing, I added a link to your post in the first post FAQ :slight_smile:

3 Likes

Anyone tried linking to Tuya using these nodes?

It seems like they offer a way to support all Tuya devices!

There also appears to be a local approach too....

Update: cant get these to work. They require a device key (not the account key) and I can't find any way to generate or find that.

I just started using the Broadlink HE integration & Node Red together and the Command Node puts the code being sent underneath. Is it possible to disable that just for specific nodes? It really grates on my OCD with all of those numbers but I generally want that information on every other node. :grinning:

1 Like

:rofl: Unfortunately, not possible ... I'm sorry for you

Workaround (not tested)
Add a Change node before each command to inject the command arguments in the msg.arguments.
Then the node will not print dynamic arguments

You can open an issue on github to ask for a better solution.
I may re-start to give a little bit love to this project. Now that I have a house and waiting for end-of-year deal to buy more IoT stuff :drooling_face:

3 Likes

GREAT MINDS THINK ALIKE!!! This morning, I set it up for the first few to test and it works as we both knew it would. :grinning: And, since it will eventually only add one net node because I am replacing a Command Node with a Change Node then all of them can go to one Command Node, I might not even call this a workaround.

3 Likes

Can someone help me?

I'm at my friend's place "helping" him get Node-RED up and running with Hubitat, and I forget how I configured a change node to send three saved flow context variables as msg.arguments for hue, saturation, and level.

I thought I had done something like setting msg.arguments to be JSONata with the following entry:

$flowContext(".hue_variable"),$flowContext("saturation_variable"),$flowContext("level_variable")

But this is obviously wrong because it throws an error.

Many thanks!

It's not exactly what you want but this is how I'm setting Hue lamp brightness level and temp, based on global context variables, in case it helps (probably not since I guess it is Philips Hue specific and just white lamps not colour/hue)...

1 Like