Unique Automation Application

Situation: I have the lights in my garage on a timer to turn off after 10 min. I also have a dummy switch to override the timer if I need the light to stay on but it can only be accessed through a panel. I’m curious if there is a way to use the manual light switch to turn the dummy override switch on.

I was thinking I could just flip the switch on again but the switch doesn’t report on another “On” event when the switch is already on. My next thought was if I turn the switch off then on again within say 2 seconds but I couldn’t see a direct way to do that in the automations. Anyone have any ideas?

I’m trying to understand your setup. Please correct me if I’m wrong.
The light is controlled by a smart switch.
An automation triggered by flipping the switch turns off the light 10 min later. You have an input boolean in home assistant that, which overrides this behaviour if it is on. Now you somehow want to turn this input boolean on through the light switch.
Does this switch support different types of button presses, like long press, short press, double click etc.?

Someone else had a similar need where they wanted an on/off/on action (within a timespan of under 3 seconds) to serve as a command to toggle another light’s state. Perhaps it can be of some use to you:

Burningstone,
You pretty much have the gist of it. The input boolean cancels the timer if activated within Lovelace and I’m looking for a way to “trigger” the input boolean using a manual switch on the existing light switch. The switch is a simple zwave on/off switch and doesn’t support any “advanced” inputs like long or double presses.

Taras,
That looks promising. I will give that a try and see if I can make it work for what I want.

As I was looking into it further, I was thinking I could trigger an automation timer with the “off” event on the switch but couldn’t quite wrap my head around the logic yet.

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
1 Like

This thread was great. I just adapted it to add a 30 minute timer to the bathroom light & fan.

I have an older house with only one switch for the bathroom. I managed to retrofit a proper exhaust fan years ago to vent shower steam, but either you had to turn the light & fan off manually or if I installed a timer, the light and fan turns off if you have an occasional long shower.

The bathroom is in a post-war story and a half dormer, if I could get constant power to the fan, I could do incredible things - but fishing a wire there is impossible for me, and cost prohibitive for the electrician I asked.

Anyway, now the light and fan are on or off with the switch, but thanks to this, I just flip the light/fan off/on/off and it goes back on for 30 minutes then off. I can go to bed after a shower without having to get up again to turn the light/fan off after a bit.

I didn’t even know I wanted this automation, but it’s now one of my very favourites!

alias: "Toggler 02: Upstairs Bathroom Light & Fan stays on for 30 minutes."
description: >-
  Upstairs Bathroom Light & Fan stays on for 30 minutes after being triggered by
  toggle.
trigger:
  - platform: state
    entity_id:
      - light.sonoff_1234
    from: "on"
    to: "off"
condition:
  - condition: template
    value_template: "{{ states('timer.toggler') == 'active' }}"
action:
  - type: turn_on
    device_id: 1234
    entity_id: light.sonoff_1234
    domain: light
  - service: notify.me_devices
    data:
      title: Cheat Code Enabled!
      message: Bathroom light & fan will turn off in 30 minutes.
  - delay:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
  - service: notify.me_devices
    data:
      title: 30 minute timer finished.
      message: Bathroom light & fan will turn off now.
  - type: turn_off
    device_id: 1234
    entity_id: light.sonoff_1234
    domain: light

…and I just realized that since I managed to stick a Sonoff Mini R2 behind the light switch, I could actually use that as just a signal, send constant power to the fan/light, then install separate light and fan humidity controls to the fan.

Something like the light follows the switch, the fan follows the switch, runs for 10 more minutes, or until the humidity drops to within whatever of the rest of the house.

I actually ended up with a much simpler and more streamlined setup using Node Red.

This allows me to:

  • automatically turn off the light after 10 minutes
  • enable the override switch via lovelace
  • enable the override by turning the light off and back on within 4 seconds via the physical switch
  • turn off the override via lovelace and start the 10 minute timer
  • cancel the override by physically turning the light off

Additional nodes not shown turn the light on when the garage door is opened and all flows trigger accordingly.

I’ve actually replaced just about all of my old automations with Node Red. I find it to be much more flexible and I can accomplish things in just a few nodes rather than multiple automations. I would highly recommend brushing up on Node Red as opposed to using automation.