Got log error and AI helped me to find its cause: int in below should be int(0) to prohibit that sensor crashes as sensor is unknown. {{ (include_ambient == 'ambient_enabled') and
((states(ambient_light_sensor) | int) < (ambient_light_value | int)) }} and thanks for your automations!
I am not keen on setting a default value for this in the automation, and AI is not understanding my thought process.
I have included a FAQ (Click Here see REF - ALS-2) entry explaining how to handle sensors that occasionally become unavailable. Personally, I would replace a sensor that frequently loses connection with one that is more reliable.
If you would like to use this sensor, a better approach is to create a template sensor that provides a fallback value when the original sensor becomes unavailable. This gives you full control over what should happen and what value should be used. Some people may prefer 0 , while others may prefer 100 . It is entirely up to you.
This is why I do not set a default value in the blueprint. I do not want to assume your preference and potentially turn a light ON or OFF based on a faulty sensor. By creating your own template sensor, you can decide exactly how unavailable states should be handled.
To create a Template sensor, follow these steps:
Navigate to Settings > Device & Services > Helpers tab at the top.
Click the Create helper button.
Select Template and then choose sensor.
Next, provide a Name you would like to call your sensor, Unit of measurement = (lx), Device class = (Illuminance) and State class of your choice if any. If applicable, you can link this template to an existing device (your lux sensor) so it appears under that device's details.
In the State field, add the code below, replacing sensor.your_lux_sensor_here with your actual lux sensor entity ID.
Then in the float you have a value of 0.0 if your sensor keeps going 'unavailable', 'unknown' or 'none'