Help with my first template

I am new to HA and am trying to create my first template, summarizing current consumption of lit lamps. I am getting the following error:
"can not read a block mapping entry; a multiline key may not be an implicit key (30:20)

27 | + states(“sensor.shellyplus1pm_441793952b48_power” …
28 | + states(“sensor.shellyplus1pm_4417939324f0_power” …
29 | + states(“sensor.pub_belysning_bardisk_power”)|flo …
30 | unit_of_measurement: ‘W’
-------------------------^"

If I remove the space before ‘W’ I get the same error, but reffering to line 31 instead. Can anyone see what’s wrong?

# Summa förbrukning lampor
-platform: template
sensors:
power_total:
friendly_name: 'Summa förbrukning lampor'
value_template: ({{states("sensor.belysning_kok_channel_1_power")|float + states("sensor.belysning_kok_channel_2_power")|float
+ states("sensor.belysning_vardagsrum_channel_1_power")|float
+ states("sensor.belysning_vardagsrum_channel_2_power")|float
+ states("sensor.belysning_viggos_rum_power")|float
+ states("sensor.shellyswitch25_c45bbe778a5e_channel_1_power")|float
+ states("sensor.shellyswitch25_c45bbe778a5e_channel_2_power")|float
+ states("sensor.shellyplus1pm_44179393335c_power")|float
+ states("sensor.shellyplus1pm_44179394e6ec_power")|float
+ states("sensor.shellyplus1pm_30839809fcd4_power")|float
+ states("sensor.shellyplus1pm_a8032ab9d160_power")|float
+ states("sensor.shellyplus1pm_441793952b48_power")|float
+ states("sensor.shellyplus1pm_4417939324f0_power")|float
+ states("sensor.pub_belysning_bardisk_power")|float|round(1)}})
unit_of_measurement: 'W'

Look at the multi line string example and you should see what’s wrong :wink:

  1. Indentation is wrong.
  2. Single line template not in quotes.
  3. No default values for float filters.
  4. Your parentheses are in the wrong place - you are only rounding the last sensor state.
  5. Using legacy template platform - not really “wrong” just not recommended for new templates.

Using the new template integration it would look like this (in configuration.yaml, not sensors.yaml):

template:
  - sensor:
      - name: 'Summa förbrukning lampor'
        state: >
          {{ ( states("sensor.belysning_kok_channel_1_power")|float(0) 
            + states("sensor.belysning_kok_channel_2_power")|float(0)
            + states("sensor.belysning_vardagsrum_channel_1_power")|float(0)
            + states("sensor.belysning_vardagsrum_channel_2_power")|float(0)
            + states("sensor.belysning_viggos_rum_power")|float(0)
            + states("sensor.shellyswitch25_c45bbe778a5e_channel_1_power")|float(0)
            + states("sensor.shellyswitch25_c45bbe778a5e_channel_2_power")|float(0)
            + states("sensor.shellyplus1pm_44179393335c_power")|float(0)
            + states("sensor.shellyplus1pm_44179394e6ec_power")|float(0)
            + states("sensor.shellyplus1pm_30839809fcd4_power")|float(0)
            + states("sensor.shellyplus1pm_a8032ab9d160_power")|float(0)
            + states("sensor.shellyplus1pm_441793952b48_power")|float(0)
            + states("sensor.shellyplus1pm_4417939324f0_power")|float(0)
            + states("sensor.pub_belysning_bardisk_power")|float(0) )|round(1) }}
        availability: >
          {{ states("sensor.belysning_kok_channel_1_power")|is_number
            and states("sensor.belysning_kok_channel_2_power")|is_number
            and states("sensor.belysning_vardagsrum_channel_1_power")|is_number
            and states("sensor.belysning_vardagsrum_channel_2_power")|is_number
            and states("sensor.belysning_viggos_rum_power")|is_number
            and states("sensor.shellyswitch25_c45bbe778a5e_channel_1_power")|is_number
            and states("sensor.shellyswitch25_c45bbe778a5e_channel_2_power")|is_number
            and states("sensor.shellyplus1pm_44179393335c_power")|is_number
            and states("sensor.shellyplus1pm_44179394e6ec_power")|is_number
            and states("sensor.shellyplus1pm_30839809fcd4_power")|is_number
            and states("sensor.shellyplus1pm_a8032ab9d160_power")|is_number
            and states("sensor.shellyplus1pm_441793952b48_power")|is_number
            and states("sensor.shellyplus1pm_4417939324f0_power")|is_number
            and states("sensor.pub_belysning_bardisk_power")|is_number }}
        unit_of_measurement: 'W'
        device_class: power
        state_class: measurement # only if you want long term statistics for this sensor.

The availability template will prevent weird results if one or more of the sensors becomes unavailable.

Thanks. Sorry for the late reply. I have been struggling with HA since day one and are about to give it up all together.

I cannot use the code you provided since every restart I attempt results in HA not available. I have been reinstalling from backup at least one time per week and are getting fed up with the instability of HA on RPI. I have spent some more money on a NUC that I will try it with and hopefully i will become stable and let me use HA as intended.

What makes you think it is the pi and not a bad configuration?

Lots of people use a pi without problems.

Have you checked the logs?

Again, sorry or the late reply. For some reason, my PI wouldn’t let me restart. I had to reinstall from backup every time I tried.

Now, I have a VM install on win10 and I no longer have any issues restarting. The code above works, but only for two out of three sensors. I am mising something, I just don’t know what it is. :wink: