How to make the sum of Channel A+B+C in Lovelace Mini Graph Card - Shelly 3EM

I want to make a graph in Lovelace of the sum of all 3 signals.

Current code:

type: custom:mini-graph-card
name: POWER
entities:
  - sensor.shelly_3em_channel_a_power
  - sensor.shelly_3em_channel_b_power
  - sensor.shelly_3em_channel_c_power
height: 300
line_width: 1
show:
  labels: true
  average: true
  extrema: true
hours_to_show: 2
points_per_hour: 60
panel: true
With panel: true

image

This is not possible in the mini-graph card. Either create a template sensor that sums your sensors and graph that or use the Apexchats card that does have this functionality.

1 Like

Thanks for your advice.

The solution:

With File Editor open the file configuration.yaml and write following code:

template:
  - sensor:
      - name: Energy_total
        unit_of_measurement: kWh 
        state: "{{ (states('sensor.shelly_3em_channel_a_power')|float + states('sensor.shelly_3em_channel_b_power')|float + states('sensor.shelly_3em_channel_c_power')|float) }}"
        device_class: energy

Save, and reboot.

Then search for sensor.energy_total, this is your summation of all 3 sensors.
The Code will be then for mini-graph card:

type: custom:mini-graph-card
name: POWER
entities:
  - sensor.shelly_3em_channel_a_power
  - sensor.shelly_3em_channel_b_power
  - sensor.shelly_3em_channel_c_power
  - sensor.energy_total
height: 300
line_width: 1
show:
  labels: true
  average: true
  extrema: true
hours_to_show: 2
points_per_hour: 600
panel: true
With panel: true

DONE

2 Likes

You may want to add an availability template to your total sensor so that it only reports values when all the sensors are available. Also you have to define default values for the float filters or the template sensor may fail during startup.

template:
  - sensor:
      - name: Energy_total
        unit_of_measurement: kWh 
        state: "{{ states('sensor.shelly_3em_channel_a_power')|float(0) + states('sensor.shelly_3em_channel_b_power')|float(0) + states('sensor.shelly_3em_channel_c_power')|float(0) }}"
        availability: >
          {{ states('sensor.shelly_3em_channel_a_power')|is_number and
             states('sensor.shelly_3em_channel_b_power')|is_number and
             states('sensor.shelly_3em_channel_c_power')|is_number }}
        device_class: energy
1 Like

Great. Thanks a lot! :slight_smile:

I made an error in the code.
It must be:

unit_of_measurement: W

NOT
kWh

I am trying to implement this as well (newbie), but have a few questions:

  1. shouldn’t the device class be “power”?
  2. It doesn’t work for me, value is 0W
template:
  - sensor:
      - name: power_total
        unit_of_measurement: W 
        state: "{{ states('sensor.shelly_3em_channel_a_power')|float(0) + states('sensor.shelly_3em_channel_b_power')|float(0) + states('sensor.shelly_3em_channel_c_power')|float(0) }}"
        availability: >
          {{ states('sensor.shelly_3em_channel_a_power')|is_number and
            states('sensor.shelly_3em_channel_b_power')|is_number and
            states('sensor.shelly_3em_channel_c_power')|is_number }}
        device_class: power

Thanks :slight_smile:

Hi Markus hope this helps:
This is my final setting that works:

configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml


template:
  - sensor:
      - name: energy_total
        unit_of_measurement: W
        state: "{{ (states('sensor.shelly_3em_channel_a_power')|float + states('sensor.shelly_3em_channel_b_power')|float + states('sensor.shelly_3em_channel_c_power')|float) }}"
        availability: "{{ states('sensor.shelly_3em_channel_a_power')|is_number and states('sensor.shelly_3em_channel_b_power')|is_number and     states('sensor.shelly_3em_channel_c_power')|is_number }}"
        device_class: energy

  - sensor:
      - name: energy_null
        unit_of_measurement: W
        state: "{{ 0 }}"
        device_class: energy

mini-graph-card

type: custom:mini-graph-card
name: Summe Leistung, 2h [W]
entities:
  - sensor.energy_total
  - sensor.energy_null
height: 300
line_width: 1
show:
  labels: true
  average: true
  extrema: true
hours_to_show: 2
points_per_hour: 60
panel: true
With panel: true

As Markus said, this is wrong:

It should be:

 device_class: power

Power is measured in W or kW.

Energy is measured in Wh, or kWh.

Same for this:

  - sensor:
      - name: energy_null
        unit_of_measurement: W
        state: "{{ 0 }}"
        device_class: energy