Combined energy sensors not showing up

Fairly new to HA but not new to home monitoring, etc. I’ve had HA set up for a couple months and am slowly adding to it.

HA Core; Docker; Home Assistant 2022.9.7; Frontend 20220907.2

A couple weeks ago I purchased a Shelly EM to monitor my home power consumption. I am in the US and have split phase power. Got the Shelly installed, everything works just fine. HA is able to find it when I add the integration and after an hour or so I get both phases added to the energy dashboard.

This works… fine, but I don’t like my power consumption showing up as two entities. I decide that it’s time to learn to make a template sensor to combine the two power and energy readings and use that in the energy dashboard. It just isn’t working though. I can use the developer tools to write/test the template and it gives the right answers.

However, when I put it into my yaml files I get nothing. No errors/configuration tests ok but the sensors do not show up.

I’m sure this is a syntax problem somewhere but I have no idea.

configuration.yaml

# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
sensor: !include sensor.yaml

http:
 use_x_forwarded_for: true
 trusted_proxies:
   - <ip removed>
   - <ip removed>

# Air Quality Index
sensor:
  - platform: waqi
    token: <token removed>
    locations:
      - <location removed>

frontend:
  themes: !include_dir_merge_named themes

sensor.yaml

# Combined Shelly Power Sensors
- platform: template
  sensor:
    consumed_energy_total:
      friendly_name: 'Total Energy Consumed'
      device_class: energy
      state: "{{ states('sensor.marked_leg_energy') | float + states('sensor.plain_leg_energy') | float }}"
      unit_of_measurement: "kWh"
  sensor:
    consumed_power_total:
      friendly_name: 'Total Power Consumed'
      device_class: power
      state: "{{ states('sensor.marked_leg_power') | float + states('sensor.plain_leg_power') | float }}"
      unit_of_measurement: "W"

And just to confirm what the template tool is telling me:
Imgur

You are using the old way of making template sensors, but I would imagine it still works. There are several things you could improve but lets just get it working for now.

You have a duplicate key and should remove the sensor: line above consumed_power_total.
HA should be failing to restart and telling you there is an issue with that file right now.

You are correct, I was using the old method which I’ve since corrected. I’ve been told this would have worked for now but not at some point in the future. The larger problem was the duplicate sensor: entries. HA would start and run, no errors, just ignoring. Anyway, I’ve moved things into the main yaml file to simplify it for now and hopefully avoid future mistakes like that. I’ll post my yaml here in case anyone needs to see what I did.

# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#sensor: !include sensor.yaml

http:
 use_x_forwarded_for: true
 trusted_proxies:
   - <removed>
   - <removed>

# Air Quality Index
sensor:
  - platform: waqi
    token: <removed>
    locations:
      - <removed>

frontend:
  themes: !include_dir_merge_named themes

# Combined Shelly Power Sensors
template:
  - sensor:
    - name: 'Total Energy Consumed'
      unique_id: 'total_energy_consumed'
      device_class: energy
      state: "{{ states('sensor.marked_leg_energy') | float + states('sensor.plain_leg_energy') | float }}"
      unit_of_measurement: 'kWh'
    - name: 'Total Power Consumed'
      unique_id: 'total_power_consumed'
      device_class: power
      state: "{{ states('sensor.marked_leg_power') | float + states('sensor.plain_leg_power') | float }}"
      unit_of_measurement: 'W'

Glad you got it working mate.

Because your yaml is so simple at the beginning now is a good time to look into packages too.