Hi, I have a motion sensor that includes an illuminance sensor placed in an hallway. I have successfully automated lights to come on if motion is detected and to turn off when motion ends.
Next I made it to turn on the lights only if the illuminance sensor reports < 15lx. Unfortunately it turns out that the device only updates illuminance every 30 seconds. This means that when motion ends, there is a period when the illuminance sensor still thinks it has high illuminance even if the light is off, and ambient is dark. The effect of this is that a second passage in the hallway does not trigger the lights.
I tried creating the following template called sensor.ambient_upstairs_illumination:
{# If light is on, hold the previous value of the sensor #}
{% if is_state('light.upstairs_lights', 'on') %}
{{ states('sensor.ambient_upstairs_illumination') }}
{% else %}
{{ states('sensor.presence_sensor_actual_illuminance') }}
{% endif %}
However, since the light off event is reported timely by the smart switch, this means that the illuminance immediately jumps to the “high” value provided by the sensor as soon as the lights go off.
Is there a strategy that would allow me to hold the previous reported brightness if the lights are on now, or have been on any time in the previous minute?
Thanks for replying but as far as I can see this code has the same issue as mine. When the sensor reports no more occupancy, the light sensor still has the “high” value for about 30 seconds. If in those 30 secs another person comes in the occupancy sensor gets triggered again, but since the light sensor reads “high”, the lights won’t turn on. Am I missing something?
What device are you using that only updates every 30 seconds ?
@chairstacker mentioned that the aqara devices typically don’t update their illuminance values until motion is detected again, so it can appear to hold onto the old value, but it does actually get refreshed.
Some mmwave sensors have this problem, because they update more regularly. The very early firmware for the everything presence one had this issue, where it would only update every 15 seconds, irrespective of when motion had been detected.
It reports brightness “high” as soon as motion is detected, but it takes a minute (not 30 secs as I said before, my bad) to report brightness “low”, I guess because motion ended and it went back to low-power monitoring.
In my case:
The Aqara sensor has a setting for a ‘Detection Interval’, which I set to 2s.
Therefore, it will ‘re-detect’ motion every two seconds - if there is any - and update the illuminance value every time.
The result is that
if the light is still on, no problem: it will just reset the 35 second duration for the light.
if the light has been turned off already - meaning that 35 seconds had gone by - it will re-evaluate the illumination value that’s just been sent at the time when the motion was detected
For you:
It sounds like you need to play with the for value and make sure it’s kind of in line with the fixed update duration of your illuminance sensor, so that the light turns off just before the illuminance value is updated.
So the illuminance does refresh when motion is detected, but are you saying that irrespective of the actual light conditions, it always first gives a high reading ?
Do you have the model of the sensor we can investigate a bit more.
Nope - it always seems to give an up-to-date reading when motion is detected, otherwise my condition wouldn’t work.
And it seems like most of the times, it doesn’t update for 10 or 20 minutes if the motion sensor isn’t triggered - so, unlike my FP2s (which are mains-powered) I can’t use the P1s for reliable continuous illumination readings.
Given that the P1s are battery-powered and integrated via Z2M I understand that the compromise has to be made somewhere - and not updating the values in short intervals but getting the value together with the motion detection is a totally acceptable setup for me where I want to have a motion sensor that can trigger and release within seconds.
I have some Sonoff SNZB-03s in areas where I don’t need such a quick, i.e. 2 second, reaction time and they work well where I don’t need an illuminance reading and I can live with a ‘motion release time’ of 2 minutes.
P.S.:
I thought it was clear that the Aqara model was a P1 because it’s in the sensor’s name and mentioned in my first post.
P.P.S.:
And once I wrote all that I, realized that @Rofo probably responded to @l.scorcia’s message and not mine - duh!
But as I’d been done writing, I thought I might as well add it to the conversation.
How I got the topic working for me - Hopefully useful to someone.
I’ve found the Aqara P1 sensor detection range and performance to be great. Just be sure that before setting the sensor’s “max sensitivity” configuration change in Home assistant, you briefly press the pairing button on the Aqara P1 sensor first.
Here is a summary of the tricks to make the automation reliable:
Use 2 triggers. The first is “When Aqara PIR Occupancy changes from any state to Detected” and the second one is “When Aqara PIR Occupancy changes from Detected to any state for 100 seconds”(Where the 100 seconds delay is the “period of no movement” timeout you want - You set this value in the trigger configuration)
Use “If-then-else” logic to check the entity states
System environment
Home Assistant on a R.PI4 (2GB)
Sonoff zigbee 3 dongle - Used in Z2M mode. (Dongle is the more expensive one - Based on TI CC2652P + CP2102N)
Aqara P1 sensor (N.B. In the “Zigbee2MQTT” section, select the Aqara P1 device and go to the “exposes” tab. Set motion sensitivity to “High” and Detection interval to something less than your time out i.e. For testing use 2 seconds, but for production, set it to a suitable fraction of “period of no movement” e.g. divide it by 3 )
INNR smart plug (updated to the latest firmware to cater for over voltage sensitivity)
Desired automation behaviours
The automation is triggered by motion detection and it controls a switch
The switch will turn ON only if the light is below a set Lux level (i.e.it is dark)
The switch is kept ON until a set “period of no movement” has elapsed
Any movement re-triggering during the “period of no movement” resets the start of the “period of no movement”
After the “period of no movement” has elapsed, the switch is turned OFF.
YAML Code (for reference - use the Wizard instead!)
N.B. I created the automation using the “create Automation” wizard.
Whilst I didn’t need to alter any YAML code directly, I’m thinking the code below is useful to see, because you can compare it to the YAML code that gets created when you use the wizard.