Hi All, need your help to setup door automation using timer features to off all light which I can’t figure it out.
Lets put sensor name as below
binary_sensor.door_sensor_opening
timer.30 (30secs)
binary_sensor.motion_sensor
script.off_all_light
Automation that need to run as below:
when door open, there will be 30sec timer running, if no motion detect after end of 30sec timer then run “script.off_all_light”. But if motion detected during 30sec then cancel the timer.
I not sure if I need to put this “But if motion detected during 30sec then cancel the timer” because it might made the automation never run or you guy have any other method for this matter?
This implements what you’ve asked for, assuming the door remains open for 30s. Note that I didn’t use your timer: see rule 8. Triggers after the door has been open for 30s, checks if there’s been no motion in that 30s.
trigger:
- platform: state
entity_id: binary_sensor.door_sensor_opening
to: 'on' # whichever state means "open"
for: "00:00:30"
condition:
- condition: state
entity_id: binary_sensor.motion_sensor
state: 'off'
for: "00:00:30"
action:
- service: script.turn_on
target:
entity_id: script.off_all_light
If there has been motion, the light will not turn off — but that is what you asked for. If you want something different, please explain in a structured way.
In particular, how do you open the door without triggering the motion sensor?
sorry @Troon didn’t notice the rule, I should explain the result that I need.
here is result that I need,
Once I open the door, I would like to off all light provided no one in the house trigger the motion sensor within 30secs. But if someone is in the house & moving within 30secs, then the light won’t off. Problem now is if someone walk through the motion sensor & within 30sec open the door, the automation might not run as the motion sensor required 30sec to release from “detect to clear”. Unless I increase the timing to higher?
Well you can try using timer helper. In my scenario I use time helper to turn off light in kitchen. This is working far more better than using state for function for a few reasons.
You can change timer duration without changing automation.
Motion sensors have default value how long will they consider that motion is on, usually 90 seconds. You can change this is z2m config if using zigbee.
Timer will run only if no motion is detected. If motion sensor stop detecting motion it will start timer. But if motion is detected while timer is running, than cancel timer and start it again when motion is not detected.
@Troon look like the automation doesn’t always work, it will work for 1st time. Once timer start, 2nd time trigger on motion won’t cancel the timer. By the way, my binary sensor is the group of motion sensor that will on once one the motion sensor is on.
By the way, possible to combine both automation into one automation as it is consider under one control.
alias: OFF ALL light
description: ""
trigger:
- type: opened
platform: device
device_id: xx
entity_id: binary_sensor.door_sensor_opening
domain: binary_sensor
id: door open
- platform: event
event_type: timer.finished
id: ALL light OFF timer END
event_data:
entity_id: timer.off_all_light_timer
- platform: state
entity_id:
- binary_sensor.motion_sensor
to: "off"
id: Confirm ALL sensor OFF
condition: []
action:
- if:
- condition: trigger
id: door open
then:
- service: timer.start
data: {}
target:
entity_id: timer.off_all_light_timer
- if:
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.motion_sensor
state: "off"
- condition: trigger
id: ALL light OFF timer END
then:
- service: script.off_all_light
data: {}
mode: restart
I using different method as above although this one I need to set the timer time higher but still not perfect as might accidently off all light.