A brief tutorial demonstrating how to create a single automation to control a light that is able to handle missed events (i.e. Home Assistant is off when the primary trigger(s) occur).
I have some of my lights set to on/dim unless there is some motion. My current automation just does a brightness pct 100 to get it to maximum brightness. When no longer motion I do a brightness pct back to 40%.
But what if the light is already at 100% or 40%?
Could we expand on the masterclass code above to include brightness pct? Iâd like to improve my automations to not fire off an action when it is not needed for changing the % brightness. Could the line above
- "{{ is_state('light.exterior', 'on') }}"
be expanded to allow for (in english) âIs the brightness already 40%/100%â
No because brightness_pct is not an attribute, itâs an option for the light.turn_on service.
What you can use is a light entityâs brightness attribute. It only exists when a light is on. The value of brightness ranges from 0 to 255 so 40% corresponds to 255 x 0.4 = 102.
This checks for brightness exceeding 40%.
- "{{ is_state('light.exterior', 'on') and state_attr('light.exterior', 'brightness') >= 102 }}"
If you want it to confirm brightness is exactly 40% or 100% (corresponding to 102 or 255) then you can do this:
- "{{ is_state('light.exterior', 'on') and state_attr('light.exterior', 'brightness') in [102, 255] }}"
Thanks a lot for this automaiton.
I would like to modify the second condition and turn off the light not at elevation above -3.1, but at a specific time. Say 1AM.
There is probably a variable to add and conditions to change, but I canât get my head around itâŚ
Thanks in advance for your help.
I tried copying-pasting the code and get the error when trying to save it Message malformed: extra keys not allowed @ data['0'] Iâm not sure what Iâm doing wrong when trying to import this code.
Iâm trying to implement the code that is the âsmartest versionâ inf the first post:
I would want an automation to run in case it got missed; for example HA restarts and it so happens that it was sunset, thus the automation wasnât triggered.
I tried also re-building the code but canât seem to get it to work. If there is any direction you point me.