Timer reset/restart

To reset or restart an active timer while it is running … it is necessary to cancel and start the timer. This will result in an unwanted CANCEL event before the timer gets active again.

Can we have a reset/restart functionality for TIMER to reset the clock to the start time keeping the status as active?

This is already possible by triggering the start service again.

Starts or restarts a timer with the provided duration. If no duration is given, it will either restart with its initial value, or continue a paused timer with the remaining duration.

https://www.home-assistant.io/components/timer/

2 Likes

Yes, I have tried this … but the timer always continues with the remaining time… it never does a restart for me

xx_Nexus_xx is right, the timer actually does restart, but the time remaining in the frontend is still the time of the first period (not restarted).
Even though the timer have been successfully restarted, the frontend display the wrong value.

Same experience here. When restarting a running timer, I would expect the timer to display a new countdown in the frontend, but it doesn’t. But in the background it is indeed restarted, only not displayed in the frontend.

Sounds like a bug, submit a PR

It’s also not working with the latest version (0.88.2 atm). But I found a workaround.

Solution is to cancel the timer before (re)starting.

Here’s an example of motion_sensor1 which, after have been triggered,
will turn light1 on for 2 minutes.

configuration.yaml:

timer:
  timer_light1:
    duration: '00:02:00'

automation.yaml:

- id: '0000000000001' 
  alias: Motion Sensor1 Triggered
  trigger:
  - entity_id: binary_sensor.motion_sensor1
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      brightness_pct: 10
      entity_id: light.light_1
    service: light.turn_on
  - data:
      entity_id: timer.timer_light1
    service: timer.cancel
  - data:
      duration: 00:02:00
      entity_id: timer.timer_light1
    service: timer.start
  - data:
      message: (re)started
      name: 'Timer for Light1: '
    service: logbook.log
  initial_state: 'on'

- id: '0000000000002'
  alias: Timer Light1
  trigger:
  - event_data:
      entity_id: timer.timer_light1
    event_type: timer.finished
    platform: event
  condition: []
  action:
  - data:
      entity_id: light.light_1
    service: light.turn_off
  initial_state: 'on'
1 Like

Like puk1966, I also had to cancel and start the timer to update the duration on an active timer (push time zero into the future) in version 0.92. I consider this a work around since this segments timer’s active state in history graphs rather showing a continuous active state.

I had the same experience, I cannot restart a timer.

System Health

item value
arch x86_64
dev false
docker true
hassio true
os_name Linux
python_version 3.7.3
timezone America/New_York
version 0.94.3
virtualenv false

Cancel and re-start is not an option, that will complicate automations.

My use case is a count down timer to turn off a light, every time there’s motion reset the timer. This way I don’t have lingering and overlapping automations.

I would have (2) Automations and one timer per light:
(1) Turn on the light and start (or restart) the timer on motion
(2) automation to turn off the light when the timer hits zero

The timer would vary based on the use of the room, living room set higher (10m) because you sit idle, working area of a kitchen lower (2min), because you’re constantly moving.

~Todd

Yes, that use-case sound very familiar, but I have sorted it out in Node-Red

Nor quite ready for that plunge!

I started with baby-steps myself, but did the full transition after a few weeks of getting to know NR

Hello, I am using this automation:

- alias: 'Movimiento 01 - start'
  hide_entity: True
  trigger:
    platform: mqtt
    topic: casa/zigbee2mqtt/xiaomi-motion-illu-01
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ trigger.payload_json.occupancy == true }}'
      - condition: template
        value_template: '{{ states("timer.hall") == "idle" }}'
  action:
    - service: notify.notificacion_syslog
      data_template:
        message: "Movimiento START lux: {{ state_attr('binary_sensor.motion_lux_01', 'illuminance') }} segs: {{ states('input_number.hall_light_second
s_on') | int }}"
    - service: timer.start
      entity_id: timer.hall
      data_template:
        duration: '{{ states("input_number.hall_light_seconds_on") | int }}'
    - service: light.turn_on
      entity_id: light.tradfri_e27_01
      data:
        entity_id: light.tradfri_e27_01
        brightness: 255
        transition: 1


- alias: 'Movimiento/luz 01 - restart'
  hide_entity: True
  trigger:
    platform: mqtt
    topic: casa/zigbee2mqtt/xiaomi-motion-illu-01
  condition:
    condition: template
    value_template: '{{ states("timer.hall") != "idle" }}'
  action:
    - service: notify.notificacion_syslog
      data_template:
        message: "Movimiento RE-START lux: {{ state_attr('binary_sensor.motion_lux_01', 'illuminance') }} segs: {{ states('input_number.hall_light_sec
onds_on') | int }}"
    - service: timer.start
      entity_id: timer.hall
      data_template:
        duration: '{{ states("input_number.hall_light_seconds_on") | int }}'


- alias: 'Movimiento/luz 01 - finished'
  trigger:
    platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.hall
  action:
    - service: light.turn_off
      data:
        entity_id: light.tradfri_e27_01
        transition: 5

This is still not working in the latest version. You have to cancel a timer before (re-)starting it.

To show it on frontend, yes.
But it does work, only doesnt show restart on frontend.

1 Like

this bug in the frontend is still there in:
Frontend 20221010.0 - latest
Home Assistant 2022.10.3