Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95419

Crazy templating

$
0
0

@gekomax wrote:

Hello folks,

I have a strange code, I can’t make it work.
This is the code:

- platform: template
  sensors:
    qualita_aria_floated:
      value_template: '{{ ((states.sensor.luftdaten_34405_p1.state)) | round(0, "ceil") }}'
      entity_id: sensor.luftdaten_34405_p1
    qualita_aria:
      value_template: >-
        {% if states.sensor.qualita_aria_floated.state >= '0' and states.sensor.qualita_aria_floated.state <= '49' %}
          buona
        {% elif states.sensor.qualita_aria_floated.state >= '50' and states.sensor.qualita_aria_floated.state <= '100' %}
          moderata
        {% elif states.sensor.qualita_aria_floated.state >= '101' and states.sensor.qualita_aria_floated.state <= '150' %}
          malsana per gruppi sensibili
        {% elif states.sensor.qualita_aria_floated.state >= '151' and states.sensor.qualita_aria_floated.state <= '200' %}
          malsana
        {% elif states.sensor.qualita_aria_floated.state >= '201' and states.sensor.qualita_aria_floated.state <= '300' %}
          molto malsana
        {% elif states.sensor.qualita_aria_floated.state >= '301' and states.sensor.qualita_aria_floated.state <= '500' %}
          pericolosa
        {% else %}
          sconosciuta
        {% endif %}
      entity_id: sensor.luftdaten_34405_p1

If I use the tempate editor in HAS,:


       {% if states.sensor.qualita_aria_floated.state >= '0' and states.sensor.qualita_aria_floated.state <= '49' %}
          buona
        {% elif states.sensor.qualita_aria_floated.state >= '50' and states.sensor.qualita_aria_floated.state <= '100' %}
          moderata
        {% elif states.sensor.qualita_aria_floated.state >= '101' and states.sensor.qualita_aria_floated.state <= '150' %}
          malsana per gruppi sensibili
        {% elif states.sensor.qualita_aria_floated.state >= '151' and states.sensor.qualita_aria_floated.state <= '200' %}
          malsana
        {% elif states.sensor.qualita_aria_floated.state >= '201' and states.sensor.qualita_aria_floated.state <= '300' %}
          molto malsana
        {% elif states.sensor.qualita_aria_floated.state >= '301' and states.sensor.qualita_aria_floated.state <= '500' %}
          pericolosa
        {% else %}
          sconosciuta
        {% endif %}
        
        {{ states.sensor.qualita_aria_floated.state  }}
        {{ ((states.sensor.luftdaten_34405_p1.state ) ) | round(0, "ceil") }}`

got this:

pericolosa

    5
    5

(on lovelace got the same)

That it’s completely illogical… or am I wrong?

I’m sorry this is written in italian but I think it’s in understandable…

Any suggestion?
Thanks!
Bye
Gekomax

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 95419

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>