Migration from legacy to new format templates

Hi, I need your support… I’m struggling with the migration from legacy format to the new format.
I need advice, how to switch these two sensors in the new format:

differenz_humidity_garage:
        friendly_name: "Differenz Luftfeuchte"
        unit_of_measurement: "g/m³"
        device_class: humidity
        icon_template: mdi:water
        value_template: "{{ ((states('sensor.garage_absolute_humidity') | float(0)) - (states('sensor.aussensensor_absolute_humidity') | float(0)))|round(2) }}"

and 2.

corrected_temperature_technik:
        friendly_name: "Technik"
        unit_of_measurement: "°C"
        device_class: temperature
        value_template: '{{ states("sensor.temperatur_technik") | float(0) - 1.3 }}'

Thank you!

template:
  - sensor:
      - unique_id: differenz_humidity_garage
        name: "Differenz Luftfeuchte"
        unit_of_measurement: "g/m³"
        device_class: humidity
        icon_template: mdi:water
        state: "{{ ((states('sensor.garage_absolute_humidity') | float(0)) - (states('sensor.aussensensor_absolute_humidity') | float(0)))|round(2) }}"

      - unique_id: corrected_temperature_technik
        name: "Technik"
        unit_of_measurement: "°C"
        device_class: temperature
        state: '{{ states("sensor.temperatur_technik") | float(0) - 1.3 }}'

If you want the entity_ids to match the old ones you will have to edit the entity_ids in the frontend to match the old entity ids:

sensor.differenz_luftfeuchtesensor.differenz_humidity_garage

sensor.techniksensor.corrected_temperature_technik

Thank you, I give it a try this evening… The empty line between the sensors is ok?

Another short question: I’ve a customize.yaml with sensors. Is this format already the new one (in the customize.yaml)?

binary_sensor.tor_garage:
  friendly_name: Tor | Garage
  device_class: garage_door
  unique_id: STOG

Space is fine.

There have been no changes to customize.

Hi, after migrating all my sensor to the new format, I’m getting these error:

Invalid config for [template]: [icon_template] is an invalid option for [template]. Check: template->sensor->5->icon_template.

I guess it’s due to this: icon_template: mdi:water and it should be icon: mdi:water - right?

Yes, it’s not icon_template: it’sjust icon:. Apologies, I should have caught that.

Doesn’t matter, thank you anyway!

Another question, just for my understanding, regarding the state:
Sometimes there’s just a 'and sometimes " in one line, after state - is this the same, or do I have to pay attention to it?

And furthermore there’s state: > or state: >- but the {{...}} in another intended line.

You can use either double or single quotes outside your single line template, it does not matter - as long as whatever you use inside is the opposite type. e.g. both of these are valid:

state: "{{ state_attr('sensor.foo','bar') }}"
state: '{{ state_attr("sensor.foo","bar") }}'

Convention is to use double quotes outside and single quotes inside. However json data requires double quotes around keys so sometimes this is not possible.

Multi-line templates, indicated with >, or | should not have quotes outside the template:

state: >
  {{ state_attr('sensor.foo','bar') }}

The use of a dash after the multi-line character strips the last new line character from the data. It is rarely required as home assistant ignores it anyway. You can learn more about this by experimenting with the interactive demo here (scroll down to watch the light grey text at the end of the RESULT text as you play with the controls):

https://yaml-multiline.info/