Node Red Master Class – #2 Advanced Flow

Node Red Master Class – #2 an Advanced Flow.

In this tutorial we look at how to configure a more advanced flow. We will look at how to use a Flow Variable as well as additional nodes.

The flow covers automates 2 lights with a PIR and some timers to turn the lights back off. I will show you how to use a enable or disable the automation via a physical switch via a Shelly 1.

Nodes we’ll look at:

  • Switch Node
  • Wait Until Node
  • Comment Node
  • Current State Node
  • Link In Node
  • Link Out Node

Starting Flow from this Video:

[{"id":"eb14e751.cd81a8","type":"server-state-changed","z":"ca13c281.83306","name":"PIR ON","server":"22f5da40.d3e236","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.pir_side","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":260,"y":220,"wires":[["f8fcfd46.0dc1e","9f04729e.146c9"],["70b61c12.227fd4","f8fcfd46.0dc1e"]]},{"id":"9a6b0b92.a98808","type":"api-call-service","z":"ca13c281.83306","name":"Light ON","server":"22f5da40.d3e236","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.boot_room_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":720,"y":140,"wires":[["44550d9f.81f824"]]},{"id":"a49fe551.142738","type":"api-call-service","z":"ca13c281.83306","name":"Light OFF","server":"22f5da40.d3e236","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.boot_room_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":800,"y":260,"wires":[[]]},{"id":"70b61c12.227fd4","type":"delay","z":"ca13c281.83306","name":"10 Sec Delay","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":630,"y":260,"wires":[["a49fe551.142738"]]},{"id":"69c09f2e.db723","type":"inject","z":"ca13c281.83306","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":120,"wires":[[]]},{"id":"f8fcfd46.0dc1e","type":"debug","z":"ca13c281.83306","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":100,"wires":[]},{"id":"eb3f923d.0ae65","type":"debug","z":"ca13c281.83306","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1090,"y":160,"wires":[]},{"id":"44550d9f.81f824","type":"change","z":"ca13c281.83306","name":"Change Message","rules":[{"t":"set","p":"Boot room light status","pt":"flow","to":"ON","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":200,"wires":[["eb3f923d.0ae65"]]},{"id":"9f04729e.146c9","type":"time-range-switch","z":"ca13c281.83306","name":"Sunset to Sunrise","lat":"","lon":"","startTime":"sunset","endTime":"sunrise","startOffset":"-1","endOffset":"+1","x":570,"y":200,"wires":[["9a6b0b92.a98808"],[]]},{"id":"22f5da40.d3e236","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Completed Flow from this Video:

[{"id":"b7265e20.3de64","type":"server-state-changed","z":"ca13c281.83306","name":"PIR ON","server":"22f5da40.d3e236","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.pir_side","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":230,"y":260,"wires":[["beb615b8.fc04b8"],[]]},{"id":"36cdb5ab.e4a52a","type":"api-call-service","z":"ca13c281.83306","name":"B/R Light ON","server":"22f5da40.d3e236","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.boot_room_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":400,"wires":[[]]},{"id":"7d3cb1fa.30f8b","type":"api-call-service","z":"ca13c281.83306","name":"B/R Light OFF","server":"22f5da40.d3e236","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.boot_room_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1250,"y":340,"wires":[[]]},{"id":"c184b915.29ac88","type":"delay","z":"ca13c281.83306","name":"30 Sec Delay","pauseType":"delay","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1070,"y":340,"wires":[["7d3cb1fa.30f8b"]]},{"id":"46cfa3f5.a91b3c","type":"inject","z":"ca13c281.83306","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":180,"wires":[["beb615b8.fc04b8"]]},{"id":"beb615b8.fc04b8","type":"time-range-switch","z":"ca13c281.83306","name":"Sunset to Sunrise","lat":"","lon":"","startTime":"sunset","endTime":"sunrise","startOffset":"-1","endOffset":"+1","x":490,"y":280,"wires":[["ef3a961b.8fd058","62adebbd.efed14"],["62adebbd.efed14","ef3a961b.8fd058"]]},{"id":"b55d4f1e.2be58","type":"api-current-state","z":"ca13c281.83306","name":"O/S State","server":"22f5da40.d3e236","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.outside_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":220,"wires":[["5ffca661.3e6db8","f09627e3.e3bef8"],[]]},{"id":"f2de15f2.77b6f8","type":"switch","z":"ca13c281.83306","name":"Switch","property":"BRautomation","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":640,"wires":[["c246fba9.9f9c48"],["5ca48a0b.b58174"]]},{"id":"5ffca661.3e6db8","type":"api-call-service","z":"ca13c281.83306","name":"O/S Light ON","server":"22f5da40.d3e236","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.outside_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":260,"wires":[[]]},{"id":"de47ba50.2e8828","type":"api-call-service","z":"ca13c281.83306","name":"O/S Light OFF","server":"22f5da40.d3e236","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.outside_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":200,"wires":[[]]},{"id":"f09627e3.e3bef8","type":"delay","z":"ca13c281.83306","name":"5 Min Delay","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1070,"y":200,"wires":[["de47ba50.2e8828"]]},{"id":"18aab5d7.ee8a4a","type":"api-current-state","z":"ca13c281.83306","name":"B/R State","server":"22f5da40.d3e236","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.boot_room_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":380,"wires":[["36cdb5ab.e4a52a","c184b915.29ac88"],[]]},{"id":"13cb37e4.795998","type":"server-state-changed","z":"ca13c281.83306","name":"B/R On","server":"22f5da40.d3e236","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.boot_room_light","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":360,"y":620,"wires":[["ba3149d4.623148"],[]]},{"id":"ba3149d4.623148","type":"ha-wait-until","z":"ca13c281.83306","name":"B/R Off","server":"22f5da40.d3e236","outputs":2,"entityId":"switch.boot_room_light","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"500","timeoutType":"num","timeoutUnits":"milliseconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":510,"y":620,"wires":[["f2de15f2.77b6f8"],[]]},{"id":"54e725d0.b1246c","type":"debug","z":"ca13c281.83306","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":640,"wires":[]},{"id":"5ca48a0b.b58174","type":"change","z":"ca13c281.83306","name":"BRautomation true","rules":[{"t":"set","p":"payload","pt":"msg","to":"BRautomation True","tot":"str"},{"t":"set","p":"BRautomation","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":660,"wires":[["54e725d0.b1246c"]]},{"id":"e4b83c53.1a339","type":"server-state-changed","z":"ca13c281.83306","name":"B/R Off","server":"22f5da40.d3e236","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.boot_room_light","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","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":360,"y":680,"wires":[["6a424b06.ee72c4"],[]]},{"id":"6a424b06.ee72c4","type":"ha-wait-until","z":"ca13c281.83306","name":"B/R On","server":"22f5da40.d3e236","outputs":2,"entityId":"switch.boot_room_light","entityIdFilterType":"exact","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"500","timeoutType":"num","timeoutUnits":"milliseconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":520,"y":680,"wires":[["f2de15f2.77b6f8"],[]]},{"id":"c246fba9.9f9c48","type":"change","z":"ca13c281.83306","name":"BRautomation false","rules":[{"t":"set","p":"payload","pt":"msg","to":"BRautomation False","tot":"str"},{"t":"set","p":"BRautomation","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":600,"wires":[["54e725d0.b1246c"]]},{"id":"c077302d.0b591","type":"inject","z":"ca13c281.83306","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":550,"y":540,"wires":[["f2de15f2.77b6f8"]]},{"id":"ef3a961b.8fd058","type":"switch","z":"ca13c281.83306","name":"Switch","property":"BRautomation","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":690,"y":380,"wires":[["18aab5d7.ee8a4a"]]},{"id":"1c616ee9.c04191","type":"switch","z":"ca13c281.83306","name":"Switch","property":"OSautomation","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":900,"wires":[["44ba17f6.672398"],["349b657b.10feea"]]},{"id":"a59eb74d.027218","type":"server-state-changed","z":"ca13c281.83306","name":"O/S On","server":"22f5da40.d3e236","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.outside_light","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":360,"y":880,"wires":[["db8c96c5.0a9ac8"],[]]},{"id":"db8c96c5.0a9ac8","type":"ha-wait-until","z":"ca13c281.83306","name":"O/S Off","server":"22f5da40.d3e236","outputs":2,"entityId":"switch.outside_light","entityIdFilterType":"exact","property":"state","comparator":"is","value":"off","valueType":"str","timeout":"500","timeoutType":"num","timeoutUnits":"milliseconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":520,"y":880,"wires":[["1c616ee9.c04191"],[]]},{"id":"52357a58.fc9454","type":"debug","z":"ca13c281.83306","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":900,"wires":[]},{"id":"349b657b.10feea","type":"change","z":"ca13c281.83306","name":"OSautomation true","rules":[{"t":"set","p":"payload","pt":"msg","to":"OSautomation True","tot":"str"},{"t":"set","p":"OSautomation","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":920,"wires":[["52357a58.fc9454"]]},{"id":"eacd3718.db6988","type":"server-state-changed","z":"ca13c281.83306","name":"O/S Off","server":"22f5da40.d3e236","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.outside_light","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","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":360,"y":940,"wires":[["54a29116.94b63"],[]]},{"id":"54a29116.94b63","type":"ha-wait-until","z":"ca13c281.83306","name":"O/S On","server":"22f5da40.d3e236","outputs":2,"entityId":"switch.outside_light","entityIdFilterType":"exact","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"500","timeoutType":"num","timeoutUnits":"milliseconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":520,"y":940,"wires":[["1c616ee9.c04191"],[]]},{"id":"44ba17f6.672398","type":"change","z":"ca13c281.83306","name":"OSautomation false","rules":[{"t":"set","p":"payload","pt":"msg","to":"OSautomationn False","tot":"str"},{"t":"set","p":"OSautomation","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":860,"wires":[["52357a58.fc9454","e2a5e1a8.73495"]]},{"id":"eaf3b1f5.eb8a6","type":"inject","z":"ca13c281.83306","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":550,"y":800,"wires":[["1c616ee9.c04191"]]},{"id":"62adebbd.efed14","type":"switch","z":"ca13c281.83306","name":"Switch","property":"OSautomation","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":690,"y":240,"wires":[["b55d4f1e.2be58"]]},{"id":"88f7749f.76c418","type":"change","z":"ca13c281.83306","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":140,"wires":[["f09627e3.e3bef8"]]},{"id":"73a902bd.45f85c","type":"inject","z":"ca13c281.83306","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":620,"y":140,"wires":[["88f7749f.76c418"]]},{"id":"e2a5e1a8.73495","type":"link out","z":"ca13c281.83306","name":"","links":["27fa9b4c.97cf64"],"x":1095,"y":820,"wires":[]},{"id":"27fa9b4c.97cf64","type":"link in","z":"ca13c281.83306","name":"","links":["e2a5e1a8.73495"],"x":655,"y":180,"wires":[["88f7749f.76c418"]]},{"id":"22f5da40.d3e236","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Haven’t got it installed yet? Don’t Panic…

Music: https://www.bensound.com

Video: Free Stock Video Footage by Videezy!