I’ve a motion sensor, outdoor (colour) light and a timer configured in Home Assistant.
Basically I want the following scenario:
If motion is detected:
Record the current state of the light (colour and brightness)
Turn on the light to a specific brightness and make it white
Start a 2 minute countdown
If motion is detected whilst the existing timer is running
Reset the countdown to 2 minutes
If the countdown expires
Restore the original light state (could be a colour, or maybe off)
I have the following automation configured:
- alias: Front Garden Motion hide_entity: true initial_state: true trigger: - platform: state entity_id: binary_sensor.front_garden_motion_motion from: 'off' to: 'on' condition: - condition: numeric_state entity_id: sensor.front_garden_motion_light_level below: 500 action: - service: timer.start entity_id: timer.garden_light - alias: Front Garden Light Timer Started trigger: - platform: event event_type: timer.started event_data: entity_id: timer.garden_light action: - service: scene.create data: scene_id: garden_before snapshot_entities: - light.garden - service: hue.hue_activate_scene data: group_name: Garden scene_name: Bright - alias: Front Garden Light Timer Stopped trigger: - platform: event event_type: timer.finished event_data: entity_id: timer.garden_light - platform: event event_type: timer.cancelled event_data: entity_id: timer.garden_light action: - service: scene.turn_on data: entity_id: scene.garden_before
According to the documentation (https://www.home-assistant.io/integrations/timer/#service-timerstart) this should work fine since the timer will be restarted at its original value.
However it appears Timers are in fact broken (https://github.com/home-assistant/home-assistant/issues/12013) as when service.start is invoked on a timer it actually doesn’t restart.
To get the countdown timer to reset to 2 minutes I could instead have the following action:
action: - service: timer.cancel entity_id: timer.garden_light - service: timer.start entity_id: timer.garden_light
But this has the downside of triggering a state change and an event which means my
scene.create action where I attempt to record the original light state is now overwritten by the ‘bright’ state.
I did try introducing a condition in the ‘Brighten the Garden’ automation by ensuring the timer has remained in an idle state for 2 seconds before invoking
scene.create, but this has no effect since the condition will fail as the timer will now be ‘active’.
- alias: Brighten the Garden hide_entity: true initial_state: true condition: - condition: state entity_id: timer.garden_light state: "idle" for: seconds: 2 trigger: - platform: state entity_id: timer.garden_light from: "idle" to: "active" action: - service: scene.create data: scene_id: garden_before snapshot_entities: - light.garden - service: hue.hue_activate_scene data: group_name: Garden scene_name: Bright
So… I’m kind of stuck - I can’t implement my above scenario which stores the existing state of a scene. I can only really set the light to an explicit state at the beginning and end of a timer and call ‘cancel and start’ one after the other.
Can anyone else suggest a method to achieve the scenario outlined at the beginning?