Basically, the TOD sensor creates a binary_sensor that switches on and off based upon times. I use them instead of NodeRed nodes because I still have automations in HA that use them as well and I get a good visual indicator of what mode the house is in. Pair that with the Workday sensor and you have a fantastic way to manage house modes:
- platform: workday
country: US
workdays: [mon, tue, wed, thu, fri]
excludes: [sat, sun, holiday]
add_holidays:
- '2020-10-09'
- '2020-10-15'
- '2020-10-16'
- platform: tod
name: Early Morning
after: sunrise
after_offset: '-00:45'
before: '08:00'
- platform: tod
name: Morning
after: '08:00'
before: '12:00'
- platform: tod
name: Afternoon
after: '12:00'
before: sunset
before_offset: '-02:30'
- platform: tod
name: Evening
after: sunset
after_offset: '-02:30'
before: '20:30'
- platform: tod
name: Night
after: '20:30'
before: '23:59'
Here is my set early morning subflow. What it does is sets a global variable in NodeRed so that I don’t have to constantly query HA for which mode it is in. This allows me to use global.get(“mode”) in Function nodes or Switch nodes easily.
[{"id":"21a6fc58.38b1dc","type":"subflow","name":"Manage Mode","info":"","category":"","in":[{"x":50,"y":30,"wires":[{"id":"2ce8e867.5f6b28"}]}],"out":[],"env":[],"color":"#DDAA99","status":{"x":1140,"y":380,"wires":[{"id":"2ce8e867.5f6b28","port":1},{"id":"f3b51d67.7bb6","port":0}]}},{"id":"e4281ed.028aee","type":"switch","z":"21a6fc58.38b1dc","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"binary_sensor.early_morning","vt":"str"},{"t":"eq","v":"binary_sensor.morning","vt":"str"},{"t":"eq","v":"binary_sensor.afternoon","vt":"str"},{"t":"eq","v":"binary_sensor.evening","vt":"str"},{"t":"eq","v":"binary_sensor.night","vt":"str"},{"t":"eq","v":"binary_sensor.overnight","vt":"str"},{"t":"eq","v":"binary_sensor.workday_sensor","vt":"str"},{"t":"eq","v":"input_boolean.good_night","vt":"str"}],"checkall":"true","repair":false,"outputs":8,"x":470,"y":220,"wires":[["8615c65b.c1f818"],["183d0170.84c41f"],["7d00b6e8.140058"],["1d2f8951.5940af"],["54c8ab49.30f31c"],["aff9e205.29df4"],["553e19ae.e47fd"],["aff9e205.29df4"]]},{"id":"8615c65b.c1f818","type":"change","z":"21a6fc58.38b1dc","name":"Set Global Mode","rules":[{"t":"set","p":"#:(file)::mode","pt":"global","to":"Early Morning","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":120,"wires":[["f3b51d67.7bb6"]]},{"id":"f3b51d67.7bb6","type":"function","z":"21a6fc58.38b1dc","name":"Set Various Global Variables","func":"var mode = global.get(\"mode\", \"file\");\n\nglobal.set(\"night_lights_active\", mode == \"Early Morning\" || mode == \"Evening\" || mode == \"Night\" || mode ==\" Overnight\", \"file\");\n\nreturn msg;","outputs":1,"noerr":0,"x":1000,"y":200,"wires":[[]]},{"id":"183d0170.84c41f","type":"change","z":"21a6fc58.38b1dc","name":"Set Global Mode","rules":[{"t":"set","p":"#:(file)::mode","pt":"global","to":"Morning","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":160,"wires":[["f3b51d67.7bb6"]]},{"id":"7d00b6e8.140058","type":"change","z":"21a6fc58.38b1dc","name":"Set Global Mode","rules":[{"t":"set","p":"#:(file)::mode","pt":"global","to":"Afternoon","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":200,"wires":[["f3b51d67.7bb6"]]},{"id":"1d2f8951.5940af","type":"change","z":"21a6fc58.38b1dc","name":"Set Global Mode","rules":[{"t":"set","p":"#:(file)::mode","pt":"global","to":"Evening","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":240,"wires":[["f3b51d67.7bb6"]]},{"id":"54c8ab49.30f31c","type":"change","z":"21a6fc58.38b1dc","name":"Set Global Mode","rules":[{"t":"set","p":"#:(file)::mode","pt":"global","to":"Night","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":280,"wires":[["f3b51d67.7bb6"]]},{"id":"aff9e205.29df4","type":"change","z":"21a6fc58.38b1dc","name":"Set Global Mode","rules":[{"t":"set","p":"#:(file)::mode","pt":"global","to":"Overnight","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":320,"wires":[["f3b51d67.7bb6"]]},{"id":"553e19ae.e47fd","type":"change","z":"21a6fc58.38b1dc","name":"Set Global Mode","rules":[{"t":"set","p":"#:(file)::workday","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":360,"wires":[[]]},{"id":"2ce8e867.5f6b28","type":"switch","z":"21a6fc58.38b1dc","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":170,"y":240,"wires":[["e4281ed.028aee"],[]]}]