Automation trigger time using "after:"

I’m trying to use a a time trigger with a random delay to turn off the switch. I’ve seen a couple examples using delay: and after, so I tried modifying my fixed off time (see below), but get an error when checking the config:

Invalid config for [automation]: [after] is an invalid option for [automation]. Check: automation->trigger->0->after. 
#    
#-------  TURN LIVING ROOM LIGHT SWITCH ON/OFF AT NIGHT
# 
- alias: 'Living RM Light On'
  trigger:
    platform: time
    at: '19:00:00'
  action:
    - service: switch.turn_on
      data:
        entity_id: 
        - switch.switch

- alias: 'Living RM Light Off'
  trigger:
    platform: time
    after: '20:01:00'
  action:
    - delay: '{{ (range(0, 1)|random|int) }}:{{ (range(1, 30)|random|int) }}:00'
    - service: switch.turn_off
      data:
        entity_id: 
        - switch.switch

What I’m I doing wrong?

I tried checking the documentation for trigger (https://www.home-assistant.io/docs/automation/trigger/), it appears that there is no “after:”.

Was “after” in an earlier version and not in the current version?

Thanks.

Yeah, after was corrected to at ages ago because after suggested an ongoing trigger, which was never the case.

Thanks for the info, changed it back to “at” and kept the “delay”, which appears to work.

So, Im confused how at can mean after? How do you get after a certain time?

You don’t with a trigger.
A trigger happens at a set instant.
A condition could check for after, once something has triggered it.
What are you trying to achieve? There’s always a way

Thanks for that mate,

I actually got it after thinking about it for a while lol

I have a question regarding this -
I want to turn on a light after 20:00 until 06:00 am in the morning
If I set time to 20:00, and we have for example a power outage between 19:30-20:30, than I still
want the light to turn back on automatically at these hours.
If I could set a trigger of a time range, I could have achieved that.
Is there a way to configure it?

Thanks

1 Like

No. You’d have to deal with that scenario in a Home Assistant startup automation, unless your HA is UPS protected and survives the power outage and the devices are not power protected, in which case you’d trigger an automation based on power being restored.

I have lights set to restore to last state when possible but that’s not always appropriate i.e. If power went out at night and returned during the day. So after a power interruption, I turn them off. If I then want them on before motion detection, I say “Alexa, turn on…”.

If your power is extremely unreliable, consider a genarator!
:wink: