To my understanding, in an if statement the first one with outcome true will be set.
A few times a week the brightness is set to 8 while the hour is not smaller than 6 but e.g. 20. Why is it set to 8 then?
An automation that triggers the one above when a door is opened, but with condition that the light is off.
An automation that turns on the light with 255 brightness when an entity comes home.
Automations that turn on the light when a Xiaomi button is used.
Automations that set the light to a specific colour from actionable notifications on iOS.
All of these did not happen.
If I remember correctly I saw this brightness 8 being set when the original (first post) automation was triggered by it’s motion sensors. It’s also the only automation I have that would set that light to brightness 8.
Well the template is correct. I set up a test quickly to verify your logic and look at the outputs. All hours and minute combinations of the day are set correctly. Starting at 6 it slowly increases to 192 until 9 am and stays steady until 11 pm. Then it slowly drops to 10 at 11:59 pm and it’s 8 again at midnight. So, if what you are saying is correct and it’s getting set wrong, then it’s possible that your timezone in HA or your timezone in your OS is wrong. Or the hardware is failing. You may also want to have your logs set to info and watch state changes to verify that 8 is being sent to it.
Thanks for checking.
HA time and timezone is ok.
Device time and timezone is ok.
A few weeks ago I had to enable hourly time sync though because when syncing once a day it was some minutes (~7) off.
It wouldn’t be the case that reading the time during this hourly sync results in trouble, right?
Will be difficult to debug as it only happens a few times a week.
I agree, but in order to track it down. Maybe send yourself a message. Make an automation or something that triggers between the non 8 hours and send you the message if the brightness is 8. Then immediately go check the info logs. Or at least you have a timestamp to then check the logs later at night.
Notification for brightness < 9 is set up and working.
Just got a hit and there is no log for it on the INFO level. At least, the following one is related, but this seems to be happening when the turn_off is activated (id: 001). ERROR (MainThread) [homeassistant.helpers.condition] Error during template condition: UndefinedError: 'mappingproxy object' has no attribute 'brightness'
Can increase the log level but then we have to be more specific to prevent thousands of entries.
Here is the full automation including the one it enables:
because the method returns None, and when none gets converted into an int with the int filter, it makes it zero. So that template is looking for values between 0 and 9, which should be what you are looking for.
Honestly no, need to see what could be causing the problem. I’d say debug logging but don’t keep it on too long. You’ll have a huge log.
The first automation turns on the light. It also enables an automation to turn off the light when the motion sensors do not detect motion any more.
Apparently the brightness is below 9 and thus the notification is sent.
A little over 2 minutes later the trigger for no motion is met and the light is turned off. (Note: Xiaomi Aqara motion sensors only send the ‘no motion’ signal if there is already no motion detected by them for 2 minutes.)
Only odd thing I see is the ‘below 9 brightness’ trigger happening about 20 seconds after turning on the light. Thus theoretically it would be possible that ‘something’ turned down the brightness 20 seconds after the trigger. No clue what that could be though, not in HA, as well as outside HA.
This is the only odd thing happening to my setup.
No crashes, no instability, no high resource usage.
Time seems off max 5 seconds per hour, with synchronization each hour. Not nice for a modern computer (RPi 3b) but should still be fine.
That leaves the option open that it is the light bulb itself…then again, brightness 8 is a huge coincidence then. I am changing the template value to 6 now.
The next template runs on another light and I haven’t seen a wrong brightness setting.
As far as I am able to see, I would point to HA. Maybe there still is something in it’s way. Maybe the way I coded the if statement is wrong (maybe it needs single or double quotes?). Maybe HA trips over it.
None of that should matter. If it fails setting a brightness it would assign it zero if anything. The template looks good. I see nothing wrong with it and I even tested all the numbers. How about this. Make a template sensor with the same equation. Perform a update sensor service call in your automation before setting the lights. Then in your notification, add that sensor value to the message. Then you’ll see if the template is really messing up during runtime.