I have an Ultrasonic sensor on an ESPhome integration. Based on a certain distance, I would like to set a state of a template sensor.
Looking in the developer tools-> states, the ultrasonic sensor reading is 0.91.
If I want to set the output of the template sensor, I would like to see if the distance is between 0.85 and 0.95. Therefor, I use this template:
{%if states(‘sensor.sbf4_ultrasonic_sensor’) |float < 0.95 and
states(‘sensor.sbf4_ultrasonic_sensor’) |float > 0.85%}
Empty
{% else %}
Full
{% endif %}
The output of the template is “Full”, but the sensor state is 0.91
Looking at the template tool:
{{states (‘sensor.sbf4_ultrasonic_sensor’) |float |round (4) }}
This results in 0.0
Looking at the States tool:
It shows state: 0.91
So there is a difference in processing the ultrasonic sensor value.
The ultrasonic sensor is only outputting its value a couple of times per hour and the ESP is also using sleep modes. However, in the developer tools-> states, the 0.91 is always there. If I overwrite the value and update it again, it will show 0.91 again, while the template shows 0.0.
What is going on here
I haven’t configured the complete sensor yet. Since I am not an expert in coding, I thought to test it in the developer test tool first. Adding the space didn’t change anything.