Template confusing me (old vs new) and different types

Hi,

i tried to add new templates for calculating and comparing humidity to be able to control the ventilation. copied the code from Simon42.
now I got errors and according to home-assistant template website I found out that the writing changed and there is an old and a new way.

before that it worked, when I add the new code i get an error. the strange thing is the new code works, when I remove my existing templates. and vice versa.

I would like to update my config to the new standard, but don’t know how. here is what I got:

template:
  - sensors:
      - name: "Anruf-Status"
        unique_id: 'phone_line_status'
        value_template: >-
              {% if is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "idle") %}
                  Leitung frei
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "dialing") %}
                  {{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.to_name }} ({{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.to }})
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "ringing") %}
                  {{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.from_name }} ({{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.from }})
              {% else %}
                  {{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.with_name }} ({{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.with }})
              {% endif %}
        icon_template: >-
                {% if is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "idle") %}
                  mdi:phone-classic
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "dialing") %}
                  mdi:phone-outgoing
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "ringing") %}
                  mdi:phone-incoming
                {% else %}
                  mdi:phone-in-talk
                {% endif %}

    - name: "weather_home_humidity"
        value_template: "{{ state_attr('weather.wetterdienst', 'humidity') }}"
        friendly_name: 'Außen Luftfeuchtigkeit'
        unique_id: "OutdoorHumidity"
        unit_of_measurement: '%'

      # Errechnet aus der relativen Luftfeuchtigkeit und Temperatur im Innenraum die absolute Luftfreuchtigkeit in Gramm pro Kubikmeter
    - name: "Absolute Luftfeuchtigkeit Holodeck"
        unique_id: "AbsoluteHumidityHolodeck"
        unit_of_measurement: "g/m^3"
        state_class: "measurement"
        state: >
            {{ ( 1000*e**(19.016-(4064.95/(float(states('sensor.innen_temperatur'))+236.25)))*100/(461.66*(float(states('sensor.innen_temperatur'))+273.15)) * float(states('sensor.innen_humidity'))/100 | float) | round (2) }}

      # Errechnet aus der relativen Luftfeuchtigkeit und Temperatur außen die absolute Luftfreuchtigkeit in Gramm pro Kubikmeter
    - name: "Absolute Luftfeuchtigkeit außen"
        unique_id: "AbsoluteHumidityOutside"
        unit_of_measurement: "g/m^3"
        state_class: "measurement"
        state: >
            {{ ( 1000*e**(19.016-(4064.95/(float(states('sensor.hue_outdoor_motion_sensor_1_temperature_2'))+236.25)))*100/(461.66*(float(states('sensor.hue_outdoor_motion_sensor_1_temperature_2'))+273.15)) * float(states('sensor.weather_home_humidity'))/100 | float) | round (2) }}

      # Errechnet den Untschied der Luftfeuchte von innen und außen in Gramm pro Kubikmeter
    - name: "Absolute Luftfeuchtigkeit Unterschied"
        unique_id: "AbsoluteHumidityDifference"
        unit_of_measurement: "g/m^3"
        state_class: "measurement"
        state: >
            {{ ( float(states('sensor.absolute_luftfeuchtigkeit_holodeck')) - float(states('sensor.absolute_luftfeuchtigkeit_aussen')) ) | float | round (2) }}

  - binary_sensor:
    - platform: ping
      host: 192.168.1.200
      name: myComputer
    - platform: template
      sensors:
        desktop_online:
          friendly_name: "Mein Computer ist Online"
          delay_off:
            minutes: 1
          value_template: >-
            {{ states('binary_sensor.mycomputer')}}

the error says

Error loading /config/configuration.yaml: while parsing a block mapping
in "/config/configuration.yaml", line 70, column 5
expected <block end>, but found '-'
in "/config/configuration.yaml", line 94, column 5

I googled and tests now for 2 hours and I am confused. can’t bring it be work.

hope you can help me out.
TurboKanne

template:
  - sensor:
      - name: "Anruf-Status"
        unique_id: 'phone_line_status'
        state: >
              {% if is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "idle") %}
                  Leitung frei
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "dialing") %}
                  {{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.to_name }} ({{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.to }})
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "ringing") %}
                  {{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.from_name }} ({{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.from }})
              {% else %}
                  {{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.with_name }} ({{ states.sensor.fritz_box_7590_call_monitor_telefonbuch.attributes.with }})
              {% endif %}
        icon: >
                {% if is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "idle") %}
                  mdi:phone-classic
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "dialing") %}
                  mdi:phone-outgoing
                {% elif is_state("sensor.fritz_box_7590_call_monitor_telefonbuch", "ringing") %}
                  mdi:phone-incoming
                {% else %}
                  mdi:phone-in-talk
                {% endif %}
1 Like

Yes, that is working now thank you very much.
but still not understanding why I was not able to manage that :cry:

You can find this information in the documents. All that Tom changed was the field names, which is covered in the template docs in the new sensor section. The legacy sensor section contains the legacy field names.