Node-RED nodes for hubitat

The function node is a little long, but that's all hidden out of view

Capture

[{"id":"8535a4ec.224618","type":"hubitat command","z":"f451db6.6b82428","name":"LED's Red","server":"6030cf9.9313d3","deviceId":"273","command":"setDefaultLEDColor","commandArgs":"1","x":410,"y":500,"wires":[[]]},{"id":"a85efaf2.af12c8","type":"hubitat command","z":"f451db6.6b82428","name":"LED's Blue","server":"6030cf9.9313d3","deviceId":"273","command":"setDefaultLEDColor","commandArgs":"170","x":410,"y":460,"wires":[[]]},{"id":"89a2b34a.0a54e","type":"unsafe-function","z":"f451db6.6b82428","name":"Set deviceId","func":"var dev1 = { deviceId:\"273\" };\nvar dev2 = { deviceId:\"275\" };\nvar dev3 = { deviceId:\"277\" };\nvar dev4 = { deviceId:\"276\" };\nvar dev5 = { deviceId:\"271\" };\nvar dev6 = { deviceId:\"368\" };\nvar dev7 = { deviceId:\"340\" };\nvar dev8 = { deviceId:\"270\" };\nvar dev9 = { deviceId:\"269\" };\nvar dev10 = { deviceId:\"268\" };\nvar dev11 = { deviceId:\"267\" };\nvar dev12 = { deviceId:\"265\" };\nvar dev13 = { deviceId:\"266\" };\nvar dev14 = { deviceId:\"296\" };\nvar dev15 = { deviceId:\"279\" };\nvar dev16 = { deviceId:\"1383\" };\nvar dev17 = { deviceId:\"262\" };\nvar dev18 = { deviceId:\"263\" };\nvar dev19 = { deviceId:\"274\" };\nvar dev20 = { deviceId:\"272\" };\nreturn  [[ dev1, dev19, dev2, dev3, dev4, dev5, dev6, dev7, dev8, dev9, dev10, dev11, dev12, dev13, dev14, dev15, dev16, dev17, dev18, dev20 ] ];","outputs":1,"noerr":0,"x":251.5,"y":460,"wires":[["a85efaf2.af12c8"]]},{"id":"c11b55c2.0cfde8","type":"unsafe-function","z":"f451db6.6b82428","name":"Set deviceId","func":"var dev1 = { deviceId:\"273\" };\nvar dev2 = { deviceId:\"275\" };\nvar dev3 = { deviceId:\"277\" };\nvar dev4 = { deviceId:\"276\" };\nvar dev5 = { deviceId:\"271\" };\nvar dev6 = { deviceId:\"368\" };\nvar dev7 = { deviceId:\"340\" };\nvar dev8 = { deviceId:\"270\" };\nvar dev9 = { deviceId:\"269\" };\nvar dev10 = { deviceId:\"268\" };\nvar dev11 = { deviceId:\"267\" };\nvar dev12 = { deviceId:\"265\" };\nvar dev13 = { deviceId:\"266\" };\nvar dev14 = { deviceId:\"296\" };\nvar dev15 = { deviceId:\"279\" };\nvar dev16 = { deviceId:\"1383\" };\nvar dev17 = { deviceId:\"262\" };\nvar dev18 = { deviceId:\"263\" };\nvar dev19 = { deviceId:\"274\" };\nvar dev20 = { deviceId:\"272\" };\nreturn  [[ dev1, dev19, dev2, dev3, dev4, dev5, dev6, dev7, dev8, dev9, dev10, dev11, dev12, dev13, dev14, dev15, dev16, dev17, dev18, dev20 ] ];","outputs":1,"noerr":0,"x":250,"y":500,"wires":[["8535a4ec.224618"]]},{"id":"4d5e660c.81eb68","type":"inject","z":"f451db6.6b82428","name":"Red","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":540,"wires":[["c11b55c2.0cfde8"]]},{"id":"4834ef89.9afff","type":"server-state-changed","z":"f451db6.6b82428","name":"Ring Alarm","server":"94fdcfdf.a00b","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"alarm_control_panel.ring_alarm","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"disarmed","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":80,"y":480,"wires":[["89a2b34a.0a54e"],["c11b55c2.0cfde8"]]},{"id":"fc47cc2.016723","type":"inject","z":"f451db6.6b82428","name":"Blue","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":420,"wires":[["89a2b34a.0a54e"]]},{"id":"554c0d4.aa57bf4","type":"comment","z":"f451db6.6b82428","name":"Change LED color based on alarm status","info":"","x":340,"y":400,"wires":[]},{"id":"6030cf9.9313d3","type":"hubitat config","z":"","name":"Hubitat","usetls":false,"host":"192.168.2.12","port":"80","appId":"1606","nodeRedServer":"http://192.168.2.112:1880","webhookPath":"/hubitat/webhook","autoRefresh":true},{"id":"94fdcfdf.a00b","type":"server","z":"","name":"Home Assistant","addon":true}]
1 Like

