Configuring Template

I would like to configure a sensor that checks that all temperature sensors are working correctly.
I wrote this but the sensor value is always “unavailable” where am I wrong? Thank you

`- platform: template
sensors:
sensori_casa:
friendly_name: “Sensori casa”
value_template: >-
{% if states.sensor.rm_cucina_temperature != ‘unavailable’
and is_state(‘sensor.rm_sala_temperature’ != ‘unavailable’)
and is_state(‘sensor.rm_camera_temperature’ != ‘unavailable’)
%}
ok

          {% else %}
            ko
          {% endif %}`

Please format the code correctly.

Use this syntax:

states('sensor.rm_cucina_temperature') != 'unavailable'

Really neat (in my opinion):

        value_template: >-
          {% if 'unavailable' in 
                [states('sensor.rm_cucina_temperature'),
                 states('sensor.rm_sala_temperature'),
                 states('sensor.rm_camera_temperature')]
          %}
            ko
          {% else %}
           ok
          {% endif %}
1 Like

Is there a way to tell if the value is different from a number? sometimes the sensor is in ‘unavailable’ state, other instances ‘none’
Thanks again

You can int cast it and if it returns 0 then it’s a string.

This will do that check on your list of sensors:

        value_template: >-
          {% if [states('sensor.rm_cucina_temperature'),
                 states('sensor.rm_sala_temperature'),
                 states('sensor.rm_camera_temperature')]
                |map('int')|select('eq',0)|list|length > 0
          %}
            ko
          {% else %}
            ok
          {% endif %}

It will apply the int filter to each element, keep only those that are zero, turn it into a list and calculate the length of that list. If there are any items left, one of your sensors is returning a string.

This relies on your rooms staying above 0°C of course.