Error creating a sensor

I want to create this sensor

  - platform: template
    sensors:
    costo_energia_total:
    friendly_name: "Costo Energia Total"
    value_template: "{{ ( states('sensor.llave_termica_energia_total')|float * (80)|float  ) | round(2)  }}"

But when doing the verification it gives me this error

Invalid config for 'template' from integration 'sensor' at sensors.yaml, line 2: expected dictionary for dictionary value 'sensors', got None
Invalid config for 'template' from integration 'sensor' at sensors.yaml, line 3: 'costo_energia_total' is an invalid option for 'sensor.template', check: costo_energia_total
Invalid config for 'template' from integration 'sensor' at sensors.yaml, line 4: 'friendly_name' is an invalid option for 'sensor.template', check: friendly_name
Invalid config for 'template' from integration 'sensor' at sensors.yaml, line 5: 'value_template' is an invalid option for 'sensor.template', check: value_template

what am I doing wrong? Thanks in advance!

  - platform: template
    sensors:
     costo_energia_total:
       friendly_name: 'Costo Energia Total'
       value_template: 
1 Like

And you should be using the new template integration for new sensors. The legacy platform, while still being supported for the foreseeable future, will not be getting new features.

configuration,yaml (not sensors.yaml)

template
  - sensor:
      - name: "Costo Energia Total"
        unit_of_measurement: "€"
        device_class: monetary
        state_class: measurement
        state: "{{ ( states('sensor.llave_termica_energia_total')|float * 80  ) | round(2)  }}"
        availability: "{{ has_value('sensor.llave_termica_energia_total') }}"

FYI there is no need to apply float filters to numbers, as you did here: * (80)|float. The float filter converts strings to floating point numbers. You already had a number.

2 Likes

thanks very much!

1 Like