Timer doesn't get reset

I want to turn off the lights X mins after the last motion has been detected from any of the motion sensors. The following automation doesn’t seem to reset the timer when there is a new motion:

automations.yaml:

- alias: Turn on garage lights when there is movement
  trigger:
  - platform: state
    entity_id: binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_4, binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_3
    to: 'on'
  action:
  - service: homeassistant.turn_on
    data:
      entity_id:
        - switch.garage_switch_3
  - service: timer.start
    data:
      entity_id: timer.garage
- alias: Turn off garage lights 1 minutes after trigger
  trigger:
    platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.garage
  action:
    service: homeassistant.turn_off
    data:
      entity_id:
        - switch.garage_switch_3

configuration.yaml:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Text to speech

zwave:
  usb_path: /dev/ttyACM0
  polling_interval: 3000

tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
timer:
  hallway1:
    duration: '00:01:00'
  garage:
    duration: '00:10:00'
script: !include scripts.yaml

This is a known issue and not sorted as of now. You have to cancel and restart the timer manually

Can you direct me to where on Github this Issue is reported? For which version of Home Assistant does it apply?

you can get some info here

Sorry, I did not follow that issue further as I migrated to NodeRed for all my automation.

Based on the linked post, try adding a timer.cancel to your first automation, just before it calls timer.start.

- alias: Turn on garage lights when there is movement
  trigger:
  - platform: state
    entity_id: binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_4, binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_3
    to: 'on'
  action:
  - service: homeassistant.turn_on
    entity_id: switch.garage_switch_3
  - service: timer.cancel
    entity_id: timer.garage
  - service: timer.start
    entity_id: timer.garage

Also, you may already be aware of this but the alias of the second automation refers to “1 minutes”. However, the garage timer’s duration is 10 minutes, so the light will actually be turned off after 10 minutes (assuming no further activity from the motion sensors).


EDIT
According to this post, the issue is that using timer.start to restart an existing timer that is running will, in fact, restart it. However, the timer’s status in the UI will be incorrect (that’s the bug).

To be more precise: the UI does not show the countdown accurately if changed; however, if the timer is started (from stopped) or cancelled, it does reflect that state correctly.

1 Like

Thanks everyone! I’m testing it right now. One more question since somebody mentioned it already. I only see one times in the UI when in fact a I have a few. Is there a fix for that?

And, I’m surprised no one has mention this but I think your automation could be even easier and not use any separate timers at all.

If you want the lights to turn off 1 minute after both motion detectors have turned off then you can do this:

- alias: Turn off garage lights 1 minutes after trigger
  trigger:
    - platform: template
      value_template: >
        {% if is_state('binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_4', 'off') and is_state('binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_3', 'off') %}
          true
        {% endif %}"
      for: '00:01:00'
 action:
    service: switch.turn_off
    data:
      entity_id:
        - switch.garage_switch_3

And then just remove the timer.start from your first automation since it’s not using a timer

Good idea! Unless there’s a desire to see the timer in the UI, using for is a neater solution.

I would suggest the following which, upon evaluation, will return either true or false.

      value_template: >
        {{ is_state('binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_4', 'off') and
           is_state('binary_sensor.elexa_consumer_products_inc_dome_motion_detector_sensor_3', 'off') }}
1 Like

yeah, you’re right that it doesn’t need the extra if-else stuff. I went to the docs to verify that the new “for:” option was actually implemented now and while I was there I just did a quick copy/paste of the example listed there for the formatting.

I’m not sure why they used that as the example since it is unnecessarily more complex than it needs to be.