Template that doesn't work

hi all, i have set up tis template but is always “unavailable”, do you have any ideas why?

template:  
  - sensor:
      - name: "litri_consumati_istantanei" 
        unique_id: litri_consumati_istantanei
        state: >
          {% if states('sensor.meross_smart_plug_1_power') > 0 %}
              5
          {% else %}
               0
          {% endif %}
        unit_of_measurement: "L/s"

If you put the template in the developer tools in ha, what ist the result, is it working there?
If even not there, maybe the value is stored as a string, then converting it to an integer could help:

{% if states('sensor.meross_smart_plug_1_power') | int(0) > 0 %}
    5
{% else %}
    0
{% endif %}
1 Like

yes! the conversion from string to integer works! thanks a lot!

There’s no ‘maybe’ about it. State values are always strings. Only attributes can have different types.

1 Like

Thanks for clarification, this was one of the background things in ha i wasn’t aware of!