Search code examples
node-red

Update Switch State


I have a flow with where I have a Hue Node -> Switch -> Service Node

Toggling the Switch on and off and I can call the service node and then turn off the light via Home Assistant to Hue just fine. The issue I'm trying to solve is the state of the Switch. I'f I use the Hue app to turn off a light I would like the state of the switch to reflect the state of the light as well so everything is in sync.

However, I'm not sure how to make the switch react to the state of the bulb. I can see the state of the bulb but I'm not sure how to reflect it on the switch.

enter image description here

Edit: Added Output

{
  "on":false,
  "reachable":true,
  "bri":100,
  "xy":[0.4595,0.4105],
  "hsv":[82,56,100],
  "rgb":[202,254,111],
  "hex":"CAFE6F",
  "color":"khaki",
  "mired":369,
  "kelvin":2710
}

Solution

  • Assuming that the sample you posted is msg.payload then you should be able to use a change node to take the msg.payload.on value and move it to msg.payload.

    enter image description here

    If you then uncheck the "If msg arrives on input, pass through to output: " checkbox this will mean it won't get caught in a loop updating.