Hi,
I deployed a ESPhome device that measures the distance inside a water tank via sonar. The distance is queried multiple times per second and sometimes the value is reported as unknown which causes my gauge card to flicker in and out.
Is there a way to prevent this? All my attempts in catching only numeric values so far did not work. Here is my template so far:
- name: "WTL Sensor 01 nan handled"
unique_id: wtl_01_safe
unit_of_measurement: "%"
state: >
{% set val = states('sensor.water_tank_level_sensor_01_distance') | float(default=nan) %}
{% if val == val %}
{{ ( (1.71 - val) / (1.71 - 0.33) * 100 ) | round(1) }}
{% else %}
-999
{% endif %}
availability: >
{{ states('sensor.water_tank_level_sensor_01_distance') not in ['unknown', 'unavailable', 'None'] }}
Thanks in advance!