In my configuration.yaml I have an entry for a sensor template where I’m bringing in a weather value from the REST platform. It is working fine until the external system doesn’t send a numerical value but a string of dashes and not always the same number of dashes. “- - -”
I’d like to test if the value has a dash and if so substitute a null or empty or blank value. Maybe something like this but I’m unsure how to do it. Any ideas?
{%- if is_state_attr('sensor.station_data','windAvg10') | contains('-') %}
If windAvg10 contains a value that thefloat filter cannot convert to a floating point number (in other words, the value is a non-numeric string) then float will report the default value I specified which is an empty string (but you can change it to whatever you want).
So if the value of windAvg10 doesn’t contain any numeric characters (merely one or more hyphens), float will report an empty string.