I would like to create an automation that turns on the lights 15 minutes before sunset but not after 22:00 and only if the outdoor illumination is below 250 and indoor illumination is below 10 for 2 minutes.
I think I need it to trigger on outdoor illumination with the durration of 2 minutes, then set a condition based on indoor illumination and time and then set the action to turn on the lights. Any thoughts on this automation?
Change the entity names to match the ones you have in your system.
How it works
It is triggered 15 minutes before sunset or when outdoor light level is below 250.
It checks if:
The current time is before 22:00
The outdoor light level is below 250
The indoor light level is below 10
If all conditions evaluate to true then it executes the action (turns on a light).
The one thing it does not do is the part where you specified the indoor light level must be below 10 for at least 2 minutes. A State Condition can check if a value remains unchanged for a given period of time. For example this checks if the indoor light level has remained unchanged at 10 for 2 minutes:
condition: state
entity_id: sensor.indoor_light_level
state: 10
for: '00:02:00'
However, it means the light level cannot drop below 10 during those 2 minutes; it must remain unchanged. Therefore a State Condition would not meet your requirement. A Numeric State Condition doesnât support a for option but it does handle your requirement for checking if the value is anything below 10.
There is a small, optional enhancement you can add and thatâs to only turn on the light if it is currently off (do nothing if it is already on). Itâs simply a matter of adding a State Condition:
Sunset doesnât really work as a trigger unless the other trigger is true. Could you not use the indoor light with a template trigger to satisfy the 2 minutes requirement. Then use sunset under condition?
Letâs consider the implications of that Template Trigger being part of several other triggers including:
when the outdoor illumination drops below 250
when its 15 minutes prior to sunset
If any of the other triggers trigger the automation, the Numeric State Condition is still limited to only checking if the indoor light level is âbelow 10â and not âbelow 10 for 2 minutesâ. So thereâs still a loop-hole where that requirement is not met.
If we were to eliminate the other two triggers, and only use your Template Trigger, that would definitely satisfy the âbelow 10 for 2 minutesâ requirement. However, if the indoor light level were to ever decrease below 10 before sunset or before outdoor light level is below 250 the conditions would prevent the light from being turned on. If it remained below 10 when sunset occurred, the automation would not trigger because a Template Trigger, once it has evaluated to true, must first return to false before it can trigger again.
Ideally, the Numeric State Condition would support for but, according to its documentation, it does not.
Yes, sorry, when I said âthatâs more like itâ I meant the use of for: in the Template Trigger. I completely ignored the actual template (which is incorrect).
The is_state() function doesnât support tests like âgreater/less thanâ only âequal toâ and it is implicit (i.e. it doesnât require that you explicitly add an equals sign within the function). For example, this means is the sensorâs state value equal to 10.
Thanks all for the input, itâs greatly appreciated. For the 2 minute issue I could use a âHelperâ and create an automation that sets the helper to on when itâs below 10 and off when itâs above 10.
The delay_on: '00:02:00' option will set the binary_sensorâs state to on only if the template is evaluates to true for a minimum of 2 minutes. In other words, the light level must be below 10 for at least 2 minutes in order for the binary_sensor to report on (otherwise it will report off).