Very basic node-red question

I've got node-red up and running and have a Hubitat pallette installed. Setting up a simple switch was pretty easy but I have a question about how to trigger actions by the change of state of a device. What nodes would be used to turn on one switch when another switches on?

Here is a very simple example:

The node on the left is a "Device" node with "Send Events" checked. The ones on the right are "Command Nodes". The "Device" node reports the state of a device and in combination with the "Send Events" property will fire when the selected event occurs - you can also select "All" to trap all events/attributes.

edit: sorry made a mistake in the screen cap... has been corrected!!

1 Like

If this is not working then you will need to look at your HE Nodes Config in NR and Maker API settings in HE to make sure the webhook information is correct.

And, in Node Red, there is always more than "one way to skin a cat". In @erktrek's example, the Switch Node could be a Change Node and you can set msg.command to msg.payload.value then you only need one Command Node and leave the Command blank in its edit box.

image
Note: I change the color of my Hubitat Device Nodes to light blue.

This only works if the device in Device Node is same type as device in Command Node (ie one switch reacting to action on another switch). If your device in Device Node is a motion sensor, then @erktrek's method is the way to go but payload.value is active/inactive instead of on/off.

Just wait until you ask for help for a more complicated flow and get 17 different, valid, and efficient ways to do the same task. :grinning:

If you haven't already, setup some flows w/ an Inject Node, Device Node (with ALL selected) and a Debug Node w/ output as "complete message object" and start it to see what shows up in Debug Window. You will learn A LOT!!!

2 Likes

Yeah that's the way I do it as well. Love me some JSONATA!

Also, have you watched the video?

2 Likes

Thanks for the responses. My confusion had been in how to configure the message in the switch. I ended up doing it like it as shown in this pic.

Never use payload.currentValue - it is deprecated, and may/may not be removed at some point.

You should always use payload.value.

From the online node help (always read the node help!!! :slight_smile: It is often the only official documentation for node-red nodes):
image

3 Likes

If you want to experiment you can try something like @stephen_nutt suggested... use a change node instead of a switch node and just set msg.command based on msg.payload.value.

Note: in the "Command" node I left the "# Command" field as the default (i.e. "Choose Command") since setting the "msg.command" property will override it anyway.

2 Likes

To expound a little further... (because why the heck not?) IF you are using events that do not return "on/off" in the msg.payload.value property but something else like "active/inactive" - you can use JSONATA and "inline ifs" in the change node.. JSONATA is kind of like XQUERY for JSON.

So rewriting the above (and using a motion device) would look something like this:

https://jsonata.org/

Note: You do not need to include "msg" when referencing it's properties.

2 Likes

don't you need payload.value, not just value, though? Or does it work either way?

1 Like

yep my bad.. correcting!!!!

Nuts, thought I was learning something new. :slight_smile:

1 Like

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