Problem in summing up 2 sensors

I get this error:
Logger: homeassistant.config
Source: config.py:454
First occurred: March 22, 2022, 15:58:58 (4 occurrences)
Last logged: 11:30:41

Invalid config for [template]: [name] is an invalid option for [template]. Check: template->name. (See /config/configuration.yaml, line 8).

when I try to create a new sensor which would be the sum of 2 existing ones.

The aim is: I have 2 separate Solar panel installations, both report current output, and I can see them individually, use them in charts etc.
I also want to have a summed version of the 2, I found this code which should do it if I place it in the configuration.yaml. but I am getting above error.

Help appreciated :slightly_smiling_face:
Line 8 is the line with the text : template
Corrected the code block.
See already in the reply that identation is much more important than i realized, will try.


template:
    sensor:
    name: "Zon_Totaal"
    unit of measurement: 'KW'
    state: '{{states("sensor.inverter_omvormer") | float - states("sensor.envoy_122132021771_current_power_production")| float }}'

Could you please format your pasted code correctly. See point 11 here:

Review the example in the documentation for the Template Sensor integration. You probably didn’t indent the options correctly. It should look like this:

template:
  - sensor:
      - name: "Zon_Totaal"
        unit_of_measurement: "kW"
        state: '{{ states("sensor.inverter_omvormer") | float(0) - states("sensor.envoy_122132021771_current_power_production") | float(0) }}'
1 Like

@123 Thanks, indeed that solved it. I copy / pasted stuff on my macbook and there the indents where not that well visible. I took away dust from an old windows machine and got it more visible.
Now up to googling for a good MacOS editor which saves me from stupidity next time :frowning:

1 Like