So I am trying to create my first simple template. If Lightning is > 10 miles from my house return ‘Far’ (because I do not care), else if Lightning is < 10 miles from my house it reports the distance and the time measured.
{% if ("sensor.weatherflow_last_lightning_strike_distance" < "10") -%}
Far at
{%- else -%}
{{ states('sensor.weatherflow_last_lightning_strike_distance')}} at {{states('sensor.weatherflow_last_lightning_strike')}}
{%- endif %}
The template works however I cannot format the time to a readable time (ie. HH:mm). Also, how would I limit this template to only report lightning strikes in the past 60 minutes?
{% if (states('sensor.weatherflow_last_lightning_strike_distance') | float(0) > 10) -%}
So you don’t just use the sensor name but get that sensors state, convert it to a number that may have decimals and compare it to a number (not a string that is the textual representation of that number). The 0 parameter for the float filter is the default that is used when the sensor is unavailable.
Edit: I also changed the < to > because you meant far, as you said correctly above your code.
Thank you all for your help. It’s working now (almost) perfectly. Now I would like to limit the sensor to only show how many miles away if lightning struck in the last 60 minutes.