123 Taras, I’m giving you the solution for this since your post led me down the right path though the setup itself didn’t actually work for me. I was not at all thinking about using a timer entity instead of the waits and durations in the automations and your post helped me through the logic I was needing.
My final result ended up using 2 separate timers, an existing input boolean that gets enabled, and quite a few automations. No scripts or templates were needed and, at least in my opinion, is quite elegant in the way it works. Instead of an on/off/on trigger, everything I need is set off by an off event. So, even if the light has been on for a while, I can still set the override. If anyone can see room for improvement, I’m open to it. Hopefully this can help someone else out.
Here’s my final setup:
Timers
The garage_light timer is the “basic” timer that will turn the light off after 10 min which is what the normal behavior will be. The toggler timer will start when the off event fires and gives 3 seconds to turn the light back on again.
timer:
toggler:
duration: '00:00:03'
garage_light:
duration: '00:10:00'
Input booleans:
The garageoverride was the existing boolean that kept the light on. This will get enabled by the automations or through the UI.
input_boolean:
garageoverride:
name: Garage Light Override
Automations:
First, the simple automations to turn the light off automatically.
- id: '1558998212488'
alias: Garage Light Timer Start
trigger:
- device_id: mydeviceid
domain: switch
entity_id: switch.mylightswitch
platform: device
type: turned_on
condition:
- condition: state
entity_id: input_boolean.garageoverride
state: 'off'
action:
- alias: ''
data:
entity_id: timer.garage_light
service: timer.start
- id: '1576009002117'
alias: Garage Light Timer Finished
trigger:
- event_data:
entity_id: timer.garage_light
event_type: timer.finished
platform: event
condition: []
action:
- device_id: mydeviceid
domain: switch
entity_id: switch.zooz_willis_electric_zen23_toggle_switch_switch_2
type: turn_off
The first will start the timer if the override boolean is off and the second turns the light off when the timer expires. If the override boolean is enabled when the light is turned on, the timer is not started.
Next are the automations to enable the override using the manual switch.
When the light is turned off, start the toggler timer only if the normal timer is running. If the normal timer is not running due to the override being on already, the timer does not start.
- id: '1576009594713'
alias: Garage Light Manual Override Start
trigger:
- device_id: mydeviceid
domain: switch
entity_id: switch.mylightswitch
platform: device
type: turned_off
condition:
- condition: state
entity_id: timer.garage_light
state: active
action:
- data:
entity_id: timer.toggler
service: timer.start
When the light is turned on (runs simultaneously with the timer automation), check if the toggler timer is running. If it is, turn the override boolean on.
- id: '1576009955312'
alias: Garage Light Toggler Timer Check
trigger:
- device_id: mydeviceid
domain: switch
entity_id: switch.mylightswitch
platform: device
type: turned_on
condition:
- condition: state
entity_id: timer.toggler
state: active
- condition: and
conditions:
- condition: state
entity_id: input_boolean.garageoverride
state: 'off'
action:
- data:
entity_id: input_boolean.garageoverride
service: input_boolean.turn_on
When the override boolean is turned on and the garage light timer is active, cancel the running timer. This also catches if the override is turned on through the UI.
- id: '1576010679009'
alias: Garage Light Override Turned On
trigger:
- entity_id: input_boolean.garageoverride
from: 'off'
platform: state
to: 'on'
condition:
- condition: state
entity_id: timer.garage_light
state: active
action:
- data:
entity_id: timer.garage_light
service: timer.cancel
When the light is manually turned off, either at the switch or in the UI, and the override boolean is on, turn the override boolean off as well.
- id: '1576014691135'
alias: Garage Light Disable Override With Off
trigger:
- device_id: mydeviceid
domain: switch
entity_id: switch.mylightswitch
platform: device
type: turned_off
condition:
- condition: state
entity_id: input_boolean.garageoverride
state: 'on'
action:
- data:
entity_id: input_boolean.garageoverride
service: input_boolean.turn_off
Finally, if the override boolean is turned off in the UI while the light is still on, restart the timer that will turn the light off automatically.
- id: '1576010818278'
alias: Garage Lights UI Override Turned Off
trigger:
- entity_id: input_boolean.garageoverride
from: 'on'
platform: state
to: 'off'
condition:
- condition: device
device_id: mydeviceid
domain: switch
entity_id: switch.mylightswitch
type: is_on
action:
- data:
entity_id: timer.garage_light
service: timer.start