Automation and time schedule

Hello everyone,

I’ve searched for some time how to simply turn switches on and off based on a time schedule or delay.
It is especially hard when the config check reports no issue! It must be simple but I don’t know where to look anymore :sweat:

I can pinpoint the issue to the second part with the delay, but I’m really out of ideas.

automation:
  - alias: 'Water Heater Schedule'
    trigger:
      platform: time
      after: '04:00:00'
    action:
      service: switch.turn_on
      entity_id: switch.water_heater
  - alias 'Water Heater Schedule Off'
    trigger:
      platform: state
      entity_id: switch.water_heater
      to: 'on'
    action:
      delay: '02:00:00'
      service: switch.turn_off
      entity_id: switch.water_heater

The syntax is correct and copied from other examples.
Thanks for the help!

Try this combined rule. I am assuming you want the water heater to run for two hours at 4am and then shut off two hours later:

automation:
      - alias: 'Water Heater Schedule'
        trigger:
          platform: time
          at: '04:00:00'
        action:
          - service: switch.turn_on
            entity_id: switch.water_heater
          - delay: '02:00:00'
          - service: switch.turn_off
            entity_id: switch.water_heater

thank you for having a look.
unfortunately the ‘at’ doesn’t work.

ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: [at] is an invalid option for [automation]. Check: automation->trigger->0->at.

but, by changing it with after, it works.
thanks a lot!

1 Like

Sorry. If you are not running .46, “after:” works. Beyond that, “at:” works…


indeed, after upgrading to v51.2, “after” did’t work anymore. replaced with “at” again and up and running again. thank you!