HueMagic show light status

I am using HueMagic and can't show the state on the dashboard. It works fine if I turn a light on from the dashboard but if I turn it one from a wall mounted hue switch I can show the state on the dashboard. Any help appreciated, thanks

I haven't used that light, but since no-one else has jumped in I will ask a relevant question. Do you know how to get the current status of the light (on/off) into node-red from the light?

You can for a test pass in the Inject node a msg.payload.status for it to return the state without making any change to the lights

image

image

The debug will have msg.payload.on with TRUE or FALSE

image

So you can do the above to watch what the switch does when it turns on your light.

so for example i have a BUTTON on my dashboard and depending if light is On or OFF
changes the button colour.

The function just does simple Payload.on TRUE/FALSE test to change colours.

Colin, thanks as usual. this is the debug output of the light and I was trying to strip out on:xxxx and feed it to a button which changes state dependant on the out put of this node but also the same button turns the light on and off. The light node has an input as well as an output.

thanks

Dave

Kazzy... if only I knew what to do to make that happen, can you let me have the flow please. thanks

You should be able to use a Switch node, if I understand what you want to do. Configure it to output whatever you need to switch the light on and off (which appropriate change node if necessary to build the appropriate message. Get that working first. From what you say I think you may have that going already.
Next feed the value coming back from the light into a change node to set the payload to exactly the same as the switch generates. So if, for example, the switch is configured to output boolean true/false then the you want the message coming back from the light to be exactly that. Put a debug on the output of the switch and another on the adjusted value coming back from the light and check they show the same value and type when you work the switch. So in the case I suggested, when you switch the switch On you should see boolean true coming out of the switch, the light should go on and you should then see the boolean true out of the adjusted value coming back from the light.
Now, in the switch OFF the message passthrough checkbox and set Switch Icon Shows State of Input. Make sure you do that or you may get an infinite loop. Then connect the adjusted output from the light into the front of the switch.
What should now happen is the when you switch the switch it does not immediately move (though you should not notice that), the light will switch on, the value will come back in, and the switch will move.
Similarly if the light is switched by another route external to node red the switch will follow it.

Ok here is my example flow. However you will hopefully be able to make a couple of changes
so that it fits to your setup.

  1. Will need to update Bedroom light so it uses your HueBridge config details and then select the light you want to use,
  2. Change it so it used you default Dashboard page

but at its very basic the function is just doing the following condition

if (msg.payload.on === true)

[{"id":"b022026f.e010a","type":"hue-light","z":"e18f26b1.221168","name":"MyBedroom","bridge":"52aeb2a8.fd470c","lightid":"5","colornamer":false,"skipevents":false,"universalevents":false,"x":190,"y":1480,"wires":[["48d2fdf8.908b54"]]},{"id":"48d2fdf8.908b54","type":"function","z":"e18f26b1.221168","name":"Enable/Disable Button","func":"/* msg.payload.on will be \n   false (light is off)\n   true  (light is on)\n   \n   so set different colour for the Button On/Off state\n*/\n    \nif (msg.payload.on === true) \n{\n    msg.background = \"#097479\"\n    msg.iconcolour = \"#FFCC66\"\n    msg.btn_label  = \"Bedroom\"\n    /* store the current light state into a flow variable */\n    flow.set(\"btnBedroomLightState\",true)\n}\nelse\n{\n    msg.background = \"#808080\"\n    msg.iconcolour = \"rgba(0,0,0,0.38)\"\n    msg.btn_label  = \"Bedroom\"\n    /* store the current light state into a flow variable */\n    flow.set(\"btnBedroomLightState\",false)\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":1480,"wires":[["20770716.9c5e68"]]},{"id":"2a7ea194.0d781e","type":"function","z":"e18f26b1.221168","name":"Toggle Light State","func":"/* clear out all msg. */\nmsg.payload = {}\n\n/* Toggle boolean state.. True becomes False and False becomes True */\nmsg.payload.on = !flow.get(\"btnBedroomLightState\")\n\n/* Store the state back */\nflow.set(\"btnBedroomLightState\",msg.payload.on) \n\n/* Send the new state back to the light\nso if it was on it will now send Off to it */\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":1480,"wires":[["b022026f.e010a"]]},{"id":"20770716.9c5e68","type":"ui_button","z":"e18f26b1.221168","name":"Bedroom","group":"1d854e2.4e703b2","order":11,"width":2,"height":2,"passthru":false,"label":"{{btn_label}}","tooltip":"","color":"{{iconcolour}}","bgcolor":"{{background}}","icon":"fa-lightbulb-o fa-3x","payload":"false","payloadType":"bool","topic":"","x":560,"y":1480,"wires":[["2a7ea194.0d781e"]]},{"id":"52aeb2a8.fd470c","type":"hue-bridge","name":"Philips hue","bridge":"192.168.0.136","key":"CcxHU-NoeE3QR","interval":"800","disableupdates":false},{"id":"1d854e2.4e703b2","type":"ui_group","name":"Main","tab":"6e172f59.18ec8","order":1,"disp":false,"width":"8","collapse":false},{"id":"6e172f59.18ec8","type":"ui_tab","name":"System","icon":"dashboard","disabled":false,"hidden":false}]

It should even capture if you turn the light off using the physical light switch.

Colin/Kazzy

Thank you both for your input, now got it working,

Stay safe
Cheers Dave

1 Like

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