i am facing the problem, that my lights turn off too fast in some occasion.
So I thought about extending the time the light is on, based on how often the motion sensor had detected motion in a certain time frame.
Is that possible that way?
Just extending the time in general is not a real solution for me, because I don’t want to have lights on for such a long time.
Yes it is. If you aren’t extending the time but rather restarting the timer.
I have all my lights set to around 15 minutes, and every time motion is detected it simply restarts the timer. That way the lights will always switch off 15 minutes after the last motion. There is nothing to stop you reducing that to 5 minutes or less though, as long as you don’t make it less than the cooldown period of the motion detector.
Here is an example of the motion lighting in the hall:
This code cancels and restarts the timer when motion is detected. Catches the timer finished event to turn the light off, and starts a timer if the light was turned on manually - so it will still switch off when the timer expires.
It’s not exactly what I was looking for though.
Right now my lights turn off, if there is no motion for 20s.
For most occasions that is enough, but at times it turns off when I was standing still for too long.
So I thought I could expand the 20s to like 1min, when there is motion detected more than x times.
Does that make sense?
You could detect how many times the motion sensor turned on in the last X minutes. And then use choose when the motion sensor is triggered to decide if the lights should turn off after X seconds or X minutes based on how many times the history_stats sensor says the detector was on in the last X minutes.
eg: turn off after 20 seconds if the count is <2 and after 1 minute if the count is > 1
I am using a ratio history stats sensor to solve for this. Just turn the lights off when the ratio falls to 0 and make the delta long enough that someone typically triggers it before it hits 0 (this takes some analysis to find the sweet spot).
- platform: history_stats
name: Guest Bathroom Motion Ratio Last 10m
entity_id: binary_sensor.guest_bathroom_motion_occupancy
state: "on"
type: ratio
start: "{{ (now() + timedelta(minutes=-10)) }}"
end: "{{ now() }}"
Using a plain and simple automation here for avoiding the lighting for our patio is getting switched off if we are still sitting outside there after the scheduled switch-off time.
The lighting should switch to off daily at 22:00 but only if there has been no movement/occupancy detected for 10 minutes. If we are still sitting outside after above scheduled time the lights wont switch to off for as long as the occupancy sensor detects movement. Only after there has been no movement detected at the patio for at least 10 minutes the lights will be switched to off:
trigger:
- platform: time
at: '22:00:00'
- platform: state
entity_id: binary_sensor.xiaomi_aqara_motion_sensor_inner_patio_occupancy
to: 'off'
for:
minutes: 10
condition:
- condition: state
entity_id: binary_sensor.xiaomi_aqara_motion_sensor_inner_patio_occupancy
state: 'off'
for:
minutes: 10
- condition: time
after: '21:59:59'
before: '05:00:00'
action:
- service: switch.turn_off
target:
entity_id: switch.lichtschalter_innenterasse_4_fach
mode: single
The above works pretty well since quite some time now never left us sitting in the dark all of a sudden nor didn’t it switch the lights to off after it finally got quite at the patio. It’s basically a set-and-forget automation.
I’m using an approach with 2 automations:
The first one switches the lights on upon motion (trigger: motion detected).
The second one switches the lights off, but with an delay of x minutes (trigger: no motion detected, delay x minutes).
This way the lights stay on as long as there is motion and for x minutes after the last motion was detected.