You're gaining absolutely nothing by assigning to variables, just return the array in one shot

Screenshot 2020-06-19 20.14.18

3 Likes

That's even better!! I didn't know it could be done like that. Thanks

1 Like

There are an increasing number of devices that now use presence, such as the Tasmota devices and now the Xiaomi devices, even Hubconnect. This poses a problem for the Device Watchdog app, for when these devices report "not present", the Device Watchdog app classifies that as activity. And they are not reported as "missing" according to the Watchdog app.

Obviously, I want to do it within Node Red. I'm wondering is the best way to do it, to use an Events Node, using has key: presence, and then using a switch to filter for "not present". Does this hammer the hub? Or is there a better way? I'd like to send it to a dashboard.

Doesn't the events node just report on events as they fire via the webhook? That shouldn't spam the hub I would think.

1 Like

I dont know. That's why I'm asking. Also is it the best way?

I say give it a shot - it's easy to back out if necessary.

I guess you could do it on the HE end with a virtual switch but your approach seems a bit more dynamic. Unless of course you wrote a custom HE app..

edit: hopefully others will chime in.. am interested in the impact of events node as well.

1 Like

It won't hammer the node-red side at all. Many people take the raw event node and parse every incoming message for things like trends and dashboards, with no issues.

The events are coming in whether you use them or not. Might as well use them.

4 Likes

Hey guys, good news. My father came to my place and restart my switch. :tada:
I can now have access to HE via VPN :smiley:

I would need some help to test an experimental feature: websocket

To install the development version

cd /somewhere
git clone https://github.com/fblackburn1/node-red-contrib-hubitat.git
git checkout experimental-websocket
cd ~/.node-red
npm install /somewhere/node-red-contrib-hubitat

I only ask for those who can test on non-production environment (or doesn't value too much their prod :stuck_out_tongue_winking_eye:)

4 Likes

Nice! I would, but I only run production.

I have a dev hub and dev node-red, so I'll try to fit this in this week.

I'll be out of town all week starting Monday, but I have VPN so if I get some free time I'll check it out!

Busy fighting with k3s right now. :confused:

Seems to be working so far.. I deleted out the POST config entirely on the hubitat side. I assume it is using websocket now (not sure how one would tell on the node-red side though).

image

Can I do this?

I still can't tell what you are doing from that description. Is it a button on hubitat, or node-red dashboard, or other? Use more words and describe exactly what you are doing, and where.

If a button in hubitat, is the device making an event in Hubitat for every button press? You can check for the events in the device event log. If it is, you should see it on the node-red side. If not, then it will never make it to node-red anyway.

If a button in hubitat, what kind of device is it?

If it is making the event in hubitat on each press, and you aren't seeing it in node-red, post your flow so we can see what you're doing.

For instance, here is a virtual switch in hubitat - it creates an event in node-red every single time the pushed event happens.


Sorry, I got it working, kinda. After the automation goes through, it keeps on looping. Is there an “end” node?

I can tell you have "send events" turned on in the "bedroom wall fan switch" device node because the status symbol below it is a filled in circle, instead of hollow circle/ring.

Go to the "bedroom wall fan switch" device node and turn off send events. Then that node will only run when it gets an incoming message from the "nightstand button" node, thus getting rid of the loop you made.

image

Note the "hollow" blue status circle shown below, because "send events" is turned off:
image

2 Likes

Worked perfectly. Thank you

2 Likes

Awesome! Glad to hear it!

Why does this automation work faster than rm? I figured it be slower as it’s an extra step

Thanks for the feedback

  • You can look at the payload, it is different from webhook event (no type property)
  • You can look at the NR log (e.g. Websocket connected)
  • You can use event node to see a new status when used with websocket

But I would like to have another shape for the icon to make a distinction between webbook/websocket :thinking:

EDIT: Oh maybe green for websocket and blue for webhook !! :partying_face:

2 Likes