Replies: 1 comment
-
A core paradigm in Node-RED is that most control messages don’t pass through the node they act on. That’s why the Switch node behaves this way — it receives the command, sends it to Home Assistant, but doesn’t emit an output unless the state change is reported back from Home Assistant.
Without seeing your full flow, this seems like the most straightforward and common approach for your use case — sending the control message to both the HA Switch node and the SNMP node in parallel. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Node Red to work around an issue with the SNMP integration when controlling a Power Distribution Unit (PDU). The PDU outputs are controlled using SNMP messages generated in Node Red instead of the SNMP integration because the SNMP integration expects the PDU outlet state to be a simple on/off value instead of the dozen or so outlet states the PDU returns.
I use the Switch ON/OFF output ports to trigger corresponding SNMP nodes to command the PDU to turn an outlet on or off. Everything work fine if I actuate the switch from HA. Changing the switch state from Node Red fails however because the same msg.enable property needed to actuate the switch also inhibits the Switch outputs. So, the SNMP nodes don't fire and the PDU outlet does nothing.
One workaround is to send the On/Off message to the Switch node so the switch state is reflected in HA and also the the corresponding SNMP node. This is simple enough but seems really non-intuitive to me. Another workaround is to add a node that checks for state changes on the HA side, feeding that into a switch node, and then to the SNMP nodes that actually actuate the PDU outlet. This is even less intuitive since it uses an "invisible" causal relationship between the Switch and Status nodes (i.e. the outlet state in HA) to work. Flows are supposed to make causal relationships like this obvious.
There must be some subtlety I'm missing here. Why is this the as-designed behavior? The most common use case would seem to be having the Switch node always issue outputs (consistent with the "Output only on state change" flag). If knowing the source of the switch state change is important then indicating that in a property of the Switch output message. A Node Red "Switch" node after the HA Switch node would cover things. The workarounds either look like a workaround or force the flow to rely on spooky action at a distance:-)
Beta Was this translation helpful? Give feedback.
All reactions