2 automations 1 single switch

Hi There,

I try to achive to fire two different automations with only one switch.

Automation 1:
When I press the switch -> Turn on light for 15 minutes.

Automation 2:
When I press the switch twice (within 3 seconds) -> Turn on light for one hour.

Hardware: (can be any wall switch / light)
In my case a Shelly 1 wired to a wall-switch (Using the SW input on the shelly). Light connected to shelly output.

The automation I have now is only for the press switch once.
Who can help me with the automation to leave the light on for one hour after a fast on/off/on sequence?

- alias: 'Lights garage'
  initial_state: true
  trigger:
    platform: state
    entity_id: switch.berging
    to: 'on'
  action:
  - service: homeassistant.turn_on
    entity_id: switch.berging

- alias: 'Switch off light garage'
  initial_state: true
  trigger:
    platform: state
    entity_id: switch.berging
    to: 'off'
  action:
  - service: homeassistant.turn_off
    entity_id: switch.sonoff_wcd1

- alias: 'Switch off garage light after 15 mins'
  initial_state: true
  trigger:
    platform: state
    entity_id: switch.berging
    to: 'on'
    for: 
      minutes: 15
  action:
    service: homeassistant.turn_off
    entity_id: switch.berging

  • Let’s assume the state of switch.berging is currently off.
  • You press the physical switch to turn on the light.
  • The state of switch.berging changes from off to on.
  • You press the physical switch a second time to turn on the light.
  • The state of switch.berging is unchanged and remains on.

Because the second press doesn’t change the state of switch.berging you can’t use a State Trigger to detect the second press.

The only way to detect two consecutive button presses is if the switch is capable of understanding this combination and reports it as an event (or reports every button press as an event). If the switch you are using doesn’t have this feature then you will have to think of another way (other than using two consecutive button presses) to signal that you want the timeout to change from 15 minutes to 1 hour.

NOTE

There’s a technique I have used (but recently abandoned) that works like this:

After you turn on the light, if within 3 seconds you turn it off and then back on, that serves as a signal that you want the light to behave differently.

In my case the signal was to prevent the light from being turned off automatically (when no motion was detected) but in your case it would serve to change the timeout duration.

The technique worked but was rarely used because the action of immediately turning the light off then back on felt unnatural. It has been replaced by another technique (which is not applicable for your purpose). Anyway, if you’re interested you can see how it was implemented here (hint: it uses a 3-second timer):