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
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.
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?
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.