Can some body please please please help a complete Home Assitant dummy with a “simple” automation.
I am trying to set up an automation to turn on a group of lights (connected by smart sockets) when the light level in a room is below a set level (17 lux) between certain times of the day (after 15:15 & before 21:30).
I am using an Aqara P1 as the motion sensor connected via Zigbee2MQTT & the smviceart plugs are a mixture of wifi & Zigbee.
Below are screen shots of the automation (I don’t do YAML & I am far too old to learn now)
I’m guessing the "star icon is the P1 illumination sensor but the A/B one is I have no idea. It does say that “This step wasn’t executed” when I click on it which I guess means the automation did not run (a cross is bad right?) but WHY???
Below is the copy of the Automation config. In lines 9 to 13 the numeric values (hours, minutes, seconds & below) are correct but these are in red. IS this bad or just to look pretty??? :-
id: ‘1764087627624’
alias: Downstairs Evening Lights ON
description: ‘’
triggers:
It is triggered by illuminance (when the value decreases below 17 or rises above 0) and time (at 15:15).
When triggered (either by illuminance or time) it checks if illuminance is within the defined range (between 0 and 17) and the time is within the desired range (between 15:15 and 21:30).
If the conditions are met, it turns on four switches (referencing them by their device_id).
Here’s why time is a trigger. If illuminance decreases below 17 before 15:15, the conditions will not be met (because it’s too early). However, the Numeric State Trigger will have done its job and, here’s the important part, will not trigger again until the illuminance first rises above 17 and then decreases below it (a Numeric State Trigger triggers upon the crossing of the threshold value).
The inclusion of the Time Trigger ensures that when it’s 15:15, the automation is triggered and checks the conditions again. This time they will be met (because the illuminance had decreased below 17 prior to 15:15) and the action will be executed.
FWIW, this is the usual way to handle a very common scenario: perform an action when some value lies within a certain range but only within a desired time period.
NOTE
If you want to make the automation more fault-tolerant, add this third trigger:
- trigger: homeassistant
event: start
Here’s what that does for the automation.
Let’s say you have a power failure at 15:00, power comes back at 16:00, and illuminance is 15. The third trigger detects when Home Assistant starts and checks the conditions. The conditions are met because it’s within the time range and the illuminance is below 17 (and the switches are turned on).
Without that third trigger, the automation fails to do anything because Home Assistant was non-functional during the power failure. The Numeric State Trigger missed the chance to detect the illuminance decreasing below 17 and the Time Trigger couldn’t trigger at 15:15.
Just want to add, you can also use Sun - Home Assistant to trigger when the sun comes up/down (because actual daylight will vary from specific time periods.
Another thing to note: lux sensors in motion sensors often only update when there is motion. Check the history graph of your lux sensor entity if it behaves as you need when there isn’t any motion.
Thank you all seems I have a lot to learn & have an up hill struggle on my hands here but your help is so much appreciated.
nice see people are really helpful on here & not condescending. Special thanks to 123 Taras, your “How it works” comment turns what to me is a completely foreign language into English, kudos to you & everybody else.
I had no idea that’s how they worked. I thought changing to detection interval under devices governed the reporting back to Home Assistant interval. I bet that did not help matters at all. Thank you
I suggest you get your hands on a dedicated Lux sensor (Aqara make these too). Light level detection is pretty much a secondary feature on most motion sensors (hence the name). A dedicated light sensor will ensure that you get constant readings without requiring any motion.