my plc is monitoring a possible power failure with an embedded battery to stay alive.
I have a power_fail address that changes following the power status:
power_fail = 1 if power is Down
power_fail = 0 if power is UP
I injected this value (as in integer) into Node Red and I want to activate/deactivate a hubitat switch, regarding the state:
if power_fail = 0 (UP) then deactivate the Hubitat Power.Fail switch
if power_fail = 1 (DOWN) then activate the Hubitat Power.Fail switch
I set a switch node, but whatever I put there, I always receive an error (see pic).
The payload[40] is the numeric value obtained from the harvested PLC (it works for others hubitat variables).
So, I want to convert this numeric value (0 or 1) to a switch state (ON or OFF). Where is my mistake ?
I could define a sensor instead of a switch and display the value obtained (and create a RM rule to warn me if the value of that "sensor" increases to 1), but I won't be happy of this bypass, I want to know where my error is !
never a silly question. Yes, my command nodes are on and off.
And when I inject a simple command (with the inject instruction) on/off, it works. That means all the commands (hubitat side) are working: commands, Maker API, etc
So it's definitely between the 0/1 obtained from my plc and the on/off sent to my hubitat switch.
Somewhere in the switch node... But I tried arguments, msg.payload[40], etc, without success
The only thing I can think of is maybe since you are not using a "command" property it doesn't like the payload array for some reason maybe delete it before calling the command nodes or add a change node to set a "command" property based on 0/1 and use one command node.... very strange.
No idea offhand, but do make sure there is no msg.deviceId property that came from the PLC msg going into the command node. As the command node uses msg.deviceId as well, that can cause issues.
I only mention that as I've found that many node-red device nodes use msg.deviceId. This has bit me a few times, as I would get odd errors form the Hubitat command node and not understand why until I realized there was a msg.deviceId parameter on the incoming msg I wasn't expecting.
When troubleshooting sometimes I go so far as to put a change node in front of command nodes and just delete msg.deviceId altogether.
what my plc send is just a number extracted from an array.
I harvest my plc (40+ values) and I extract them separately to inject into HE.
It works fine for any temperature sensors .
PLC => value[x] => number
In this case, instead of sending the data itself (the temperature) to a HE temperature sensor, I want to open/close a HE switch, depending of the value [x] of the PLC
value[x] = 0 => HE switch = 0
value[x] = 1 (in this case a power failure detected) => HE switch = 1
It seemed simple at the beginning: collect the value[x], add a switch node that redirect to a command ON or a command OFF to the HE switch.
The entire process works if I do a simple test inject, but not when I add this switch node...
@PPz - I've run into this issue at least once. Took me for ever to figure out. In the end, I discovered it by trial and error - I used a debug node to look at the incoming message and then eliminated every msg property one at a time using a change node.
I would suggest posting the complete msg object coming out of the switch node then, not just msg.payload. There is clearly something in the msg that the command node does not like.
@JasonJoel
I'll try the trial / error scheme because I like to find solutions (even I like to ask for clues) myself.
If I'm still stuck after this, I'll post more.
If I find (I hope) the solution, I'll post it too
thank you