Turn a device off and after x Minutes automatically on again

Hey,
i want to turn off my ventilation for 60 Minutes.
That means, i want to press a button on the dashboard and the Ventilation turns off. After 60 minutes, the ventilation should turn on automatically.

Can anyone help me or give me a yaml snippet?

Thank you :pray:t2:

Use a state trigger on the switch/fan being off for 60 minutes.
Then the action turn on the switch/fan.

My Problem is, that I have an automation, which turns off the fan every day from 22 till 7 in the morning.
Sometimes i like to turn off the fan for 60 minutes during the day. When i set a state trigger, then it would switch the fan on after 60 Minutes in the night.

Any other suggestions?

Condition of time

  • Create a timer helper and set it to 60 minutes.

  • Add a condition in your existing automation that your timer’s state is idle. This will avoid your automation starting to run if you enabled the timer just before your automation started at 22:00.

  • Create another automation for when your timer goes from active to idle, and add a condition that the time is between 22:00 & 07:00. This will turn on your fan again if the timer ended and the time is between your specified times.

Job done.

Eventually, you might want to move everything into a single automation (depending on your preference), but for now, leave it as is to verify it’s working as intended.

In simplest terms, 2 automations…

description: turn fan on from 7:00 to 22:00
mode: single
triggers:
  - trigger: time
    at: "07:00:00"
  - trigger: time
    at: "22:00:00"
conditions: []
actions:
  - if:
      - condition: time
        after: "21:59:00"
    then:
      - action: switch.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: switch.fan
    else:
      - action: switch.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: switch.fan

and

description: turn fan off for 60 minutes
triggers: []
conditions:
  - condition: time
    after: "07:00:00"
    before: "22:00:00"
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.fan
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.fan
mode: restart

There are more elegant solutions, edge cases (ha resets while in the delay), etc.

PS. I’ve never understood why time triggers are AT timeX, but time conditions are AFTER timeX. Time conditions should be >=, not just >. Annoying!

This is not good.
It actually won’t work since the time is always past 6:59.
And your second automation has no triggers so it will trigger constantly

Thank you @Hellis81
This worked for me:


alias: LĂĽftung 60 Minuten aus
description: ""
triggers:
  - type: turned_off
    device_id: 5facd4828c5ba73e69bb78bcb6a
    entity_id: 63701604202b536de9682bf741
    domain: switch
    trigger: device
    for:
      hours: 1
      minutes: 0
      seconds: 0
conditions:
  - condition: time
    after: "07:21:00"
    before: "22:00:00"
    weekday:
      - fri
      - thu
      - wed
      - tue
      - mon
  - condition: time
    after: "08:31:00"
    before: "22:00:00"
    weekday:
      - sat
      - sun
actions:
  - type: turn_on
    device_id: 5facd4828c5ba73e69bb78bcb6a
    entity_id: 63701604202b536de9682bf741
    domain: switch
mode: single

I did update the first one. The Second one is an automation that can be manually triggered. I use trigger-less automations all the time, from UI buttons. Why would it be constantly triggered?

@thomba: This is also a great idea to make a triggerless automation, so I can trigger it with a Button. :+1:t2:

Your right it shouldn’t trigger all the time I confused it with a empty state trigger.
But a triggerless automation is a script.

1 Like

Now you’re just being pedantic. Where’s the “+Create Script” button…

Hey

Same idea, I use this to pause / switch off a fish tank pump while the fish are being fed. Will auto resume after 15 minutes. Trigger is a button on Home assistant dashboard or the button in the the smart plug that pump is connected to.

alias: Automation - Fish Tank Skimmer - Timer
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.fish_skimmer_socket_1
    to: "off"
  - event_type: timer.finished
    event_data:
      entity_id: timer.fish_skimmer
    id: timer_complete_fish_skimmer
    trigger: event
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - timer_complete_fish_skimmer
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              device_id: ca034292908715527c9aa012f41e5446
      - conditions:
          - condition: state
            entity_id: timer.fish_skimmer
            state: idle
        sequence:
          - metadata: {}
            data:
              duration: "00:15:00"
            target:
              entity_id:
                - timer.fish_skimmer
            action: timer.start
mode: single

Under the topic scripts.
But I’m not pedantic.
Wait a few years and try and sort out the mess what is automations and what is scripts.

1 Like

Thank you for your great discussion and helpful input.

You can always rely on the community here!

I am a bit confused since I am an absolute beginner. However, I have now organized my thoughts. I also think that an automation without a trigger is a script. Therefore, I have now written a script and deleted the automation.

My Script now:


sequence:
  - type: turn_off
    device_id: 5facd4828c5ba73e69bb78bcb
    entity_id: 63701604202b536de9682bf74
    domain: switch
  - if:
      - condition: or
        conditions:
          - condition: time
            after: "07:20:00"
            before: "23:00:00"
            weekday:
              - mon
              - tue
              - wed
              - thu
              - fri
          - condition: time
            after: "08:30:00"
            before: "23:00:00"
            weekday:
              - sat
              - sun
    then:
      - delay:
          hours: 1
          minutes: 0
          seconds: 0
          milliseconds: 0
  - type: turn_on
    device_id: 5facd4828c5ba73e69bb78bcb
    entity_id: 63701604202b536de9682bf74
    domain: switch
alias: LĂĽftung 60min. ausschalten
description: ""

I trigger the script via a button on the dashboard. This turns off my ventilation for 60 minutes.

Happy Easter to you all. :partying_face:

1 Like

One comment - would recommend to replace the long-lived delay with a timer.

The delay in a script will not resume / survive a Home Assistant reboot or a reload of the scripts, which will leave you fan off till such time you correct it.

I’m not sure a script will resume even if it’s a timer in it.
I believe an automation is needed such as the one you posted Bambam

Indeed - a Timer is a trigger so will require a automation to use a timer