I’d like to disable an automation temporarily by pressing a Lovelace button which would also automatically enable itself after x hours.
I have created a button to toggle the automation on/off, but would like to enhance the functionality by it automatically turning back on after x hours. Doable?
I do something similar with my aircon automations, a lovelace button that triggers a 1 hour turbo cool function. The lovelace button changes an input_boolean helper and I have an automation set, triggered by state change of that helper, which fires a 1 hour timer at the end of which the boolean is turned off (and then the aircon also turns off).
For your use case it would be simple to write an automation using the timer service call to then do something (e.g. turn an automation back on).
Yeah dont wait in an automation for 2 hours. It is highly likely that this can be interrupted by a restart or reload of automations.
Timers won’t restore either (though there are ways around this).
Instead, switch your automation off with the Lovelace button and write an automation that turns the disabled automation back on if it has been off for two hours (no timer required):
trigger:
- platform: state
entity_id: automation.that_you_disabled
from: 'on'
to: 'off'
for:
hours: 2
action:
- service: homeassistant.turn_on
target:
entity_id: automation.that_you_disabled
This can be interrupted by a restart but will begin counting again from the restart.
For a bonus you can have it enabled by default, so when you reload automations or restart HA it automatically enables. Or you can have it just enabled at startup:
trigger:
- platform: state
entity_id: automation.that_you_disabled
from: 'on'
to: 'off'
for:
hours: 2
- platform: homeassistant
event: start
...
I gave a try at some stuff based on the exaples above and the are not working the way intended. I have a “turn off light at a certain time” -automation:
alias: Turn off lamp at xx o'clock
description: ""
trigger:
- platform: time
at: "21:09:00"
condition:
- condition: device
type: is_on
device_id: xxxd65
entity_id: xxx392
domain: light
action:
- type: turn_off
device_id: xxxd65
entity_id: xxx392
domain: light
mode: single
To delay this for 2 hours I have a second automation:
alias: >-
Delay turn off light at xx o_clock automation for 2 hours and restart
automation if HA reboots
description: ""
trigger:
- platform: state
entity_id:
- automation.turn_off_lamp_at_xx_o_clock
from: "on"
to: "off"
for:
hours: 2
minutes: 0
seconds: 0
action:
- service: homeassistant.turn_on
target:
entity_id: automation.turn_off_lamp_at_xx_o_clock
data: {}
mode: single