Strange issue with a node-red flow - saving state/context working - but adding a trigger causes issues

I have built a flow, which in essense, flashes my philips hue lights and returns them back to the previous state, or if there turned on, they set back to white before turning off.

Now if i do a timestamp to test the flow, this works perfectly.

If i set the trigger to my doorbell press (ring), this sets the flow off, but then does some strange things and leaves the lights turned on, but in blue.

I dont suppose one of you experts could take a look for me? (as its saving state and using context, i may be missing somthing, or not blocking part of the msg payload, however ive exhausted this for a few days looking into it so i would appreciate any help :slight_smile:

This is the flow:

[{"id":"3e135d42.436a52","type":"tab","label":"DoorBell - Flash Kitchen Light blue and return to state","disabled":false,"info":""},{"id":"6dc7a18e.2b8a8","type":"inject","z":"3e135d42.436a52","name":"Test Flow Without Press","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":120,"wires":[["90e07986.d878f8"]]},{"id":"90e07986.d878f8","type":"api-current-state","z":"3e135d42.436a52","name":"","server":"7d041947.e86358","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.hue_color_lamp_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":650,"y":120,"wires":[["ca363a69.a2c8e8"]]},{"id":"6e604327.216aec","type":"debug","z":"3e135d42.436a52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","statusVal":"","statusType":"auto","x":1430,"y":40,"wires":[]},{"id":"ca363a69.a2c8e8","type":"switch","z":"3e135d42.436a52","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":120,"wires":[["62cd638d.d3c44c"],["d9dff6e2.7016c8"]]},{"id":"62cd638d.d3c44c","type":"change","z":"3e135d42.436a52","name":"","rules":[{"t":"set","p":"lightState","pt":"flow","to":"{ \"service\" : \"turn_on\",\t  \"data\" : { \t  \"entity_id\" : $string(topic),\t  \"brightness\" : $number(data.attributes.brightness),\t  \"rgb_color\" : data.attributes.rgb_color\t  }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1110,"y":80,"wires":[["f5b7891.11f5978","6e604327.216aec"]]},{"id":"d9dff6e2.7016c8","type":"change","z":"3e135d42.436a52","name":"","rules":[{"t":"set","p":"lightState","pt":"flow","to":"{ \"service\" : \"turn_off\",\t  \"data\" : { \t  \"entity_id\" : $string(topic)\t  }\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1110,"y":140,"wires":[["f5b7891.11f5978","6e604327.216aec"]]},{"id":"d47352c2.3a2b","type":"change","z":"3e135d42.436a52","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"lightState","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":240,"wires":[["f99b5d18.df1b1","a1846e33.181d9"]]},{"id":"a1846e33.181d9","type":"api-call-service","z":"3e135d42.436a52","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1030,"y":240,"wires":[[]]},{"id":"f99b5d18.df1b1","type":"debug","z":"3e135d42.436a52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","statusVal":"","statusType":"auto","x":1030,"y":400,"wires":[]},{"id":"f5b7891.11f5978","type":"api-call-service","z":"3e135d42.436a52","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1350,"y":140,"wires":[["9e97f680.d32b88"]]},{"id":"9e97f680.d32b88","type":"api-call-service","z":"3e135d42.436a52","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1","data":"{\"brightness\":\"255\",\"color_name\":\"blue\",\"flash\":\"long\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1450,"y":220,"wires":[["1762dfad.249a8"]]},{"id":"4709b58c.b701cc","type":"delay","z":"3e135d42.436a52","name":"","pauseType":"delay","timeout":"11","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560,"y":240,"wires":[["d47352c2.3a2b"]]},{"id":"1762dfad.249a8","type":"delay","z":"3e135d42.436a52","name":"","pauseType":"delay","timeout":"9","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1580,"y":140,"wires":[["efe5277f.2ce5a8"]]},{"id":"efe5277f.2ce5a8","type":"api-call-service","z":"3e135d42.436a52","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1","data":"{\"color_name\":\"white\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1710,"y":220,"wires":[[]]},{"id":"397858e9.38fdf8","type":"trigger-state","z":"3e135d42.436a52","name":"DoorBell Press","server":"7d041947.e86358","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.robs_front_door_ding","entityidfiltertype":"exact","debugenabled":true,"constraints":[],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":260,"y":240,"wires":[["90e07986.d878f8","4709b58c.b701cc"],[]]},{"id":"7d041947.e86358","type":"server","name":"Home Assistant - Pi","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

For any one that cares, i have managed to fix the issue.

What was happening when the doorbell was pressed, it sent the flow off correctly, however when the doorbell reset back to off, it set the flow off again. Thus changing the context and saved state, and causing random things with the lights.

I set the doorbell to only listen to the "on", by doing this, when it times out back to off, it doesnt set the flow off again.

1 Like

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