Node-RED nodes for hubitat

I reposted it, try it now.

It changed a bit still an error
error

I thought I read somewhere that if you post using "Hide details", then it messes with the formatting. Try with the 3 "back ticks" (`). Example:

[{"id":"ef5785af.850e88","type":"tab","label":"ScratchPad","disabled":false,"info":""},{"id":"97d33d0f.859df","type":"inject","z":"ef5785af.850e88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":220,"wires":[["9ababee4.523d5","af71d071.30832"]]},{"id":"9ababee4.523d5","type":"hubitat device","z":"ef5785af.850e88","deviceLabel":"Deck Camera","name":"","server":"4690716e.b51858","deviceId":"769","attribute":"battery","sendEvent":true,"x":220,"y":320,"wires":[["d4b06a23.2ee5d8"]]},{"id":"af71d071.30832","type":"hubitat device","z":"ef5785af.850e88","deviceLabel":"Driveway Camera","name":"","server":"4690716e.b51858","deviceId":"760","attribute":"battery","sendEvent":true,"x":210,"y":400,"wires":[["39ea4729.8df068"]]},{"id":"731d6631.16c698","type":"debug","z":"ef5785af.850e88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":340,"wires":[]},{"id":"456c5184.f5fdb","type":"function","z":"ef5785af.850e88","name":"Add flows","func":"msg.payload = {};\ndeck = flow.get("deckBattery")||0;\ndrive = flow.get("driveBattery")||0;\nmsg.payload.value = deck + drive;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":340,"wires":[["731d6631.16c698"]]},{"id":"39ea4729.8df068","type":"function","z":"ef5785af.850e88","name":"set.flow","func":"flow.set("driveBattery", msg.payload.value);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":400,"wires":[["456c5184.f5fdb"]]},{"id":"d4b06a23.2ee5d8","type":"function","z":"ef5785af.850e88","name":"set.flow","func":"flow.set("deckBattery",msg.payload.value);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":320,"wires":[["456c5184.f5fdb"]]},{"id":"4690716e.b51858","type":"hubitat config","name":"Hubitat Main","usetls":false,"host":"192.168.1.38","port":"80","appId":"913","nodeRedServer":"http://192.168.1.46:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false,"colorEnabled":false,"color":"#000000"}]
Hidden Flow
[{"id":"ef5785af.850e88","type":"tab","label":"ScratchPad","disabled":false,"info":""},{"id":"97d33d0f.859df","type":"inject","z":"ef5785af.850e88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":80,"y":220,"wires":[["9ababee4.523d5","af71d071.30832"]]},{"id":"9ababee4.523d5","type":"hubitat device","z":"ef5785af.850e88","deviceLabel":"Deck Camera","name":"","server":"4690716e.b51858","deviceId":"769","attribute":"battery","sendEvent":true,"x":220,"y":320,"wires":[["d4b06a23.2ee5d8"]]},{"id":"af71d071.30832","type":"hubitat device","z":"ef5785af.850e88","deviceLabel":"Driveway Camera","name":"","server":"4690716e.b51858","deviceId":"760","attribute":"battery","sendEvent":true,"x":210,"y":400,"wires":[["39ea4729.8df068"]]},{"id":"731d6631.16c698","type":"debug","z":"ef5785af.850e88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":790,"y":340,"wires":[]},{"id":"456c5184.f5fdb","type":"function","z":"ef5785af.850e88","name":"Add flows","func":"msg.payload = {};\ndeck = flow.get("deckBattery")||0;\ndrive = flow.get("driveBattery")||0;\nmsg.payload.value = deck + drive;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":340,"wires":[["731d6631.16c698"]]},{"id":"39ea4729.8df068","type":"function","z":"ef5785af.850e88","name":"set.flow","func":"flow.set("driveBattery", msg.payload.value);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":400,"wires":[["456c5184.f5fdb"]]},{"id":"d4b06a23.2ee5d8","type":"function","z":"ef5785af.850e88","name":"set.flow","func":"flow.set("deckBattery",msg.payload.value);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":320,"wires":[["456c5184.f5fdb"]]},{"id":"4690716e.b51858","type":"hubitat config","name":"Hubitat Main","usetls":false,"host":"192.168.1.38","port":"80","appId":"913","nodeRedServer":"http://192.168.1.46:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false,"colorEnabled":false,"color":"#000000"}]

EDIT: Yep - as @JasonJoel said, it works. It's the 3 "ticks" that you need

I think you can do both - hide details AND use three ` on the code you hid. :slight_smile:

hidden
Hidden code!
2 Likes

Was trying to minimze the amount of images but...

the Set.Flow functions look like

While the Add Flows

Ya both flows still shown error. But I can copy what you have in the screen shots and get play around with it.

1 Like


The first debug error is when turning on the "pool table light" which updates the power
The second debug error is when refreshing "security tv power" which update the power.

Here is the pool table "function" node

Here is the security tv power "function" node

Here is the function node which both go into.

flow.get(“Pool Table Light”)||0; // 2 bars you have 1

1 Like

Changed it.

Not positive but don’t believe varible names can contain spaces. Try changing Pool Table Light to something like Pool_Table_Light. If that’s the issue then similar treatment for the Tv Power...

1 Like

Hell ya! That did it, it's doing the adding as well. So to add more devices just create a "function" node for each, then on the joining function node add each flow the + next flow?

1 Like

Can you share an example of how you are using the smooth node? Thanks!

Sure, here's are two examples. It is pretty straight forward.

My pool bleach tank level reading is noisy. I use a smoothing node (\with low pass filter) to make the signal less noisy for use in automations and graphing. A large smoothing factor is OK here as the level doesn't move very fast in reality - so while the high smoothing factor makes the readings "sluggish" it doesn't matter for this application.

Or here is an example of using a smoothing node on outdoor lux values for use in lux based lighting adjustment. Useful so that lights don't go up/down rapidly when a cloud goes by. This was an example of how the values respond on various smoothing factors and algorithms (low pass=3, low pass=5, mean=3, mean=5):

5 Likes

Thanks for the examples. Unfortunately, I'm not sure if this node will work for me as it calculates mean over a number of messages.

I found another node that does it over time or messages ( node-red-contrib-calculate) that I'm going to try for my lux readings and see if I can avoid the "jitter" in the logged data.

1 Like

Node-RED just released 1.3 with some cool features.

Also the MQTT nodes now support MQTTv5...

edit: to be clear I have NOT yet updated so ymmv..

3 Likes

Can also use the change node for the first set of functions by setting it up like:

This is awesome I'm using switches to send adb shell commands to my chromecast with google tv and am finally able to auto tune to a channel on YouTube TV.

I had to use virtual switches though as I can't get a virtual button to send events.

1 Like

I got it all up and going, works like a charm, Thanks for you help!

4 Likes

There has been discussion before about what to do when a command doesn't "work" (error from Maker API, network interruption, mesh congestion on Hubitat side so command was lost, etc).

I have a subflow to help deal with that, which I will share soon. I am waiting on a modification to the command node output that includes the command/arguments used, so that the subflow can be made as generic as possible and work in all uses of command node (command/arguments specified in incoming msg OR pre-configured in the command node).

The issue with this type of validation is that there is some coding required to know what attributes go with which commands, handle special cases like level=0%, and to handle multi-parameter arguments. This is the reason it will likely never be added to the command node code itself, as it would be a support nightmare for @fblackburn ).

