How to catch 'unavailable' in MQTT sensor template

Hi all

I should probably know the answer to this but struggling. I have several MQQT temple sensor’s and get the odd error in my logs when the template fails to render due to an ‘unknown’ value.

“expected numeric value but got unknown” for example.

So how do I prevent this in the following template for example?

    value_template: >
      {% if value_json['gasmeter']['energy']['import']['day'] == 0 
        and now() > now().replace(hour=0).replace(minute=1).replace(second=0).replace(microsecond=0) %}
        {{ states('sensor.smart_meter_gas_import_today') }}
      {% else %}
        {{ value_json['gasmeter']['energy']['import']['day'] }}
      {% endif %}

I have the same problem as you. Did you ever get this resolved?

Hi Alex, no afraid not. I probably just excluded the error from HA, sorry.