Node-Red - Lights - Check if there on or off before following a flow

Hi

I am trying to get a flow working in node-red, which will do the following.

Doorbell Press
This then checks if the light bulb is already on of if its off - (from here i want two options)
Option 1 - if the light is on, it will then change to blue, and flash for 15 seconds, then return to white
Option 2 - if the light is off - it will turn it on, then change to blue, flash for 15 seconds, return to white, then turn itself off.

(Doorbell is Ring and the lights are Philips Hue)

Can any one help? Ive tried all sorts so far, and i just cant seem to figure out the option element. In an ideal world i would have this save the current state, then run, and then return the previous state. (if thats possible?)

Thanks all

Check this out for variable functionality:
Storing Data in Node-Red Variables (steves-internet-guide.com)
Then, use a current state to get the on/off state of the bulb and then save it in a context or flow object, do the on, blue, flash, white and then set the on/off state based on your object.

Thank you.

Ill go have a read and try to get my head around it lol

Edit: So ive read it, and i dont understand it (little programming experience) - i guess ill have to learn more about node-red so i understand it better

Here’s most of the code. Create an empty flow and then click on the top-right 3-bars menu and select Import, then paste this code in:

[{"id":"8cd25121.6819d","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"e98038af.a4e548","type":"server-state-changed","z":"8cd25121.6819d","name":"Doorbell?","server":"a9088818.0cd3e8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.front_doorbell_ding","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":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":90,"y":60,"wires":[["4baf3bf7.1805a4"],[]]},{"id":"4baf3bf7.1805a4","type":"api-current-state","z":"8cd25121.6819d","name":"get light state","server":"a9088818.0cd3e8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.desk_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":110,"y":120,"wires":[["8b7d47e9.cd4718"]]},{"id":"8b7d47e9.cd4718","type":"function","z":"8cd25121.6819d","name":"save light state","func":"context.set(\"mylightstate\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":120,"y":180,"wires":[["fbfbcbfb.c93348"]]},{"id":"fbfbcbfb.c93348","type":"api-call-service","z":"8cd25121.6819d","name":"turn light on","server":"a9088818.0cd3e8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.desk_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":110,"y":240,"wires":[["53880d08.0614a4"]]},{"id":"53880d08.0614a4","type":"function","z":"8cd25121.6819d","name":"change to blue","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":120,"y":300,"wires":[["bb515e59.12295"]]},{"id":"bb515e59.12295","type":"function","z":"8cd25121.6819d","name":"flash 15 seconds","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":130,"y":360,"wires":[["15f9f2d3.c38dbd"]]},{"id":"15f9f2d3.c38dbd","type":"function","z":"8cd25121.6819d","name":"change to white","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":120,"y":420,"wires":[["27cf2b77.44e364"]]},{"id":"27cf2b77.44e364","type":"function","z":"8cd25121.6819d","name":"retrieve light state","func":"msg.payload = context.get(\"mylightstate\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":130,"y":480,"wires":[["3b11cf5.a30bc3"]]},{"id":"3b11cf5.a30bc3","type":"switch","z":"8cd25121.6819d","name":"restore light state","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":130,"y":540,"wires":[["6da091a2.dbdc1"],["78b11407.fb9d5c"]]},{"id":"6da091a2.dbdc1","type":"api-call-service","z":"8cd25121.6819d","name":"light on","server":"a9088818.0cd3e8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.desk_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":320,"y":520,"wires":[[]]},{"id":"78b11407.fb9d5c","type":"api-call-service","z":"8cd25121.6819d","name":"light off","server":"a9088818.0cd3e8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.desk_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":320,"y":560,"wires":[[]]},{"id":"a9088818.0cd3e8","type":"server","name":"Home Assistant","addon":true}]

You’ll have to change the devices to match your doorbell and light and, because I don’t have an RGB light, I don’t have anything in the change to blue, flash 15 seconds, or change to white functions (You’ll have to fill those in.) but the rest of code should work to store the light state, retrieve it, and set the light to its former state.

Another option to consider… Could be better I’m sure :slight_smile: but I too don’t have a Hue.

