How to use a payload object? Node Red - Hue buttons #variables #hue-events #hue-remote #remote - solved

Hi guys,

I have a bathroom automation using a PIR that switches on a Philips Hue striplight which is embedded in the wall and starts to play music over ceiling speakers. When no movement is detected for 15 mins it all switches off.

This works great… for me. The wife however at times takes long baths, reading books… and that involves too little movement for the PIR.

I have a Hue button remote that I’d like to use as an override and I am having trouble to do so.

I created an input boolean as an override switch that I would like to control with the button using Node Red.

I can capture button press events using the native functionality as well as the Node Red Hue addon, but this gives me an object in my payload. I’ve not used objects before. See the payloads I capture below:
image

I would like to use that to trigger the override here:
image

Can anyone guide me as to what is the best way to use the Hue button as a trigger and how to make use of this object to set the boolean on and off depending on the button press?

Neither options gives me the name of the button as you get when you test it under ‘developer tools’ so I might be going down the wrong track?


(ps, ignore the fact that it says study - I was just testing with another button)

Many thanks

I believe you just need to use json node to convert this to arrays. After converting this to arrays you can simply use a switch node to check the state to the path of the array.

https://cookbook.nodered.org/basic/convert-json

image

if you change the debug node, Native, to output msg.payload.event you’ll see the same data as you do in the HA output. You can also just click the little side ways arrows to expand and collapse the data in the debug window.

