Node-RED flow for Vacation mode with lights, Sonos

I have put together a flow for Vacation mode. Vacation mode can be sent manually, or is automatically set when all people are away for an extended period of time.

The flow turns lights on & off, and also plays ambient noise through Sonos. At night, it shuts everything off through a separate flow triggered by a “Night mode” switch (input_boolean). This is the same switch I use when home.

The flow itself works great. The scheduling, not so much. I want my vacation mode flow to work when it’s turned on. I also want it to work daily when vacation mode is on, with different parts of the flow occurring at different times. The trouble is, the flow only works on the first day that vacation mode is turned on. How can I adjust my flow to remedy this?

[{"id":"a1774f76.0cb69","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"97bdffc0.1bb2c","type":"time-range-switch","z":"a1774f76.0cb69","name":"Sunset - 9:45pm","lat":"0.0","lon":"0.0","startTime":"sunset","endTime":"21:45","startOffset":0,"endOffset":0,"x":380,"y":60,"wires":[["a3314f04.976c5"],[]]},{"id":"dafbd5dc.d322a8","type":"ha-get-entities","z":"a1774f76.0cb69","server":"296c0678.b5f9ca","name":"","rules":[{"property":"entity_id","logic":"in_group","value":"vacation_lights","valueType":"str"},{"property":"state","logic":"is","value":"off","valueType":"str"}],"output_type":"random","output_empty_results":false,"output_location_type":"msg","output_location":"payload","output_results_count":1,"x":690,"y":60,"wires":[["e87d0b23.86dd58"]]},{"id":"a3314f04.976c5","type":"function","z":"a1774f76.0cb69","name":"25%","func":"const random = Math.round(Math.random() * 100);\n\nif(random < 75) {\n    node.status({fill: \"red\", text: random});\n    return;\n}\n\nnode.status({fill: \"green\", text: random});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":542,"y":60,"wires":[["dafbd5dc.d322a8"]]},{"id":"e87d0b23.86dd58","type":"api-call-service","z":"a1774f76.0cb69","name":"turn on","server":"296c0678.b5f9ca","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"{{payload.entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":810,"y":60,"wires":[["b9a20de6.2336a"]]},{"id":"b9a20de6.2336a","type":"delay","z":"a1774f76.0cb69","name":"","pauseType":"random","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"16","randomLast":"65","randomUnits":"minutes","drop":false,"x":920,"y":60,"wires":[["d1c5af00.633c5"]]},{"id":"d1c5af00.633c5","type":"api-call-service","z":"a1774f76.0cb69","name":"turn off","server":"296c0678.b5f9ca","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"{{payload.entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1030,"y":60,"wires":[[]]},{"id":"fdaf6d0.6ae559","type":"server-state-changed","z":"a1774f76.0cb69","name":"Vacation Mode On","server":"296c0678.b5f9ca","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.vacation_mode","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","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":150,"y":60,"wires":[["97bdffc0.1bb2c","221279f8.f88bf6","52319c9e.7629f4"],[]]},{"id":"221279f8.f88bf6","type":"timecheck","z":"a1774f76.0cb69","name":"9:45pm","time":"21:50","x":360,"y":100,"wires":[["a1904f19.101d3"],[]]},{"id":"a1904f19.101d3","type":"api-call-service","z":"a1774f76.0cb69","name":"Night Mode On","server":"296c0678.b5f9ca","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.night","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":100,"wires":[[]]},{"id":"34772570.b62d9a","type":"sonos-manage-mysonos","z":"a1774f76.0cb69","confignode":"80cb210.c2ec0e","compatibilityMode":false,"command":"mysonos.export.item","state":"Ambient House Noise","stateType":"str","name":"Queue Ambient Noise","x":1060,"y":140,"wires":[["efa1a2f4.9d635"]]},{"id":"efa1a2f4.9d635","type":"sonos-universal","z":"a1774f76.0cb69","confignode":"80cb210.c2ec0e","compatibilityMode":false,"command":"group.set.volume","state":"50","stateType":"str","name":"Set Volume to 50","x":1250,"y":140,"wires":[["a39c1cf0.f2515"]]},{"id":"a39c1cf0.f2515","type":"sonos-universal","z":"a1774f76.0cb69","confignode":"80cb210.c2ec0e","compatibilityMode":false,"command":"group.play.queue","state":"","stateType":"str","name":"Play","x":1390,"y":140,"wires":[["a8aa3698.11dc08"]]},{"id":"bf49a3e7.292e","type":"api-call-service","z":"a1774f76.0cb69","name":"Sonos Living Room Power On","server":"296c0678.b5f9ca","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.sonos_living_room_power_current_value","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":650,"y":140,"wires":[["b14698b8.cc5c38"]]},{"id":"52319c9e.7629f4","type":"time-range-switch","z":"a1774f76.0cb69","name":"9:55am - 9:45pm","lat":"0.0","lon":"0.0","startTime":"09:55","endTime":"21:45","startOffset":0,"endOffset":0,"x":390,"y":140,"wires":[["bf49a3e7.292e"],[]]},{"id":"b14698b8.cc5c38","type":"delay","z":"a1774f76.0cb69","name":"After 5 minutes...","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":870,"y":140,"wires":[["34772570.b62d9a"]]},{"id":"a8aa3698.11dc08","type":"sonos-universal","z":"a1774f76.0cb69","confignode":"80cb210.c2ec0e","compatibilityMode":false,"command":"group.set.queuemode","state":"REPEAT_ONE","stateType":"str","name":"Set to Repeat","x":1520,"y":140,"wires":[[]]},{"id":"296c0678.b5f9ca","type":"server","name":"Home Assistant","addon":true},{"id":"80cb210.c2ec0e","type":"sonos-config","name":"Living Room","serialnum":"xx:xx:xx:xx:xx","ipaddress":"10.0.0.20"}]

Check out PresenceFaker. It will make things a lot easier

Ah, that looks interesting. And it probably would solve my issues around scheduling of lights… but I don’t think it’ll handle my Sonos. Scheduling is really my main concern here. Seems like it should be a simple fix, but it’s evading me.

If I replace a bunch of this stuff with a Presence Faker node, can I then use its status to trigger my Sonos daily? That might work.

It will :slight_smile:
I am using it!

[{"id":"965bdbfb.bef5d8","type":"template","z":"c07c0ac5.ca6f98","g":"bd7f225e.b5f63","name":"Jour","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n  \"windowBegin\": \"{{sunRise}}\",\n  \"windowEnd\": \"{{sunSet}}\",\n  \"minDuration\": 240,\n  \"maxDuration\": 600,\n  \"minCount\": 40,\n  \"maxCount\": 90\n}","output":"json","x":530,"y":1000,"wires":[["c0d161f3.b853f"]]},{"id":"c0d161f3.b853f","type":"presence-faker","z":"c07c0ac5.ca6f98","g":"bd7f225e.b5f63","name":"Sonos","onPayload":"true","onPayloadType":"bool","onTopic":"","offPayload":"false","offPayloadType":"bool","offTopic":"","windowBegin":"00:00","windowEnd":"00:00","minDurationHours":0,"minDurationMinutes":"0","minDurationSeconds":0,"minDuration":"0","maxDurationHours":0,"maxDurationMinutes":"0","maxDurationSeconds":0,"maxDuration":"0","minCount":1,"maxCount":1,"startupBehavior":"onMsg","actionOnDisable":"off","firstBlockType":"off","lastBlockType":"off","isLoggingEnabled":false,"x":650,"y":1000,"wires":[["fcf988a3.0c12f8"]]},{"id":"fcf988a3.0c12f8","type":"switch","z":"c07c0ac5.ca6f98","g":"bd7f225e.b5f63","name":"On/Off","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":770,"y":1000,"wires":[["54c1d66d.35c318"],["bc602255.8be59"]]},{"id":"54c1d66d.35c318","type":"change","z":"c07c0ac5.ca6f98","g":"bd7f225e.b5f63","name":"FIP","rules":[{"t":"set","p":"topic","pt":"msg","to":"play.streamhttp","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"http://direct.fipradio.fr/live/fip-midfi.mp3","tot":"str"},{"t":"set","p":"volume","pt":"msg","to":"60","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":980,"wires":[["6dac399b.f7d6b8"]]},{"id":"bc602255.8be59","type":"sonos-universal","z":"c07c0ac5.ca6f98","g":"bd7f225e.b5f63","confignode":"76b8357d.3e9ccc","compatibilityMode":false,"command":"group.stop","state":"","stateType":"str","name":"Stop","x":910,"y":1020,"wires":[[]]},{"id":"6dac399b.f7d6b8","type":"sonos-universal","z":"c07c0ac5.ca6f98","g":"bd7f225e.b5f63","confignode":"76b8357d.3e9ccc","compatibilityMode":false,"command":"message","state":"","stateType":"str","name":"Set","x":1030,"y":980,"wires":[[]]},{"id":"76b8357d.3e9ccc","type":"sonos-config","name":"Sonos","serialnum":"34-7E-5C-90-E5-A1:E","ipaddress":"192.168.0.171"}]

Here is to play a radio station randomly during the day…

Otherwise, sticking with your flow (but really you should use PresenceFaker), your flow is only activated when vacation is turned on. Not every day when it still on…
For this, many options, eg run a cron-plus task every day at eg. 6am test if vacation is on and shoot :slight_smile:

Thanks! I’ll give this a try.