Stopwatch for automation

Hi all,
I need help, please.
I want to use the switch in the bathroom that controls the light, also use it to turn on the hot water circulation pump.
The automation should look like this:
when I turn on the switch and within 5 sec. I turn it off, something will start.
I don’t know how to use measurement / stopwatch between trigger actions.
Thank you

alias: example
trigger:
  - platform: state
    entity_id: light.bathroom
    from: 'off'
    to: 'on'
condition: []
action:
  - wait_for_trigger:
      - platform: state
        entity_id: light.bathroom
        from: 'on'
        to: 'off'
    timeout:
      seconds: 5
    continue_on_timeout: false
  - service: switch.turn_on
    target:
      entity_id: switch.pump

When the light.bathroom turns on, the automation waits for light.bathroom to turn off. If it does, then the swich.pump will turn on. If the bathroom light doesn’t turn off for 5 seconds, then the automation will stop.

2 Likes

Thank you very much, it works great! This opens up completely different possibilities for me!! I am very happy

1 Like