I have an automation for a light that looks like the following (note – some stuff has been deleted to make this simpler to understand).
alias: Kitchen Sink Light On
trigger:
- platform: time
at: '18:45:00'
- platform: sun
event: sunset
condition:
- condition: time
after: '18:45:00'
- condition: sun
after: sunset
action:
- type: turn_on
The automation works fine – the light comes on at the later of 6:45 pm or sunset. Thanks to some help from folks here, I was able to put together a luminance sensor and would like to include its value in the condition. Specifically, I would like the light to trigger:
The later of 6:45 pm or sunset
After 6:45 pm and before sunset if the luminance is less than some value
Not sure how to include this – would you please offer some guidance.
The first thing I did was create a trivially simply automation to turn on a test device after a certain time and that worked. I then tried your code, but it did not work. Here are some more details:
This is a simplified copy of the device definition (copied from ESPHome UI, clicked Edit under the device’s name)
I have a thought about the issue: When I looked at the log for the sensor, I saw things like "‘Light Level’: Got illuminance=32.3lx’. If the ‘x’ is part of the value being return, I understand why a simple mathematical comparison would fail. If this is the case, what can I do to resolve the issue, i.e., how can I compare the return value to some other value?
Here is what I found:
sensor.light_level
Light Level 17.6
state_class: measurement
unit_of_measurement: lx
device_class: illuminance
friendly_name: Light Level
That looks perfectly fine, but your time condition looks off. before: 00:00:00 doenst look right to me. Try removing the line? Have you checked the automation trace to see if the automation is triggered and what conditions succeed or not?