Avoid using states.sensor.temperature.state , instead use states('sensor.temperature') . It is strongly advised to use the states() , is_state() , state_attr() and is_state_attr() as much as possible, to avoid errors and error message when the entity isn’t ready yet (e.g., during Home Assistant startup).
This won’t fix the problem, but it will help the logs. It’s possible that states.sensor.temperature.state might not even exist at some point (if HA reboots while the ESP isn’t connected).
To fix the issue, take a look at what is evaluated. Open Dev Tools >> Templates and type the following into the box.
{{ "unavilable" | float < 16.00 }}
This evaluates to True. In fact, all {{ string | float < 16.00 }} is true. Why? Becuase the float filter returns a default value of 0 if it could not convert the value.
This means any failed conversion will return 100.0. It’s not very flexible, but it will help in this case.
The better solution would be to just check that it exists first. states(‘sensor’) will return ‘unknown’ always if it doesn’t exist which is why it is recommended to use.
trigger:
- for: 00:00:20
platform: template
value_template: >
{% set t = states('sensor.xiaomi_lywsdcgq_temperature) %}
{{ t != 'unknown' and t | float < 16.00 and t | float > 22.5 }}