Adding sensor with template

I am trying to measure tank level in a rain tank with a atom lite. Got the volt as a entity, the i am trying to calculate in configuration .yaml with this code
sensor:

sensor: 
  - platform: template
    sensors:
      tank_litres:
        value_template: >
          {% set voltage = states('sensor.tank_voltage') | float %}
          {{ ((voltage - 0.41) * 1800) | round(0) }}
      unit_of_measurement: l
      friendly_name: Volym tank

sensor.tank_voltage
is the entity name for the voltage
But i renders in many fault messages, can somebody give me some light on this matter.
THX AndersPreformatted text

YAML is dependent on proper indentation. What you posted can’t be evaluated for proper indentation because it’s unformatted.

Please correct the Template Sensor’s formatting by selecting it and clicking the </> icon in the forum’s editing menu.

Post the messages.

THx, hope i did it correctly, I am a rookie

Should be a string: Template - Home Assistant
So unit_of_measurement: "L"

Thanks,
now the error message says:

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: expected dictionary for dictionary value @ data[‘sensors’][‘friendly_name’]. Got ‘Volym tank’ expected dictionary for dictionary value @ data[‘sensors’][‘unit_of_measurement’]. Got ‘L’. (See ?, line ?).

sensor: 
  - platform: template
    sensors:
      tank_litres:
        value_template: >
          {% set voltage = states('sensor.tank_voltage') | float(0) %}
          {{ ((voltage - 0.41) * 1800) | round(0) }}
        unit_of_measurement: l
        friendly_name: Volym tank

Thank you so much
Worked perfectly!

1 Like