In case this helps anyone, I managed to get it sorted. See my Node Red code below:

 [{"id":"82c03a3e.979678","type":"server-state-changed","z":"a91746a.8c7e7b8","name":"Bth PIR","server":"ae812271.6043b","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.ds_bathrm_motion_419","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":70,"y":360,"wires":[["eb41de2f.c365e","bfd9d8be.aa4498","aaf7090f.044778","2abb1272.ae855e"],["2abb1272.ae855e","aaf7090f.044778","eb41de2f.c365e"]]},{"id":"eb41de2f.c365e","type":"debug","z":"a91746a.8c7e7b8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":110,"y":240,"wires":[]},{"id":"bfd9d8be.aa4498","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Bathrm Light On","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"{{flow.var_light}}","data":"{\"rgb_color\": [235, 164, 52], \"brightness_pct\": 80}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":360,"y":240,"wires":[[]]},{"id":"2abb1272.ae855e","type":"trigger","z":"a91746a.8c7e7b8","name":"","op1":"","op2":"off","op1type":"nul","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"min","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":110,"y":500,"wires":[["4dd0577.06fbaa8"]]},{"id":"412dbb4a.ce4214","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Bathrm Light Off","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"{{flow.var_light}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":480,"wires":[[]]},{"id":"a9de754b.734468","type":"inject","z":"a91746a.8c7e7b8","d":true,"name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":690,"y":60,"wires":[["aaf7090f.044778"]]},{"id":"aaf7090f.044778","type":"switch","z":"a91746a.8c7e7b8","name":"on off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":380,"wires":[["369736da.a96e3a"],[]]},{"id":"748d8377.9ec5fc","type":"switch","z":"a91746a.8c7e7b8","name":"Is It Playing","property":"state","propertyType":"msg","rules":[{"t":"eq","v":"playing","vt":"str"},{"t":"neq","v":"playing","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":650,"y":340,"wires":[[],["dd0f7ce.673358"]]},{"id":"9abc6c41.8e22","type":"better-sonos-control","z":"a91746a.8c7e7b8","confignode":"717e13e9.a8d4ac","name":"Pause Sonos bath","mode":"pause","track":"","volume":"","volume_value":"","x":630,"y":540,"wires":[]},{"id":"dd0f7ce.673358","type":"delay","z":"a91746a.8c7e7b8","name":"delay 500ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":870,"y":340,"wires":[["1cf6ca5c.034e76"]]},{"id":"1cf6ca5c.034e76","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Get Tunes","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"media_player","service":"select_source","entityId":"{{flow.var_play}}","data":"{\"source\":\"{{var_tunes}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":380,"wires":[["3ef5cc60.68fce4"]]},{"id":"3ef5cc60.68fce4","type":"delay","z":"a91746a.8c7e7b8","name":"delay 500ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1210,"y":380,"wires":[["db41db90.577798"]]},{"id":"cad9b7d1.ea67f8","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Play tunes","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"media_player","service":"media_play","entityId":"{{flow.var_play}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":870,"y":500,"wires":[["fec7599b.129b98","bc6f083.e0a2df8"]]},{"id":"db41db90.577798","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Shuffle Tunes","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"media_player","service":"shuffle_set","entityId":"{{flow.var_play}}","data":"{\"shuffle\": \"true\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":880,"y":440,"wires":[["2042ee5d.8d7702"]]},{"id":"2042ee5d.8d7702","type":"delay","z":"a91746a.8c7e7b8","name":"delay 500ms","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1210,"y":440,"wires":[["cad9b7d1.ea67f8"]]},{"id":"fec7599b.129b98","type":"debug","z":"a91746a.8c7e7b8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1210,"y":560,"wires":[]},{"id":"bc6f083.e0a2df8","type":"better-sonos-status","z":"a91746a.8c7e7b8","confignode":"717e13e9.a8d4ac","name":"Bathroom","x":1200,"y":500,"wires":[[]]},{"id":"369736da.a96e3a","type":"better-sonos-status","z":"a91746a.8c7e7b8","confignode":"717e13e9.a8d4ac","name":"Bathroom","x":500,"y":380,"wires":[["748d8377.9ec5fc"]]},{"id":"dcb532d6.248ba","type":"comment","z":"a91746a.8c7e7b8","name":"Entity Variables","info":"","x":120,"y":40,"wires":[]},{"id":"9142b244.80d8c","type":"inject","z":"a91746a.8c7e7b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":100,"wires":[["9576f2e7.5b87f"]]},{"id":"9576f2e7.5b87f","type":"change","z":"a91746a.8c7e7b8","name":"ENTITY VARIABLES","rules":[{"t":"set","p":"var_play","pt":"flow","to":"media_player.bathroom","tot":"str"},{"t":"set","p":"var_light","pt":"flow","to":"light.ds_bathroom_strip","tot":"str"},{"t":"set","p":"var_tunes","pt":"flow","to":"BigMix2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":100,"wires":[[]]},{"id":"f949c50e.21d018","type":"comment","z":"a91746a.8c7e7b8","name":"Lights and Music","info":"SWITCHED OFF RUNNING ON PI4 as test","x":120,"y":200,"wires":[]},{"id":"b2782215.93d1","type":"server-events","z":"a91746a.8c7e7b8","name":"HueEvent","server":"2993e8b4.fc1e78","event_type":"hue_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":120,"y":800,"wires":[["7645273c.0a12c8"]]},{"id":"7645273c.0a12c8","type":"switch","z":"a91746a.8c7e7b8","name":"Device","property":"payload.event.id","propertyType":"msg","rules":[{"t":"eq","v":"study_switch","vt":"str"},{"t":"eq","v":"ds_bathroom_switch","vt":"str"},{"t":"eq","v":"lounge_switch","vt":"str"},{"t":"eq","v":"kitchen_switch","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":290,"y":800,"wires":[[],["2ab287dd.f50f58"],[],[]]},{"id":"2ab287dd.f50f58","type":"switch","z":"a91746a.8c7e7b8","name":"Bath Button","property":"payload.event.event","propertyType":"msg","rules":[{"t":"eq","v":"1003","vt":"num"},{"t":"eq","v":"2003","vt":"num"},{"t":"eq","v":"3003","vt":"num"},{"t":"eq","v":"1002","vt":"num"},{"t":"eq","v":"4002","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":490,"y":780,"wires":[[],[],[],["1192f09b.b9691f"],["55315edc.cd36b"]]},{"id":"1192f09b.b9691f","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Override On","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.bathroom_override","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":710,"y":780,"wires":[[]]},{"id":"55315edc.cd36b","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Override Off","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.bathroom_override","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":710,"y":840,"wires":[[]]},{"id":"e544ad43.e8fdd","type":"comment","z":"a91746a.8c7e7b8","name":"PIR Override on HUE button ","info":"SWITCHED OFF RUNNING ON PI4 as test","x":160,"y":720,"wires":[]},{"id":"4dd0577.06fbaa8","type":"api-current-state","z":"a91746a.8c7e7b8","name":"Chrck Override","server":"ae812271.6043b","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.bathroom_override","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":320,"y":500,"wires":[["412dbb4a.ce4214","9abc6c41.8e22"],["fccef05b.f0052"]]},{"id":"fccef05b.f0052","type":"delay","z":"a91746a.8c7e7b8","name":"delay 2hrs","pauseType":"delay","timeout":"2","timeoutUnits":"hours","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":410,"y":620,"wires":[["412dbb4a.ce4214","9abc6c41.8e22","114978a5.fb9c87"]]},{"id":"114978a5.fb9c87","type":"api-call-service","z":"a91746a.8c7e7b8","name":"Override_OFF","server":"ae812271.6043b","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.bathroom_override","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":620,"y":620,"wires":[[]]},{"id":"ae812271.6043b","type":"server","name":"Home Assistant"},{"id":"717e13e9.a8d4ac","type":"better-sonos-config","name":"Bathroom","serialnum":"00-0E-58-11-34-BE:7","ipaddress":"192.168.1.223"},{"id":"2993e8b4.fc1e78","type":"server","name":"Home Assistant","addon":true}]

Thanks guys!