Hello! I have a template that gives me the value of the uptime in a more readable way, but that value comes through mqtt and of course, when restarting home assistant it gives me an error because the value of the sensor is unknown, how could I add a filter or similar if it is unknown wait or show me loading… Thank you!
uptime_mopidy_templated:
icon_template: mdi:clock
value_template: >-
{%- set up_time = as_timestamp(now())-as_timestamp(states('sensor.mopidy_bano_last_boot') ) %}
{%- macro phrase(name, divisor, mod=None) %}
{%- set value = ((up_time // divisor) % (mod if mod else divisor)) | int %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{%- set values = [
phrase('semana', 60*60*24*7),
phrase('dia', 60*60*24, 7),
phrase('hora', 60*60, 24),
phrase('min', 60)
] | select('!=','') | list %}
{{ values[:-1] | join(', ') ~ ' y ' ~ values[-1] if values | length > 1 else values | first | default }}