Configuration Error / Sensor not visible

Hello, I have a small problem here.

Till a few days back I only had a sensor for azimuth.

Now I got a Shelly 3EM and found a way to sum up the 3 power values, which works.
After that I had an error with my Azimuth Sensor.

Now I tried to make calculations with my solar power and the summed up values for power.
I can’t see the sensor “totale_energy” and for the Sun Azimuth I get error:

Logger: homeassistant.config
Source: config.py:820
First occurred: 11:33:03 (2 occurrences)
Last logged: 11:33:03

Invalid config for [template]: [sun_azimuth] is an invalid option for [template]. Check: template->sensor->0->sun_azimuth. (See /config/configuration.yaml, line 39).
Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['sensor'][0]['state']. Got None. (See /config/configuration.yaml, line 52).

This is the part of my configuration.yaml:

template:

    - sensor:
        sun_azimuth:
        friendly_name: "Sun Azimuth"
        unit_of_measurement: '°'
        value_template: "{{ state_attr('sun.sun', 'azimuth')-3|round(0) }}"
    
    - sensor:
        name: "energy_total_shelly"
        unit_of_measurement: W
        state: "{{ (states('sensor.shellyem3_349454716f85_channel_a_power')|float + states('sensor.shellyem3_349454716f85_channel_b_power')|float + states('sensor.shellyem3_349454716f85_channel_c_power')|float) }}"
        availability: "{{ states('sensor.shellyem3_349454716f85_channel_a_power')|is_number and states('sensor.shellyem3_349454716f85_channel_b_power')|is_number and     states('sensor.shellyem3_349454716f85_channel_c_power')|is_number }}"
        device_class: energy
        
    - sensor:
        name: "totale_energy"
        unit_of_measurement: W
        state: "{{ (states('sensor.energy_total_shelly')|float + states('sensor.shellyem_05b268_channel_1_power')|float }}"
        device_class: energy

Thank you very much!
Maybe someone has any idea.

Review the documentation for Template Sensor. It describes how to configure a Template Sensor using the new (modern) way and the old (legacy) way. You have mixed together a bit of both and that’s invalid.

The template: key is used for defining Template Sensors the new way but then the Sun Azimuth sensor you defined is in legacy format. However, even that is invalid because its indentation is incorrect.

The option names used by modern and legacy formats are not the same. For example, in legacy format it’s value_template whereas in modern format it’s state. You have used both of them to define sensors under the template: key and that’s invalid.

I recommend you use the new format.

template:
  - sensor:
      - name: "Sun Azimuth"
        unit_of_measurement: '°'
        state: "{{ (state_attr('sun.sun', 'azimuth')-3) | round(0) }}"

      - name: "energy_total_shelly"
        unit_of_measurement: W
        state: "{{ (states('sensor.shellyem3_349454716f85_channel_a_power')|float + states('sensor.shellyem3_349454716f85_channel_b_power')|float + states('sensor.shellyem3_349454716f85_channel_c_power')|float) }}"
        availability: "{{ states('sensor.shellyem3_349454716f85_channel_a_power')|is_number and states('sensor.shellyem3_349454716f85_channel_b_power')|is_number and     states('sensor.shellyem3_349454716f85_channel_c_power')|is_number }}"
        device_class: energy

      - name: "totale_energy"
        unit_of_measurement: W
        state: "{{ (states('sensor.energy_total_shelly')|float + states('sensor.shellyem_05b268_channel_1_power')|float }}"
        device_class: energy
1 Like