[{"id":"f3fc1d00.466ee","type":"trigger-state","z":"25063fae.4f85f","name":"Ring doorbell ding & light status","server":"8a3231e1.3f0e1","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.front_door_ding","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"entity_id","targetValue":"switch.entrance_porch_light","propertyType":"property","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"state"},{"targetType":"entity_id","targetValue":"switch.entrance_porch_light","propertyType":"property","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off","propertyValue":"state"}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":1745.714340209961,"y":1862.8571605682373,"wires":[["42584dc7.559224"],["88cfbc73.0e545"]]},{"id":"7de894ac.64ac9c","type":"api-call-service","z":"25063fae.4f85f","name":"Set light to Blue & flash","server":"8a3231e1.3f0e1","version":1,"debugenabled":false,"service_domain":"light","service":"","entityId":"light.entrance_porch_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":true,"x":2337.1431274414062,"y":1862.857370376587,"wires":[["a625b764.da1b38","312db02.678265"]]},{"id":"a625b764.da1b38","type":"debug","z":"25063fae.4f85f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2441.428421020508,"y":1807.1427669525146,"wires":[]},{"id":"63b32970.fec118","type":"inject","z":"25063fae.4f85f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1750.0001907348633,"y":1774.2856121063232,"wires":[["42584dc7.559224"]]},{"id":"42584dc7.559224","type":"template","z":"25063fae.4f85f","name":"Light ON Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"service\": \"turn_on\",\n    \"data\":{\n        \"entity_id\": \"switch.entrance_porch_light\",\n        \"brightness\": \"130\",\n        \"rgb_color\": [0,0,255],\n        \"flash\": \"short\"\n        }\n }","output":"json","x":2061.428985595703,"y":1837.1428928375244,"wires":[["7de894ac.64ac9c"]]},{"id":"88cfbc73.0e545","type":"template","z":"25063fae.4f85f","name":"Light OFF Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"service\": \"turn_off\",\n    \"data\":{\n        \"entity_id\": \"switch.entrance_porch_light\",\n        \"brightness\": \"130\",\n        \"rgb_color\": [0,0,255],\n        \"flash\": \"short\"\n        }\n }","output":"json","x":2061.4289474487305,"y":1894.2857313156128,"wires":[["7de894ac.64ac9c"]]},{"id":"dc6abaf5.c23e98","type":"api-call-service","z":"25063fae.4f85f","name":"Restore to White & ON","server":"8a3231e1.3f0e1","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.entrance_porch_light","data":"{\"entity_id\":\"switch.entrance_porch_light\",\"brightness\":\"130\",\"rgb_color\":[255,255,255]}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2897.142906188965,"y":1834.2858200073242,"wires":[["2da27c4e.c62114"]]},{"id":"312db02.678265","type":"switch","z":"25063fae.4f85f","name":"Select restored status","property":"payload.service","propertyType":"msg","rules":[{"t":"eq","v":"turn_on","vt":"str"},{"t":"eq","v":"turn_off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2618.5715866088867,"y":1862.857195854187,"wires":[["dc6abaf5.c23e98"],["cc183cce.b428d"]]},{"id":"2da27c4e.c62114","type":"debug","z":"25063fae.4f85f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3102.857219696045,"y":1827.1429109573364,"wires":[]},{"id":"cc183cce.b428d","type":"api-call-service","z":"25063fae.4f85f","name":"Restore to White & OFF","server":"8a3231e1.3f0e1","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.entrance_porch_light","data":"{\"data\":{\"entity_id\":\"switch.entrance_porch_light\",\"brightness\":\"130\",\"rgb_color\":[255,255,255]}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2912.8571586608887,"y":1900.0000171661377,"wires":[["b88c7739.de94b8"]]},{"id":"b88c7739.de94b8","type":"debug","z":"25063fae.4f85f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3111.4286193847656,"y":1898.5714292526245,"wires":[]},{"id":"8a3231e1.3f0e1","type":"server","name":"Hassio","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

What I do is that I listen to state changes in node red (subscribing to the MQTT topics of my bulbs) and storing them with the state node (installed via Palette manager).

You sir are a gent :slight_smile:

Ill give this an import now and ill let you know how i get on.

Huge thanks :slight_smile:

Thank you, ill also give this a go to, hopfully i can then work out how it all hangs together looking at both of these.

Thanks again

Sooo, ive tried both options above, however i still dont appear to be able to get this to do what i want.

(Light just stays blue and doesnt return back) - debug shows i cant run the data value “color_name” twice.

PS - Ignore the doorbell entity - im using motion on a kitchen camera for now saves pressing the doorbell constantly

Here is my flow

[{"id":"587c632c.1c56dc","type":"tab","label":"DoorBell - Light flash blue","disabled":true,"info":""},{"id":"f3fc1d00.466ee","type":"trigger-state","z":"587c632c.1c56dc","name":"Ring doorbell ding & light status","server":"7d041947.e86358","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.kitchen_motion","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"targetType":"entity_id","targetValue":"light.hue_color_lamp_1","propertyType":"property","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"turn_on","propertyValue":""},{"targetType":"entity_id","targetValue":"light.hue_color_lamp_1","propertyType":"property","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"turn_off","propertyValue":""}],"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":150,"y":320,"wires":[["42584dc7.559224"],["88cfbc73.0e545"]]},{"id":"7de894ac.64ac9c","type":"api-call-service","z":"587c632c.1c56dc","name":"Set light to Blue & flash","server":"7d041947.e86358","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1","data":"{\"brightness\":\"130\",\"color_name\":\"blue\",\"flash\":\"long\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":630,"y":260,"wires":[["a625b764.da1b38","4d5703.ce3948fc"]]},{"id":"a625b764.da1b38","type":"debug","z":"587c632c.1c56dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":200,"wires":[]},{"id":"63b32970.fec118","type":"inject","z":"587c632c.1c56dc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":154.28585052490234,"y":231.42845153808594,"wires":[["42584dc7.559224"]]},{"id":"42584dc7.559224","type":"template","z":"587c632c.1c56dc","name":"Light ON Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"service\": \"turn_on\",\n    \"data\":{\n        \"entity_id\": \"light.hue_color_lamp_1\"\n        }\n }","output":"json","x":370,"y":260,"wires":[["7de894ac.64ac9c"]]},{"id":"88cfbc73.0e545","type":"template","z":"587c632c.1c56dc","name":"Light OFF Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n    \"service\": \"turn_on\",\n    \"data\":{\n        \"entity_id\": \"light.hue_color_lamp_1\"\n        }\n }","output":"json","x":370,"y":380,"wires":[["8cc15b5e.11bc08"]]},{"id":"dc6abaf5.c23e98","type":"api-call-service","z":"587c632c.1c56dc","name":"Restore to White & ON","server":"7d041947.e86358","version":1,"debugenabled":true,"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":1180,"y":240,"wires":[["2da27c4e.c62114"]]},{"id":"312db02.678265","type":"switch","z":"587c632c.1c56dc","name":"Select restored status","property":"payload.service","propertyType":"msg","rules":[{"t":"eq","v":"turn_on","vt":"str"},{"t":"eq","v":"turn_off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":940,"y":300,"wires":[["dc6abaf5.c23e98"],["acf393f3.56ec6"]]},{"id":"2da27c4e.c62114","type":"debug","z":"587c632c.1c56dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1330,"y":180,"wires":[]},{"id":"cc183cce.b428d","type":"api-call-service","z":"587c632c.1c56dc","name":"Restore to White","server":"7d041947.e86358","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1","data":"{\"color_name\":\"white\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":770,"y":440,"wires":[["b88c7739.de94b8","312db02.678265"]]},{"id":"b88c7739.de94b8","type":"debug","z":"587c632c.1c56dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":910,"y":500,"wires":[]},{"id":"8cc15b5e.11bc08","type":"api-call-service","z":"587c632c.1c56dc","name":"Turn light on","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":490,"y":460,"wires":[["7de894ac.64ac9c"]]},{"id":"acf393f3.56ec6","type":"api-call-service","z":"587c632c.1c56dc","name":"Turn Light Off","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.hue_color_lamp_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1160,"y":340,"wires":[[]]},{"id":"4d5703.ce3948fc","type":"delay","z":"587c632c.1c56dc","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":700,"y":360,"wires":[["cc183cce.b428d"]]},{"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}]

Hi All

Right i am now getting somwhere.

So, if the doobell is pressed (at the moment im using a timestamp trigger to make it easier), it takes the current state, (colour, brightness or if the light is off)

This is now all working as expected, however i have one issue below:

The only issue i am having at the minute, is if the light is turned off, it doesn’t record the previous colour setting, so when you turn the light back on, its blue for example. I have this going back to white at the end of the flow, so if the light was off, it does come back on white. Now i can live with this, but it woul dbe great if i could get it to return to its previous state etc.

So, can anyone help me with a flow that will use context, to turn the light on briefly, and give 2 msg payloads, and depending if the light was on or off, to then inject the correct payload?

My current flow is below:

[{"id":"10258ce4.19a9c3","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"47d61b16.4bfe14","type":"inject","z":"10258ce4.19a9c3","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":240,"wires":[["d1c28401.6845f8","8d4e4f44.cb75e"]]},{"id":"d1c28401.6845f8","type":"api-current-state","z":"10258ce4.19a9c3","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":410,"y":240,"wires":[["c67b9c40.1e714"]]},{"id":"6ff82db6.68c944","type":"debug","z":"10258ce4.19a9c3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","statusVal":"","statusType":"auto","x":1110,"y":80,"wires":[]},{"id":"c67b9c40.1e714","type":"switch","z":"10258ce4.19a9c3","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":670,"y":240,"wires":[["1430417e.d4fe3f"],["af1d4ce8.60667"]]},{"id":"1430417e.d4fe3f","type":"change","z":"10258ce4.19a9c3","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":850,"y":200,"wires":[["4e68968e.e92788","6ff82db6.68c944"]]},{"id":"af1d4ce8.60667","type":"change","z":"10258ce4.19a9c3","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":850,"y":260,"wires":[["4e68968e.e92788","6ff82db6.68c944"]]},{"id":"6d14209d.f12ff","type":"inject","z":"10258ce4.19a9c3","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1100,"y":800,"wires":[[]]},{"id":"561b95ab.7dca2c","type":"change","z":"10258ce4.19a9c3","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"lightState","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":340,"wires":[["c659f32a.951b","16a34f34.316cd1"]]},{"id":"c659f32a.951b","type":"api-call-service","z":"10258ce4.19a9c3","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":810,"y":340,"wires":[[]]},{"id":"16a34f34.316cd1","type":"debug","z":"10258ce4.19a9c3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":770,"y":400,"wires":[]},{"id":"7ae96554.093a0c","type":"inject","z":"10258ce4.19a9c3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":880,"wires":[["9615d676.e6c408"]]},{"id":"4e68968e.e92788","type":"api-call-service","z":"10258ce4.19a9c3","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":1130,"y":220,"wires":[["e9e0be2b.61073"]]},{"id":"e9e0be2b.61073","type":"api-call-service","z":"10258ce4.19a9c3","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":1390,"y":220,"wires":[["71c2ae6e.d2793"]]},{"id":"9615d676.e6c408","type":"api-call-service","z":"10258ce4.19a9c3","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":380,"y":880,"wires":[["940b1706.ea3708"]]},{"id":"940b1706.ea3708","type":"api-call-service","z":"10258ce4.19a9c3","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_1","data":"{\"color_name\":\"white\",\"brightness\":\"255\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":630,"y":880,"wires":[[]]},{"id":"8d4e4f44.cb75e","type":"delay","z":"10258ce4.19a9c3","name":"","pauseType":"delay","timeout":"16","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":320,"y":340,"wires":[["561b95ab.7dca2c"]]},{"id":"71c2ae6e.d2793","type":"delay","z":"10258ce4.19a9c3","name":"","pauseType":"delay","timeout":"15","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1640,"y":220,"wires":[["8f492b20.89a558"]]},{"id":"8f492b20.89a558","type":"api-call-service","z":"10258ce4.19a9c3","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":1860,"y":220,"wires":[[]]},{"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}]

Hi there, did you get it to work? I’m looking for something similar. I have a automation in yaml, it works… But I want to expend the lights.

For me it only have to work when the lights are on already. The problem that I have in the yaml is that when I had more lights with the condition ON… As soon of one light is off in the list it won’t trigger.

Now I’m looking in to node red…

For my situation I would like:

Doorbell pressed - check lights if the on - off = do nothing on that specific light/ on = save current state (colour etc) - switch the lights that are on to red for 15 seconds - change the lights back to previous color.

The idea is that only the lights that are on change color, but I will have lights in the automation that are not always on, for example upstairs

Any feedback or ideas are welcome, in completely new in node red and don’t have any experience in code etc

I did, this takes the current state and injects the code back at the end.

Mine does however turn the lights on, flash and then return to current state (either off or on and colour etc) - you may need to change it to get it to do what you want.

Heres my node-red flow that might help, youll obviously need to change the light entity etc to yours.

[{"id":"1a682ae3.af9745","type":"tab","label":"DoorBell - Flash Kichen Light blue and return to state","disabled":false,"info":""},{"id":"352135f8.8ea97a","type":"inject","z":"1a682ae3.af9745","name":"Test Flow Without Press","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":100,"wires":[["c4df5bd7.67c778"]]},{"id":"c4df5bd7.67c778","type":"api-current-state","z":"1a682ae3.af9745","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_3","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":450,"y":100,"wires":[["8bbb436f.c031f"]]},{"id":"f8c1f012.870c","type":"debug","z":"1a682ae3.af9745","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","statusVal":"","statusType":"auto","x":1070,"y":60,"wires":[]},{"id":"8bbb436f.c031f","type":"switch","z":"1a682ae3.af9745","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":690,"y":100,"wires":[["54deca4f.f3a284"],["dbd3a809.90c968"]]},{"id":"54deca4f.f3a284","type":"change","z":"1a682ae3.af9745","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":870,"y":60,"wires":[["63eb2db8.238004","f8c1f012.870c"]]},{"id":"dbd3a809.90c968","type":"change","z":"1a682ae3.af9745","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":870,"y":120,"wires":[["63eb2db8.238004","f8c1f012.870c"]]},{"id":"2d456345.6347fc","type":"change","z":"1a682ae3.af9745","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"lightState","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1100,"y":420,"wires":[["dc98d32a.fe6e8","64b01724.e89e38"]]},{"id":"64b01724.e89e38","type":"api-call-service","z":"1a682ae3.af9745","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_3","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1110,"y":480,"wires":[[]]},{"id":"dc98d32a.fe6e8","type":"debug","z":"1a682ae3.af9745","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","statusVal":"","statusType":"auto","x":1290,"y":420,"wires":[]},{"id":"63eb2db8.238004","type":"api-call-service","z":"1a682ae3.af9745","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_3","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":120,"wires":[["6d0b3da5.842df4"]]},{"id":"6d0b3da5.842df4","type":"api-call-service","z":"1a682ae3.af9745","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_3","data":"{\"brightness\":\"255\",\"color_name\":\"blue\",\"flash\":\"long\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":180,"wires":[["cacc5494.109258"]]},{"id":"ee2a87c1.a6f6e8","type":"delay","z":"1a682ae3.af9745","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1080,"y":360,"wires":[["2d456345.6347fc"]]},{"id":"cacc5494.109258","type":"delay","z":"1a682ae3.af9745","name":"","pauseType":"delay","timeout":"9","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1080,"y":240,"wires":[["6598f083.96ca3"]]},{"id":"6598f083.96ca3","type":"api-call-service","z":"1a682ae3.af9745","name":"","server":"7d041947.e86358","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hue_color_lamp_3","data":"{\"color_name\":\"white\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":300,"wires":[["ee2a87c1.a6f6e8"]]},{"id":"57299bf1.a3a704","type":"trigger-state","z":"1a682ae3.af9745","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":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":180,"y":140,"wires":[["c4df5bd7.67c778"],[]]},{"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}]

My flow above used sections of this one as well :slight_smile: - So thanks Juan :slight_smile:

Oke thanks you for the feedback, when I’m at home I will dive in to it

@robjones

If you don’t mind, and you have the time… Can you explain little bit more? That code you posted, it’s all abba cadabra for me.

Do I have only to put the entity id’s on the nodes? Or do I have to write code as well?

Sorry I’m a total newbie on this, I know that when you connect node red to HA it knows the entity ID s, but for the rest im not sure, add the moment in the yaml automation I use scene.create… In not sure how to implement this in node red?

Correct me if I’m wrong, I think the flow must be:

Doorbell pressed - check current state on/off - on = save current state en colour - switch lights to red - restore previous state.

Thx in advance

Just in case you don’t know how to import…

Toward the right side of that code he posted is an option to ‘copy to clipboard’. Do that. Then in NR, click on the hamburger icon in the top right, select Import, paste the code into the text box, and click the Import button.

Thank you, I will try that

This is what you should see when you import this into node-red.

You will need to change the entity;s on the current state and svc nodes, the rest will stay the same. (You will also need to change the colour, delays and remove the flash if you dont want it)

I have to set a new flow per light bulb - i do have a flow that includes all light bulbs, but even with different states some bulbs dont go back to current state.

@robjones

i have copied you’re code into my node red, for now I have it working on one light while using the " test flow whiteout press" for some reason I can’t select my right entity for my doorbell?! I have a NEST doorbell.

i have found that the light goes from bleu flashing to white and then restore the previous state?
this is what I have now:

[{"id":"57299bf1.a3a704","type":"trigger-state","z":"1a682ae3.af9745","name":"DoorBell Press","server":"a7811bea.26e4e8","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"camera.voorkant","entityidfiltertype":"exact","debugenabled":true,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on","propertyValue":"new_state.state"}],"outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":180,"y":140,"wires":[["c4df5bd7.67c778"],[]]},{"id":"a7811bea.26e4e8","type":"server","name":"Home Assistant","addon":true}]

Yeah, you will need to alter one of the svc nodes, mine was to flash blue, so you need to remove the flash and set the colour to your preferred colour.

Unfortunately my doorbell is ring.

As yours is nest, you’ll need to do the Nest integration into HA, once its in there, you will be able to see the nest doorbell entity and make the changes. (Nest Integration is a pain, you need a google dev account, plus HA needs to be available on the internet, i use cabu nasa to make this easier)