Template Sensor 3rd case

Hi, im trying to achieve a 3rd state if … if … then “0”

currently im running with 2 states, sample

  - name: "Unraid Wassertemperatur"
    unit_of_measurement: "°C"
    state: >
      {% set x = states('sensor.rest_unraid_sensors_wassertemperatur') %}
      {% set y = states('sensor.wassertemperatur') %}
      {{ y if x in  ['unavailable', 'unknown', 'none'] else x }}```

and i would like to achive, if both are unknown ... set 0

For any hints, thanks ahead

Hi @alturismo

I’d suggest going with the long hand version of the if structure:

{% if x in  ['unavailable', 'unknown', 'none'] %}
{% if y in  ['unavailable', 'unknown', 'none'] %}
0
{% else %}
{{ y }}
{% endif %}
{% else %}
{{ x }}
{% endif %}
1 Like

thanks alot :wink:

For the sake of completion, the shorthand notation would be


      {% set x = states('sensor.rest_unraid_sensors_wassertemperatur') %}
      {% set y = states('sensor.wassertemperatur') %}
      {% set fail = ['unavailable', 'unknown', 'None'] %}
      {{ 0 if x in fail and y in fail else y if x in fail else x }}

1 Like