Why don't this give me a new sensor in entity

I put this in configuration.yaml, restart home assistant, but I don’t get a new sensor… What am I doing wrong?

-platform: template
sensor:
  elpris_inkl_allt:
    unit_of_measurement: SEK/kWh
    value_template: >
      {% set elpris_nordpool =
      states('sensor.nordpool_kwh_se3_3_10_025') | float(0) %} {{
      (elpris_nordpool + 0.7815 + 0.019)| round(2) }}

indentation errors: all starting from sensor is not indented properly

1 Like
'-platform': template
sensor:
  elpris_inkl_allt:
    unit_of_measurement: SEK/kWh
    value_template: >
      {% set elpris_nordpool = states('sensor.nordpool_kwh_se3_3_10_025') |
      float(0) %} {{ (elpris_nordpool + 0.7815 + 0.019)| round(2) }}

I put it into a YAML formatter and got this. Don’t know if it did fix anything?

No, quoting the platform made it worse, and there should be a space between the - and platform… Indentation determines wat is grouped, so match the indentation of the documentation examples exactly. I cannot test it right now, but it should look something like this:

- platform: template
    sensor:
      elpris_inkl_allt:
        unit_of_measurement: SEK/kWh
        value_template: >
          {% set elpris_nordpool = states('sensor.nordpool_kwh_se3_3_10_025') | float(0) %} 
          {{ (elpris_nordpool + 0.7815 + 0.019)| round(2) }}

But whare did you get this example from? I do not recognise the format. It seems like a mix of different things.

1 Like

I put it in a new file and got this:

bad indentation of a mapping entry (2:11)

1 | - platform: template
2 | sensor:
---------------^
3 | elpris_inkl_allt:
4 | unit_of_measurement: SEK/kWh

There seems to be more wrong, as I edited above it looks like a mix of different things. Where are you putting this? In the gui in a template helper, or in configuration.yaml, or in sensors.yaml, or in template.yaml?

In templates.yaml, it should look something like this:

- sensor:
    - name: "Elpris Inkl Allt"
      unique_id: sensor.elpris_inkl_allt
      unit_of_measurement: SEK/kWh
      state: >
        {% set elpris_nordpool = states('sensor.nordpool_kwh_se3_3_10_025') | float(0) %} 
        {{ (elpris_nordpool + 0.7815 + 0.019)| round(2) }}

I tried both in configuration and in sensors.

I’ll try that…

I edited the above to the new template format that should go in templates.yaml

I put it in a new file called el.yaml, in a new called template.
In configuration.yaml i added: template: !include_dir_merge_list el.yaml

But no new sensor… I am really bad at this! But I guess its only trail&error…

Again you are combining bits of the syntax that are not meant to be used that way. Name the file templates.yaml and put this in configuration.yaml:

template: !include templates.yaml

Check the configuration in the developer tools, and if it is not giving an error and not triggering new notifications in the tray, restart Home assistant. This is what should be in templates.yaml in your config directory:

- sensor:
    - name: "Elpris Inkl Allt"
      unique_id: sensor.elpris_inkl_allt
      unit_of_measurement: SEK/kWh
      state: >
        {% set elpris_nordpool = states('sensor.nordpool_kwh_se3_3_10_025') | float(0) %} 
        {{ (elpris_nordpool + 0.7815 + 0.019)| round(2) }}

Don’t change the indentation of any of the bits you put in.

Modern format template sensors use state: not value_template.

Ah, true. Changed it above.

1 Like

That did it! Now I got a sensor named sensor.elpris_inkl_allt

I hope it gets updated as it is i want now.
It gets the price for electricity from nordpool sensor, and that sensor works. Then it adds some taxes. I know only get 0,8, and that is whats calculated in the figures I put in. It has not added the Nordpool value yet but maybe that needs another hour to update…

anyway, many thanks for the help you provided!! :slight_smile:

1 Like

@Pliggen,
I am not sure what language you posted it; however, I do see a simple YAML error.
Try this (It will get you closer):

- platform: template
  sensor:
    elpris_inkl_allt:
      unit_of_measurement: SEK/kWh
      value_template: >
        {% set elpris_nordpool =
        states('sensor.nordpool_kwh_se3_3_10_025') | float(0) %} {{
        (elpris_nordpool + 0.7815 + 0.019)| round(2) }}

We’ve moved into modern format now: this is a correction to the original legacy format sensor.