Home Assistant Vacation Mode
This node-red flow automates random turn_on and turn_off service calls against a group of lights or switches.
It is based on a HomeAssistant Script by Jeffrey Stone. Check out his Youtube channel SlackerLabs at https://www.youtube.com/channel/UCipZJ6748kd8TbelSxcvcVg or his webpage at https://slacker-labs.com/
To use this flow you will need:
A Home Assistant group in groups.yaml named vacation_lights containing the list of entities you want to automate
An input boolean helper and an associated dashboard button that toggles it on or off.
HomeAssistant with Node-Red installed as an add-on.
Install the node-red-contrib-random-item node
Create your group, add your button, install the node-red-contrib-random-item node and import the flow. The script is meant to only automate lights while the sun is below the horizon. If the sun comes up, it will wait until the sun is once again below the horizon and then resume operation.
When the Vacation Mode button is toggled off, the script will turn on all of your devices and then exit.
[{"id":"9e4ee03cbb1cc389","type":"tab","label":"Vacation Mode","disabled":false,"info":"","env":[]},{"id":"09feb63a78325b06","type":"delay","z":"9e4ee03cbb1cc389","name":"Wait 3 to 10 Min","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"180","randomLast":"180","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":960,"y":580,"wires":[["b451c754ea878750"]]},{"id":"a7c031c1fb862fd1","type":"server-state-changed","z":"9e4ee03cbb1cc389","name":"Watch for Vacation Mode Button Press","server":"aa0e51592ade96f6","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.vacation_mode","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,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":870,"y":60,"wires":[["33b3601e1c67ccde"],[]]},{"id":"33b3601e1c67ccde","type":"ha-wait-until","z":"9e4ee03cbb1cc389","name":"Wait until Sun is Below the Horizon","server":"aa0e51592ade96f6","version":1,"outputs":1,"entityId":"sun.sun","entityIdFilterType":"exact","property":"state","comparator":"is","value":"below_horizon","valueType":"str","timeout":"0","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"data","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":860,"y":120,"wires":[["5b39d8ca2adf02c7"]]},{"id":"13c27093d1971902","type":"link in","z":"9e4ee03cbb1cc389","name":"","links":["b451c754ea878750"],"x":665,"y":120,"wires":[["33b3601e1c67ccde"]]},{"id":"b451c754ea878750","type":"link out","z":"9e4ee03cbb1cc389","name":"Go Check the Sun","mode":"link","links":["13c27093d1971902"],"x":1095,"y":580,"wires":[]},{"id":"7e9315e3f115cf9e","type":"comment","z":"9e4ee03cbb1cc389","name":"Vacation Button is on the HA Dashboard","info":"","x":870,"y":20,"wires":[]},{"id":"69692657f0df18d3","type":"ha-get-entities","z":"9e4ee03cbb1cc389","name":"ON List","server":"aa0e51592ade96f6","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.vacation_lights","valueType":"str"},{"property":"state","logic":"is","value":"on","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":260,"y":460,"wires":[["a6070cc130bda46f"]]},{"id":"fdb0f650a8807341","type":"random-item","z":"9e4ee03cbb1cc389","name":"Choose One","input":"payload","inputType":"msg","output":"payload","outputType":"msg","number":1,"x":610,"y":460,"wires":[["4751c1af82610168"]]},{"id":"4751c1af82610168","type":"change","z":"9e4ee03cbb1cc389","name":"Set Values","rules":[{"t":"set","p":"payload.service","pt":"msg","to":"turn_off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":460,"wires":[["9c2e81e18bcf7427"]]},{"id":"947dd4288b087552","type":"ha-get-entities","z":"9e4ee03cbb1cc389","name":"OFF List","server":"aa0e51592ade96f6","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.vacation_lights","valueType":"str"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":260,"y":500,"wires":[["89da9405dab8b88f"]]},{"id":"9c2e81e18bcf7427","type":"api-call-service","z":"9e4ee03cbb1cc389","name":"Service Call","server":"aa0e51592ade96f6","version":5,"debugenabled":false,"domain":"homeassistant","service":"{{payload.service}}","areaId":[],"deviceId":[],"entityId":["{{payload.entity_id}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":930,"y":480,"wires":[["09feb63a78325b06"]]},{"id":"467b4da156bd436d","type":"switch","z":"9e4ee03cbb1cc389","name":"Off or On","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":100,"y":480,"wires":[["69692657f0df18d3"],["947dd4288b087552"]]},{"id":"38e7081d42f7165b","type":"random","z":"9e4ee03cbb1cc389","name":"Set Random Off or On Value","low":"0","high":"1","inte":"true","property":"payload","x":880,"y":200,"wires":[["467b4da156bd436d"]]},{"id":"a6070cc130bda46f","type":"switch","z":"9e4ee03cbb1cc389","name":"List Empty?","property":"payload","propertyType":"msg","rules":[{"t":"empty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":460,"wires":[["38e7081d42f7165b"],["fdb0f650a8807341"]]},{"id":"89da9405dab8b88f","type":"switch","z":"9e4ee03cbb1cc389","name":"List Empty?","property":"payload","propertyType":"msg","rules":[{"t":"empty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":500,"wires":[["38e7081d42f7165b"],["3a04867c271d78ad"]]},{"id":"3a04867c271d78ad","type":"random-item","z":"9e4ee03cbb1cc389","name":"Choose One","input":"payload","inputType":"msg","output":"payload","outputType":"msg","number":1,"x":610,"y":500,"wires":[["3f583218b6f9ee61"]]},{"id":"3f583218b6f9ee61","type":"change","z":"9e4ee03cbb1cc389","name":"Set Values","rules":[{"t":"set","p":"payload.service","pt":"msg","to":"turn_on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":500,"wires":[["9c2e81e18bcf7427"]]},{"id":"45ba80526dd93c83","type":"comment","z":"9e4ee03cbb1cc389","name":"Empty result: Go back to Random Off or On","info":"","x":710,"y":400,"wires":[]},{"id":"2296c127cfac21d5","type":"comment","z":"9e4ee03cbb1cc389","name":"Vacation is over :-( Reset all lights to ON","info":"Wife Acceptance Factor at work here. She expects the dumb switches to work when she reaches for them. Since they've been in the on position during Vacation Mode, set them to the on state to match now that the robots are disabled.","x":200,"y":240,"wires":[]},{"id":"2c369a3a31a591e0","type":"ha-get-entities","z":"9e4ee03cbb1cc389","name":"Vacation Lights","server":"aa0e51592ade96f6","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.vacation_lights","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":120,"y":280,"wires":[["200505ce4b1c7530"]]},{"id":"200505ce4b1c7530","type":"split","z":"9e4ee03cbb1cc389","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":290,"y":280,"wires":[["bf6fe50064ea9fa1"]]},{"id":"bf6fe50064ea9fa1","type":"change","z":"9e4ee03cbb1cc389","name":"Set Values","rules":[{"t":"set","p":"payload.service","pt":"msg","to":"turn_on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":320,"wires":[["28c7287b5e3a2af9"]]},{"id":"28c7287b5e3a2af9","type":"api-call-service","z":"9e4ee03cbb1cc389","name":"Service Call","server":"aa0e51592ade96f6","version":5,"debugenabled":false,"domain":"homeassistant","service":"{{payload.service}}","areaId":[],"deviceId":[],"entityId":["{{payload.entity_id}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":270,"y":320,"wires":[[]]},{"id":"72a718b84fae4c71","type":"comment","z":"9e4ee03cbb1cc389","name":"INSTRUCTIONS","info":"This node-red flow automates random turn_on and turn_off service calls against a group of lights or switches.\n\nIt is based on a HomeAssistant Script by Jeffrey Stone. Check out his Youtube channel SlackerLabs at https://www.youtube.com/channel/UCipZJ6748kd8TbelSxcvcVg or his webpage at https://slacker-labs.com/\n\nTo use this flow you will need:\n\n1. A Home Assistant group in groups.yaml named vacation_lights containing the list of entities you want to automate\n\n2. An input boolean helper and an associated dashboard button that toggles it on or off.\n\n3. HomeAssistant with Node-Red installed as an add-on.\n\n4. Install the node-red-contrib-random-item node\n\nCreate your group, add your button, install the node-red-contrib-random-item node and import the flow. The script is meant to only automate lights while the sun is below the horizon. If the sun comes up, it will wait until the sun is once again below the horizon and then resume operation.\n\nWhen the Vacation Mode button is toggled off, the script will turn on all of your devices and then exit.","x":200,"y":680,"wires":[]},{"id":"5b39d8ca2adf02c7","type":"api-current-state","z":"9e4ee03cbb1cc389","name":"Check Vacation Mode","server":"aa0e51592ade96f6","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.vacation_mode","state_type":"str","blockInputOverrides":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":540,"y":200,"wires":[["38e7081d42f7165b"],["2c369a3a31a591e0"]]},{"id":"112a5c4dd3142719","type":"ha-get-entities","z":"9e4ee03cbb1cc389","name":"Vacation Lights","server":"aa0e51592ade96f6","version":0,"rules":[{"property":"entity_id","logic":"in_group","value":"group.vacation_lights","valueType":"str"}],"output_type":"array","output_empty_results":true,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":120,"y":120,"wires":[["1e6761f9c77e4f90"]]},{"id":"1e6761f9c77e4f90","type":"split","z":"9e4ee03cbb1cc389","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":290,"y":120,"wires":[["63127f23063307f5"]]},{"id":"63127f23063307f5","type":"change","z":"9e4ee03cbb1cc389","name":"Set Values","rules":[{"t":"set","p":"payload.service","pt":"msg","to":"turn_off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":110,"y":160,"wires":[["663a9647a91d42d7"]]},{"id":"663a9647a91d42d7","type":"api-call-service","z":"9e4ee03cbb1cc389","name":"Service Call","server":"aa0e51592ade96f6","version":5,"debugenabled":false,"domain":"homeassistant","service":"{{payload.service}}","areaId":[],"deviceId":[],"entityId":["{{payload.entity_id}}"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":270,"y":160,"wires":[[]]},{"id":"a10baf5e4a9e881e","type":"comment","z":"9e4ee03cbb1cc389","name":"Turn off all lights during daytime","info":"","x":170,"y":40,"wires":[]},{"id":"e612c086845de57d","type":"server-state-changed","z":"9e4ee03cbb1cc389","name":"Watch for Sun Above Horizon","server":"aa0e51592ade96f6","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sun.sun","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"above_horizon","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"1","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":160,"y":80,"wires":[["112a5c4dd3142719"],[]]},{"id":"aa0e51592ade96f6","type":"server","name":"Home Assistant","version":2,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30"}]