Getting started with node red

Here is a simple example..

Make sure you have "Send events" checked in your device node..

Here is the dashboard switch node config:

edit: the inject node at the beginning of the sequence is there to populate the dashboard when you "deploy" or restart Node-RED. It is set to only run once on startup.

edit2: changed the first picture to reflect correct "Change" node. Due to the on/off payloads in the dashboard switch it requires "on/off" input!

1 Like

I think the switch from payload / Jsondata is the part that I am missing. Is it possible to share that node. The on ? true/false. Thanks for the help ErkTrek,

Here is the basic switch node with JSONATA... You should be able to easily replicate the other stuff provided HE Nodes is set up properly and responding to events.

JSONATA Switch Node example

[{"id":"68a3910b.58ba8","type":"change","z":"af91369d.586338","name":"set msg.payload = JSONATA / payload.value = \"on\" ? true : false","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value = \"on\" ? true : false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":2400,"wires":[["a0faee22.68e82"]]}]

edit: I LOVE JSONATA stuff... makes it easy to do more complicated things in the stock switch nodes etc without having to use Function nodes. I also love Function nodes too though.. :wink:

edit2: I guess I could also have just done this...

payload.value = "on"

NOTE!!!!!!!
I made a slight error - the INPUT msg.payload MUST MATCH whatever is defined by the dashboard ON/OFF payloads so in my simple example above (which has been corrected) you would NOT use JSONATA!!!!!!!

2 Likes

But also if your not a jsonata type, you can easily do the same thing with 2 nodes - a switch node followed by a change node (or two).

2 Likes

Thank you Erktrek!

2 Likes

I do not know. Something I am not doing, I just dont know. Turn the light on, it does send the data, but the switch just doesnt manually show.

Screenshot by Lightshot - Flow

Screenshot by Lightshot - Light
Screenshot by Lightshot - Sending status.

I haven't added the on or off for the Dashboard switch yet, just trying to get the Dashboard to show correct status first if someone "flips" the light or the motion sensor turns on the light from the rule in a different flow

I definitely am missing something :confused:

I thought I got it when I changed the Dashboard switch to Boolean True/False, as the updates showed if the light was on. But nope :confused:

In your dashboard node, do you have it set to follow input or output status? Should be input, which is not the default.

Not at home, so can't show you a screenshot. But as I exclusively use Node-RED dashboards (for my very limited use of dashboards) I know this can/should work.

Yes, set to input

I know it should, just doesnt make sense,. When I change the switch as well, I can no longer operate the switch either on the dashboard :confused:

Since you have "on" and "off" specified in your dashboard node, don't you want the change node setting msg.payload to "on" and "off" - instead of true/false?

So basically the change node would just be "set msg.payload to msg.payload.value". (last part no longer needs to be jsonata)

If that isn't it, I'll quit guessing and just look when I get home.

If I change to Boolean True/False in the Dashboard switch, it then syncs, and works this way. If I try to hit the switch on the Dashboard, it will not do anything now (turn on or off, I believe I need to switch the message back to operate light (Send the command to the Hubitat light to turn on or off), but the node I have above is giving a error.
I need a Switch Node for the command to the light, but just not sure how to write it.

Here is what I have so far.

[{"id":"2c23c62e.380d5a","type":"tab","label":"Dashboard","disabled":false,"info":""},{"id":"a2efc18e.cd0ef8","type":"inject","z":"2c23c62e.380d5a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"40","topic":"","payload":"true","payloadType":"bool","x":90,"y":40,"wires":[["3dd7414c.570766"]]},{"id":"3dd7414c.570766","type":"hubitat device","z":"2c23c62e.380d5a","deviceLabel":"Hallway Light","name":"","server":"4657b2d4.c14fb4","deviceId":"14","attribute":"switch","sendEvent":true,"x":120,"y":80,"wires":[["8bb1abeb.3ce1d"]]},{"id":"8bb1abeb.3ce1d","type":"change","z":"2c23c62e.380d5a","name":"set msg.payload = JSONATA / payload.value = "on" ? true : false","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.value = "on" ? true : false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":80,"wires":[["769899e2.75889"]]},{"id":"93901132.be5b68","type":"change","z":"2c23c62e.380d5a","name":"","rules":[{"t":"set","p":"command","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":80,"wires":[["814d391d.053a7"]]},{"id":"814d391d.053a7","type":"hubitat command","z":"2c23c62e.380d5a","deviceLabel":"Hallway Light","name":"","server":"4657b2d4.c14fb4","deviceId":"14","command":"","commandArgs":"","x":1240,"y":80,"wires":[[]]},{"id":"b781b02b.1b0cd","type":"debug","z":"2c23c62e.380d5a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":160,"wires":[]},{"id":"769899e2.75889","type":"ui_switch","z":"2c23c62e.380d5a","name":"","label":"Hallway Lights","tooltip":"","group":"5ba8c97c.12626","order":0,"width":0,"height":0,"passthru":false,"decouple":"true","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"x":820,"y":80,"wires":[["b781b02b.1b0cd","93901132.be5b68"]]},{"id":"4657b2d4.c14fb4","type":"hubitat config","name":"","usetls":false,"host":"192.168.13.5","port":"80","appId":"920","nodeRedServer":"http://192.168.13.7:1880","webhookPath":"/hubitat/webhook","autoRefresh":true,"useWebsocket":false,"colorEnabled":false,"color":"#ace043"},{"id":"5ba8c97c.12626","type":"ui_group","name":"Lights","tab":"dd4ab1b6.a3bf4","order":1,"disp":true,"width":"6","collapse":false},{"id":"dd4ab1b6.a3bf4","type":"ui_tab","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

I'm not going to import your flow, but I will be happy to post some pics in how I do it tonight when I'm home.

There is no 1 right/wrong way to do it. You can massage the message going into the dashboard node, massage the message coming out of it, or both, or neither.

But to your point, by the time the message gets to the hubitat device node it needs to be in the correct structure/format.

1 Like

Agreed, if you could post an example when you have time, and are at home, would appreciate it. Thanks Jason,

Okay I figured it out.. if you set the dashboard On/Off payloads to "on" and "off" you need to set the input payload to be the same. So if you edit the change node and do this:

It should just work. sorry for the confusion.. I was using a sequence I copied from a different dashboard where I was using true/false and edited it without testing.

2 Likes

Yes sir! Works perfectly now with your original sample and the new change mode, thank you sir!!!

1 Like

That's exactly what I already said..... :stuck_out_tongue:

2 Likes

I know but I had to admit my mistake...

1 Like

I'm just teasing. :slight_smile:

Plus yours included a picture, which is better.

2 Likes

Naw I deserve it! Today has been a wacky day for me. Have made a bunch of goofy mistakes. All good! :rofl:

2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.