For instance, if you send a LEVEL + DURATION as an argument in a setLevel command (like "55, 60" for instance), to know if it worked on the device you need to:

  1. Know that the attribute you need to check is "level", when the command is "setLevel"
    *** With setLevel one also needs to check if the setLevel % = 0, as in that case you actually need to check "switch"="off" instead of checking "level"=%...
  2. Make sure you don't actually check the attribute value until AFTER the duration period is complete
  3. The subflow has to strip off the "level" part of setLevel argument "55, 60" to compare to the level value from the device.

Not horribly complicated, but more complicated than one might think...

I'll include some instructions on how the end user can add their own custom command / custom attribute support when I publish it. It isn't especially hard, but it does take a couple lines of code per custom command/attribute.

When the command+arguments and attributes do not match, the subflow will re-send the command to the hub up to 3x.

Just thought I would mention this in case others have the same need. The subflow works well already, but will be easier to implement after the mentioned command node output message change is made.

More to come.

The subflow node shows status of the check, and outputs a true/false message to use for other alerting/post-processing.

Waiting for a delay before checking the attribute value:
image

Command Check was Successful (aka the command and attribute match)
image

Command Check Failed (aka the command and attribute do not match after 3x retries). Note, I may add the requested command and actual attribute value in status. BUT, many times it will be cutoff due to max status text length... So we'll see.
image

7 Likes

Released 1.7.0

  • new command node output (msg.requestCommand and msg.requestArguments)
  • add a flow example with event node

Thank you @JasonJoel for your all your contribution and idea

8 Likes