Turn switch off after 15 min

I have a switch which is turned on by automation1 and now I am writing automation2 to switch it off.

There are 2 options:

  1. put for: 00:15 in the trigger “switch went on”
  2. put for: 00:15 in the condition

Trying to figure out the difference. I thought 1) is enough but without the condition, the switch’s history is flooded with “turned off” (can be seen with the recent 0.115 update).

What is the recommended way?

One automation, using delay ?

  action:
  - data:
      entity_id: switch.lichtbuitenvoordeur
    service: switch.turn_on
  - delay: 00:15:00
  - data:
      entity_id: switch.lichtbuitenvoordeur
    service: switch.turn_off

oh, I did not realize that. cool, thanks, this solves one of my cases but not others as there may be more than one automation enabling a switch, so the original question still stands.

The trigger means ‘fire this automation when the light has been on on for 15 minutes’ (this is the one you want to)

The condition means that something else has triggered the automation, but ‘only run the action if the light has been on for 15 minutes’.

Yaml whisperer - that’s a new one
:rofl:

@aik ,
I would recommend splitting into two and using the for in the trigger of the second.
If you go the other route, then ‘if’ you have a restart (during that 15 mins) the the switch will be on permanently, until you manually switch it off.
I’m just lazy though, as you could have everything switch to off on a restart, but you WAF, may hit rock bottom.

1 Like

I’d suggest you use a Device trigger that triggers when the on state is true for 15 minutes.
It is reliable as long as you do not edit your automations during that 15 minutes.

A different solution is to use a helper that sets the timestap value + 900 seconds and have it triggered the “turn_off” automation.
Setting your helper is easy, add the following line to the data field: timestamp: {{ (as_timestamp(now())+900) | int }}`