I have automated my kitchen lights using a presence sensor (Everything Presence 1).
It triggers the light to turn on, in case some one is present in the room and the illuminance is above a certain threshold.
Unfortunatly the illuminance sensor on the Everything Presence 1 does not update immediatly, which is why I am sometimes stuck in the dark. It could be, that no further presence is detected, which after some delay turns the light back off. If someone enters the kitchen shortly after, it could be the case, that the illuminance sensor has not yet updated the value and the light automation is not triggered, as the illuminance indicated is above the threshold.
To work around the delayed update of the illuminance sensor, I would like to create a template sensor, which takes the updated values of the illuminance sensor, but only when the light is off. In case the light is on, values provided by the illuminance sensor shall be discarded.
Can someone help me to define this template sensor?
Glad to provide more details on my sensors and automation, in case it provides any benefit.
You mean below, I guess.
Not sure why the fact that the illuminance update is not instantaneous matter to you…
The automation is like “if someone enters the room (trigger) and the illuminance is below a threshold (condition), turn the light on (action)”. So illuminance should be a condition, not a trigger.
Yes, sorry you are correct. The illuminance is a condition to the automation and if below a certain threshold, it will continue running the automation. I have attached the YAML in order to clarify how it is configured at this moment.
Motion Triggered Light Automation - YAML
- alias: Light - Motion in Kitchen
id: 'light_kitchen_motion'
trigger:
- platform: state
entity_id: binary_sensor.presence_kitchen_occupancy
from: 'off'
to: 'on'
#If motion is detected within the delay, the automation is restarted.
mode: restart
max_exceeded: silent
condition: []
action:
- choose:
- conditions:
#Turn kitchen light on automatically upon detected motion, in case ambient is dark
- condition: template
value_template: "{{ (states('sensor.kitchen_illuminance') | int < states('input_number.illuminance_cut_off_kitchen') | int) }}"
sequence:
- service: light.turn_on
entity_id: light.kitchen
default: []
- wait_for_trigger: #No more motion detected
platform: state
entity_id: binary_sensor.presence_kitchen_occupancy
from: 'on'
to: 'off'
#Wait a little longer before turning light back off
- delay: "{{ states('input_number.no_motion_wait_kitchen') | int }}"
- service: light.turn_off
entity_id: light.kitchen
However the problem is not upon first entering the room. It is upon leaving the room but re-entering, when the occupancy has gone to CLEAR, the Light has been turned off, but the illuminance sensor has not yet been updated. This will prevent the automation to turn on the light when re-entering.
See the following example:
Not a fan of wait_for_trigger myself, here is my automation for basically the same.
It’s triggering on the illuminance as well (bureau_has_light, which is a threshold helper doing basically the same as your condition template), so whenever the room goes from “dark” to “illuminated” and vice-versa, the automation is triggered as well.
That maybe does not completely fix the issue of slow illuminance update, but, at least, when the update does happen, the automation is triggered and the light turned on, if with a delay…
The Ep1 updates its illuminance sensor every 30 seconds.
Unlike something like the aqara p1 motion sensor, the illuminance is NOT automatically refreshed when motion is detected.
This means that if you leave the room and wait for the lights to go out, there maybe a small window for a few seconds where you’re able to go back into the room with the EP1 recording the ‘old’ illuminance setting.
The way I have got around this is to set the threshold to a value that doesn’t get exceeded even when with the lights on. I know this sounds strange, but with the lights largely shining downwards, the illuminance value only goes up slightly when the lights are on. This is very different to the day light reading which is much higher, so the automation works just fine.
Unfortunately that is not the case for me.
I came across this git pull request, which would resolve the issue. Hope it gets merged soon into the production build. Until then a template sensor with the light state as a condition should do the job.
I was chatting to lewis about this and other stuff on the EP Discord server.
If you have adopted the EP1 into ESPHome, you can grab the yaml config file and build it yourself without waiting. There are also settings in there to change the frequency of the illuminance and temperature sensor intervals.
Its super simple. I did it earlier to test a setting that wasn’t available via the UI.
@T1ppes - The PR you mention has made it into the production release, so it should now update the lux value on motion being sensed, and solved your problem.