Restart a running timer

Hi,

I try since a couple of days to get my toiletfan-timer running.

The thing to do:

Someone go on the toilet and turn on the light less then 2 minutes nothing todo.
Someone go on the toilet and turn on the light more then 2 minutes the toiletfan shout run for 20 minutes.
If someone go on the toilet during the fan is running the time shout be run again backwards from 20.
My problem is, I can’t finde how to retrigger a running timer.
This are my automations:


alias: Wc Lüfter ein test
description: ''
trigger:
  - platform: state
    entity_id:
      - light.licht_wc
    to: 'on'
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition: []
action:
  - type: turn_on
    device_id: bf714fa29a5e278ab6203e85554c3671
    entity_id: switch.schalter_wc_2
    domain: switch
mode: single
alias: Wc Lüfter timer test
description: ''
trigger:
  - platform: state
    entity_id:
      - switch.schalter_wc_2
    to: 'on'
condition: []
action:
  - service: timer.start
    data: {}
    target:
      entity_id: timer.wc_lufter_timer
mode: single


alias: Wc Lüfter aus test
description: ''
trigger:
  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.wc_lufter_timer
condition: []
action:
  - type: turn_off
    device_id: bf714fa29a5e278ab6203e85554c3671
    entity_id: switch.schalter_wc_2
    domain: switch
mode: single

That will re-start the timer even if its running. I’m going to guess you don’t have a duration value set in the timer as a default and you’re not specifying a duration in the automation itself.

Thanks

This is not correct, the duration is set and it work.
At the moment the fan run when the light is longer on as 2 minutes and the light goes out. But if the light goes on when the fan run the duration from the timer doesen’t start again from 20minutes

Go into developer tools → events

listen for ‘timer.restarted’

In another window go to developer tools → services

Plug in your start timer service. and hit it a few times. You’ll see the timer getting restarted.

{
    "event_type": "timer.restarted",
    "data": {
        "entity_id": "timer.test"
    },
    "origin": "LOCAL",
    "time_fired": "2022-06-09T11:27:45.113828+00:00",
    "context": {
        "id": "01G543GSYS3WVZCTPBP177TT24",
        "parent_id": null,
        "user_id": null
    }
}
Event 2 fired 7:27 AM:
{
    "event_type": "timer.restarted",
    "data": {
        "entity_id": "timer.test"
    },
    "origin": "LOCAL",
    "time_fired": "2022-06-09T11:27:34.325661+00:00",
    "context": {
        "id": "01G543GFDNQCBD6T5HQ79AK8GE",
        "parent_id": null,
        "user_id": null
    }
}
service: timer.start
data: {}
target:
  entity_id:
    - timer.test

I fiddled around with this some time ago for quite a while and eventually got it done. It works flawlessly for me with the following:

Inside automations.yaml:

  alias: Wc Lüfter ein test
  trigger:
    - platform: state
      entity_id: light.licht_wc
      to: 'on'
      for: '00:02:00'
  condition: []
  action:
    - service: switch.turn_on
      entity_id: switch.schalter_wc_2
  mode: restart

  alias: Wc Lüfter aus test
  trigger:
    - platform: state
      entity_id: light.licht_wc
      from: 'on'
      to: 'off'
  condition:
     - "{{ is_state('switch.schalter_wc_2', 'on') }}"
  action:
    - service: script.turn_off
      entity_id: script.fan_timer_wc_luefter
    - service: script.fan_timer_wc_luefter
  mode: restart

Inside scripts.yaml:

fan_timer_wc_luefter:
  icon: mdi:fan-auto
  mode: restart
  sequence:
  - service: switch.turn_on
    entity_id: switch.schalter_wc_2
  - delay: 00:20:00
  - service: switch.turn_off
    entity_id: switch.schalter_wc_2