Simple timer automation

Hi,

I am trying to setup a simple automation, that responds to a motion sensor and turns on a light. The light remains on for a period, and then shuts off. I tried basing my config on this cookbook: https://www.home-assistant.io/cookbook/turn_on_light_for_10_minutes_when_motion_detected/

Unfortunately, this cookbook does not reset the timer, should motion be detected within the ‘on’ period. So it’ll turn the lights off, even if motion continues. This behavior has been experienced by others, and is the subject of an open bug report: https://github.com/home-assistant/home-assistant/issues/12013

The simple solution seems to be that you need to cancel and then manually start the timer within the automation, however my attempt at this does not work. Can anyone suggest what I’m missing?

automations.yml

- id: 'OfficeMotionLight'
  alias: 'Turn lights on when motion seen'
  trigger:
    platform: state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_burglar
    #above: 200
  action: 
      - service: light.turn_on
        entity_id: light.office
      - service: timer.cancel
        entity_id: timer.officelight
      - service: timer.start
        entity_id: timer.officelight

- id: 'OfficeLightOff'
  alias: 'Turn office lights off after delay'
  trigger:
    platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.officelight
  action:
    service: light.turn_off
    data:
      entity_id: light.office

configuration.yml


timer:
  officelight:
    duration: '00:10:00'

TIA

If it’s broken (as it appears to be) don’t use a timer. Do it this way:

I use the entity_controller custom component in this case:

I’ve read the issue. I’ve read the code. Based on that, and my own experience using timers, I’d say you’re drawing the wrong conclusion. I don’t see any reason why calling timer.start on a running timer (with or without calling timer.cancel first) would not cause it to start the duration over again. True, the remaining attribute will not update, and probably the UI won’t either, (both of which are known shortcomings), but that doesn’t mean it hasn’t started over.

I suspect your issue has more to do with not carefully watching the behavior of sensor.fibaro_system_fgms001_zw5_motion_sensor_burglar. Are you sure it’s state (i.e., state string and/or attributes) is changing when there “is still motion”?