Node-RED nodes for hubitat

You could create a simple msg "counter" subflow that counts messages with a given topic.. and outputs the accumulated value. You could then use that to update your chart. Note: you would have to save the counting data in a flow variable BUT it would be contained within the subflow instance.

@napalmcsr This is an example I whipped up for giggles..

theCount Example

[{"id":"16ba13235838884b","type":"subflow","name":"theCount","info":"","category":"","in":[{"x":120,"y":120,"wires":[{"id":"31a77bafcac74c41"}]}],"out":[{"x":640,"y":80,"wires":[{"id":"31a77bafcac74c41","port":0}]}],"env":[{"name":"RESET_ON_START","type":"bool","value":"true"}],"meta":{},"color":"#DDAA99","status":{"x":640,"y":160,"wires":[{"id":"31a77bafcac74c41","port":1}]}},{"id":"31a77bafcac74c41","type":"function","z":"16ba13235838884b","name":"Accumulate based on topic","func":"var topic = msg.topic\nvar resetTopic = msg.hasOwnProperty(\"resetTopic\");\nvar reset = msg.hasOwnProperty(\"reset\");\nvar ret = [];\nvar varName = \"counter\";\n\nvar addend = msg.hasOwnProperty(\"addend\") ? msg.addend : 1 ;\n\nvar cntr = flow.get(varName);\nif (cntr === undefined || reset) {\n    cntr = {};\n}\n\nif (!reset) {\n    if (cntr.hasOwnProperty(topic) && !resetTopic) {\n        cntr[topic] = cntr[topic] + addend;\n        \n    } else {\n        cntr[topic] = 1 - resetTopic;\n    }\n    msg.counter = cntr[topic];\n    \n    ret = [msg,{ \"payload\": { \"text\": topic + \": \" + cntr[topic].toString()}}];\n\n} else {\n\n    ret = [undefined,{ \"payload\":{\"text\": \"counters reset\"}}];\n    \n}\nflow.set(varName,cntr);\n\nreturn ret;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":120,"wires":[[],[]]},{"id":"4d92c46fa340072d","type":"ui_chart","z":"655ae8d912445576","name":"","group":"9167e5082e18187e","order":0,"width":0,"height":0,"label":"Test Bar Chart","chartType":"bar","legend":"true","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"10","removeOlder":"36","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1000,"y":1320,"wires":[[]]},{"id":"cfdbca627b6aa7c4","type":"inject","z":"655ae8d912445576","name":"add Cooling","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Cooling","payload":"","payloadType":"date","x":250,"y":1040,"wires":[["4611159fc2c1ad17"]]},{"id":"db57fcff9ad51107","type":"inject","z":"655ae8d912445576","name":"add Fan Only","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Fan Only","payload":"","payloadType":"date","x":250,"y":1180,"wires":[["4611159fc2c1ad17"]]},{"id":"e7379017ebdf9620","type":"inject","z":"655ae8d912445576","name":"add Idle","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Idle","payload":"","payloadType":"date","x":230,"y":1220,"wires":[["4611159fc2c1ad17"]]},{"id":"5fa73cf0bee8816e","type":"inject","z":"655ae8d912445576","name":"add Heating","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Heating","payload":"","payloadType":"date","x":250,"y":1260,"wires":[["4611159fc2c1ad17"]]},{"id":"4611159fc2c1ad17","type":"subflow:16ba13235838884b","z":"655ae8d912445576","name":"","env":[{"name":"RESET_ON_START","value":"false","type":"bool"}],"x":500,"y":1180,"wires":[["0e5ca17e32e7e1b4"]]},{"id":"ee1421fb138b591f","type":"inject","z":"655ae8d912445576","name":"Reset All","props":[{"p":"reset","v":"","vt":"date"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"AnyTopic","x":240,"y":1320,"wires":[["4611159fc2c1ad17","67eb55eec5ba53aa"]]},{"id":"aba03f64cea692c1","type":"inject","z":"655ae8d912445576","name":"reset Cooling","props":[{"p":"topic","vt":"str"},{"p":"payload"},{"p":"resetTopic","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Cooling","payload":"","payloadType":"date","x":250,"y":1080,"wires":[["4611159fc2c1ad17"]]},{"id":"b69dd098606f0c2f","type":"inject","z":"655ae8d912445576","name":"subtract Cooling","props":[{"p":"topic","vt":"str"},{"p":"payload"},{"p":"addend","v":"-1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Cooling","payload":"","payloadType":"date","x":260,"y":1120,"wires":[["4611159fc2c1ad17"]]},{"id":"0e5ca17e32e7e1b4","type":"change","z":"655ae8d912445576","name":"set payload = counter \\n delete counter \\n set series = topic","rules":[{"t":"set","p":"payload","pt":"msg","to":"counter","tot":"msg"},{"t":"delete","p":"counter","pt":"msg"},{"t":"set","p":"series","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":1180,"wires":[["4d92c46fa340072d"]]},{"id":"67eb55eec5ba53aa","type":"change","z":"655ae8d912445576","name":"payload = []","rules":[{"t":"set","p":"payload","pt":"msg","to":"[]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":1320,"wires":[["4d92c46fa340072d"]]},{"id":"9167e5082e18187e","type":"ui_group","name":"Default","tab":"e9ca8db812d39fb7","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"e9ca8db812d39fb7","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

1 Like

Here is where I have gotten too :slightly_smiling_face: it mixes the data with the series

Json
{"_msgid":"b6a980d9cd86bb1c","topic":"yo4","payload":[{"data":[[[10],[9],[5],[0]],[[10],[9],[5],[0]],[[10],[9],[5],[0]],[[10],[9],[5],[0]],[[10],[9],[5],[0]],[[10],[9],[5],[0]]],"series":["Cooling","Fan Only","Idle","Heating"],"labels":["6","5","4","3","2","1"]}]}

1 Like

looks like I have to transpose my arrays...

Maybe tomorrow

Yay, got that to work, now to fix the data going in!

1 Like

If you used email notifications via Gmail, and it stopped working recently (as of June 2022), it may be because Google has turned off access via less secure apps. The solution is simple (took me about 5 minutes), and is documented in this post:

2 Likes

thanks for posting this!! Sadly I dont think I even realized.

1 Like

I just received a Third Reality Light Switch that works fine thru HE but it's status does not change in Node Red. This is the HE log:

Nothing shows in the Node Red logs when I turn switch off or on in HE. Node Red Command Node can turn on or off switch but doesn't show up in Node Red logs either. I am using the native Third Reality Switch driver.

Any suggestions?

I'm going to guess here because I'm not that well versed with Node-Red <--> Hubitat connections....
is Node-Red capturing events or logs?

In Node-Red go to the Hubitat command node and re-save the web hooks entry.

3 Likes

That did it! Thanx

1 Like

@thebearmay ... I'm having the same problem as @stephen_nutt. I updated my webhook; received a green check but none of my Hubitat devices status are getting updated in NR. BUT if I restart NR, they all are initially correct until the status changes in HE. Any suggestions/ideas as to the source of my problem?

Generally resaving the webhook information is enough to restart the sync. Now that you've restarted NR, you may want to try the webhook one more time.

1 Like

I've done that as well but does not resolve the problem.

Silly/obvious question maybe but you do have your maker API instance setup properly? POST Url is set correctly etc. Also make sure you do not have "websocket" checked in the NR config under advanced..

Conversely you COULD try websockets just to see if you get anything but it is not recommended and I think you get dup events etc that you would have to handle.

The Hubitat Nodes definitely work (receives events) for my setup and 3 hubs so something is weird. One of my more complicated configurations: HomeAssistant using the Node-RED addon (then talking to HE via HE Nodes) does have issues if I do not restart Node-RED after an update or change to a config.

1 Like

If the values update on initial load, but not after that, it's basically always a webhook/post address problem. Either the post URL is wrong, something on the host is blocking the messages, or other.

One thing that used to happen a lot is that sometimes there would be a space character in the address, which would screw it up. Make sure you don't have any leading or trailing spaces that you didn't intend to be there.

2 Likes

Hi folks - I'm still quite confused on IP and Port configuration. I've got a Maker API instance set up specifically for Ned Red (which is installed under Home Assistant).

See my screenshots with questions below:

In Maker API, is the URL to post device events to supposed to be the IP of the device where HA/Node Red are running? What determines the port? Or should this be the Webhook address?

In the config node in NodeRed, is the Server the address of the Hubitat Hub? Or the address of HA/Node Red? (Why would I need to tell nodered where it's running?) And what is the Port for the server? What should that match?

Then there's the webhook configuration.
Basically I'm unclear where the IPs in both Maker API and Nodered should point, and what should match what. I looked for documentation on this but didn't find it. Did I miss this?

Where is it documented what "correctly" is?

Ah!!! Just found this configuration post from @aaiyar which helps a lot. Where did port 1880 come from? Is that a default value for nodered? And is Port 80 for hubitat required? That's the http port of course, so does that exclude any other integrations that might also use port 80?

1 Like

Yes 1880 is the default port for node-red.

2 Likes