Shelly Pro 3EM no Energy Entity

Man you’re amazing! Thank you.

So, if I understand this correctly the new Pro Version still does not have a native net metering available?
We still need to use the “old solutiion” with Riemann sum to get correct readings for overall power from and to grid?

What are the advantages of the Pro Version then, besides LAN support? Accuracy might have been improved (which is not quite clear from the data), but when using it together with solar we will lose accuracy again by integrating manually of not perfectly-in-sync power data, right?

The entity “total_active_energy” in kWh I can get from Shelly Pro 3EM with Firmware 0.14.0 and with Homeassistant 2023.3.1. It works well in the Energy dashboard.

What I am missing in Homeassistant is the total power in W, the sum of the three phases. I only can get the values for the single phases.

For total power I created a template that added the 2 phases together. I’m only using 2 phases (USA), so I used the 3rd coupler on one leg of the 220v feed to my hot water heater and used a template to multiply it by 2 to get the actual power used by the water heater. In the Energy Dashboard my costs are wrong because it adds the hot water electric usage to the total for the 2 phases of the main house, but I just disregard that.

template:
  - sensor:
    - name: "Total Energy Used"
      state: >-
        {% set state1 = states("sensor.channel_1_energy") %}
        {% set state2 = states("sensor.channel_2_energy") %}
        {% if is_number(state1) and is_number(state2) %}
          {{ ( state1|float + state2|float ) | round(2) }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      

    - name: "Live Power (Watts)"
      state: >-
        {% set state1 = states("sensor.channel_1_power") %}
        {% set state2 = states("sensor.channel_2_power") %}
        {% if is_number(state1) and is_number(state2) %}
          {{ ( state1|float + state2|float ) | round(2) }}
        {% endif %}
      unit_of_measurement: "W"
      state_class: total
      
    - name: "Hot Water Live Power (Watts)"
      state: >-
        {% set state1 = states("sensor.channel_3_power") %}
        {% if is_number(state1) %}
          {{ ( state1|float) * 2 | round(2) }}
        {% endif %}
      unit_of_measurement: "W"
      state_class: total
      
    - name: "Hot Water Energy Usage"
      state: >-
        {% set state3 = states("sensor.channel_3_energy") %}
        {% if is_number(state3) %}
          {{ ( state3|float) * 2 | round(2) }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
1 Like

Thank you.
This works. I checked and the calculated values for total power are matching to the one of the Shelly web interface.

- sensor:   
  - name: "Live Power (Watts)"
    state: >-
      {% set state1 = states("sensor.shellypro3em_phase_a_active_power") %}
      {% set state2 = states("sensor.shellypro3em_phase_b_active_power") %}
      {% set state3 = states("sensor.shellypro3em_phase_c_active_power") %}
      {% if is_number(state1) and is_number(state2) and is_number(state3) %}
        {{ ( state1|float + state2|float + state3|float) | round(2) }}
      {% endif %}
    unit_of_measurement: "W"
    state_class: total
1 Like

I was too fast. The calculation above gives me the sum of electrical power of the three phases in W. This is what I wanted. The entities for the three phases gives me the possibility use the statistic graphs (see attachment). This I cannot do with the calculated entity.

Any idea what to do to use statistics for the calculated total power?

I hadn’t used it before, but I’m able to add the “Live Power (Watts)” to a Statistics Graph Card. Because it’s a statistic, could it just need some time to accumulate before you can use it in a graph?

I thought so too because I tested just after creating the calculated value. But it is not.
When I take the values for the single phases from Shelly, I can select MIN, MAX and Mean. This also is displayed in the diagram. But when I take the calculated value for total I only have a single value to choose.

It looks like you need to create a statistics sensor in configuration.yaml pointing to the original sensor.
https://www.home-assistant.io/integrations/statistics/

I found two solutions by myself quickly. I only took one more day to test before posting an answer:

(1) state_class
The three entities from Shelly integration are state class “measurement”. Your calculation is using state class “total”. I changed the calculation formula to “measurement” and all is fine

state_class: measurement

(2) Helper
Home Assistant provides helper to generate calculations that are not too complex. Using a helper to generate the sum out of the three entities from Shelly integration also provides the expected result.

To summarize different entities this is what I am unsing for the Shelly 3EM (not the 3EM Pro) but should work on the 3EM Pro too I guess:

template:
  - sensor:
    # Shelly3EM01 sensors:
    - name: "Shelly3EM01: Total energy"
      unique_id: shelly3em01_energy_total
      state: >-
          {{ 
            [ states('sensor.shelly3em01_channel_a_energy'), 
              states('sensor.shelly3em01_channel_b_energy'),
              states('sensor.shelly3em01_channel_c_energy'),
            ] | map('float') | sum
          }}
      unit_of_measurement: kWh
      device_class: energy
      state_class: total_increasing
      attributes:
        last_reset: "1970-01-01T00:00:00+00:00"
      availability: >-
          {{ 
            [ states('sensor.shelly3em01_channel_a_energy'), 
              states('sensor.shelly3em01_channel_b_energy'),
              states('sensor.shelly3em01_channel_c_energy'),
            ] | map('is_number') | min
          }}
    - name: "Shelly3EM01: Total power"
      unique_id: shelly3em01_power_total
      state: >-
          {{ 
            [ states('sensor.shelly3em01_channel_a_power'), 
              states('sensor.shelly3em01_channel_b_power'),
              states('sensor.shelly3em01_channel_c_power'),
            ] | map('float') | sum
          }}
      unit_of_measurement: W
      device_class: power
      state_class: measurement
      availability: >-
          {{ 
            [ states('sensor.shelly3em01_channel_a_power'), 
              states('sensor.shelly3em01_channel_b_power'),
              states('sensor.shelly3em01_channel_c_power'),
            ] | map('is_number') | min
          }}
    - name: "Shelly3EM01: Total current"
      unique_id: shelly3em01_current_total
      state: >-
          {{ 
            [ states('sensor.shelly3em01_channel_a_current'), 
              states('sensor.shelly3em01_channel_b_current'),
              states('sensor.shelly3em01_channel_c_current'),
            ] | map('float') | sum
          }}
      unit_of_measurement: A
      device_class: current
      state_class: measurement
      availability: >-
          {{ 
            [ states('sensor.shelly3em01_channel_a_current'), 
              states('sensor.shelly3em01_channel_b_current'),
              states('sensor.shelly3em01_channel_c_current'),
            ] | map('is_number') | min
          }}
    # Shelly3EM02 sensors:
    - name: "Shelly3EM02: Total power"
      unique_id: shelly3em02_power_total
      state: >-
          {{ 
            [ states('sensor.shelly3em02_channel_a_power'), 
              states('sensor.shelly3em02_channel_b_power'),
              states('sensor.shelly3em02_channel_c_power'),
            ] | map('float') | sum
          }}
      unit_of_measurement: W
      device_class: power
      state_class: measurement
      availability: >-
          {{ 
            [ states('sensor.shelly3em02_channel_a_power'), 
              states('sensor.shelly3em02_channel_b_power'),
              states('sensor.shelly3em02_channel_c_power'),
            ] | map('is_number') | max
          }}
1 Like

I’m looking at getting the EM3 Pro. Can it see both house consumption and solar at the same time?

I’m with an energy wholesale and sometime I have to curtail my inverters based on the house consumption.

Hi. I have mainly used the graphical tools but i understand i need to use code to do all stuff i want.
I understand the code itself, but…
Where shall i paste it and with what tool?

To create a statistic sensor? You can do that using the GUI interface:

Settings - Helpers - + Create Helper - Statistics.