Making a robust lighting timer

This automation will set the switches according to your desired schedule. It will also set them correctly whenever Home Assistant is restarted. That’s useful should Home Assistant ever go offline at any of the scheduled times. When it starts again, the automation will ensure the switches are set to the correct state.

alias: 'Timer: Aquarium Lights On'
description: ''
trigger:
  - platform: time
    at:
    - '12:00:00'
    - '16:00:00'
    - '18:00:00'
    - '22:00:00'
  - platform: homeassistant
    event: start
condition: []
action:
  - service: "switch.turn_{{ 'on' if (12 <= now().hour < 16) or (18 <= now().hour < 22) else 'off' }}"
    target:
      entity_id:
        - switch.tapo_15
        - switch.tapo_16
mode: single

NOTE

You might find this tutorial interesting:

2 Likes