Shelly 3EM 3-phases Energy sensor

Yes, but adding these up does not give you the real energy returned to the grid as they are per phase, and the returned energy on phase B could be absorbed by consumers in phases A + C.

You donā€™t have a 3 phase system? Usually they are completely separated, each phase has itā€™s own load/consumers, and they have a pretty voltage difference, youā€™d see a big spark if you touch phase A to phase B/C

I do have a 3 phase system. But you canā€™t simply add up the Shelly 3EM returned value for each phase to come up with a valid total returned energy value to the grid.

@teropop

For what its worth and I hope it helps someone:

I figured that my HA is giving me unrealistic Values for Energy Returned to the Grid out of my PV.
After some thinking it became obvious whats going on.

The Shelly measures Energy for each Phase seperately and for Consumption and Return seperately.
My PV sits on Phase 1. If I produce more Power than what is consumed on Phase 1 the measured Power becomes negative and thus the Energy Returned Meter counts forward, despite the same Power being taken in again on the other Phases.
Electricity Meters (at least in Germany) are accumulating the Cost (ā€œsaldierendā€). That means if you put out 300 Watts on Phase 1 and take in 500 Watts on Phase 2 they only count 200 Watts.

How did I solve this in HA?
Well, I build a Sensor that sums up the Power from all three Phases:

- sensor:
    - name: "Netz Total Power"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      state: >
        {{ ([ states('sensor.l1_power'),
              states('sensor.l2_power'),
              states('sensor.l3_power') ]
              | map('float') | sum) | round(2) }}
      availability: >
        {{ not 'unavailable' in
           [ states('sensor.l1_power'),
             states('sensor.l2_power'),
             states('sensor.l3_power') ] }}

Then I split this into Power Consumed from the Grid and Power Returned to the Grid.
The one is 0 when Power goes out, the other is 0 when Power comes in.

# ---- Netz Total Power Returned ---- #
- sensor:
    - name: "Netz Total Power Returned"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      state: >
        {% if float(states('sensor.Netz_Total_Power')) < 0 %}
        {{ 0 - float(states('sensor.Netz_Total_Power'))}}
        {% else %}
        {{ 0 }}
        {% endif %}
      availability: >
        {{ not 'unavailable' in
           [ states('sensor.Netz_Total_Power') ] }}
# ---- Netz Total Power Returned ---- #

# ---- Netz Total Power Consumed ---- #
- sensor:
    - name: "Netz Total Power Consumed"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      state: >
        {% if float(states('sensor.Netz_Total_Power')) > 0 %}
        {{float(states('sensor.Netz_Total_Power'))}}
        {% else %}
        {{ 0 }}
        {% endif %}
      availability: >
        {{ not 'unavailable' in
           [ states('sensor.Netz_Total_Power') ] }}
# ---- Netz Total Power Consumed ---- #

And finally build a Helper with a Riemann-Sum for both of them, converting the Power into kW/h.

EDIT: As I learned today there is room for improvement on the availability checks.
It is more reliable to use something like

      availability: >
        {{ is_number(states('sensor.l1_power'))
        and is_number(states('sensor.l2_power'))
        and is_number(states('sensor.l3_power'))}}
7 Likes

Excellent solution.

Our smart meters in Australia work in the same fashion so a need for a workaround like this.

There have been a few proposals for Shelly to incorporate this measurement this measurement into their product, but no success so far.

1 Like

That solution by @uksa007 worked great for me.

Click me :slight_smile:

Guys, i had a smappee solar for measuring appliances and solar etcā€¦ but went dead :frowning:
maybe iā€™m gonna buy a shelly3 3-phaseā€¦

My smappee solar had 6 clamps, 3 for my solar and 3 for my electricity

This shelly3 em has only 3 clamps? how does it work? can it measure only electricity and not solar?

Normally you put a 3-clamp metering at the very beginning where energy could flow in both directions (consuming or serving) and it then simply counts up and down. You get the difference, which also could be any of both depending upon harvesting against consumption whats more.

Hmm, thatā€™s what I donā€™t understand, I have now 3 clamps at the beginning to measure consumptionā€¦
The other 3 clamps are at the beginning of my invertor to measure productionā€¦

Here is an illustrationā€¦

If I place only the Shelly at the beginning, how can it measure production??

Ask yourself what the clamps at the yellow and green dots will measure.
A clamp measures the flow of electrons. The number and their directions.

For the yellow ones itā€™s dead easy. For the green location it could be anything depending upon whatā€™s larger, the current consumption or the production.

If thereā€™s really not more intelligence in your setup the green ones would measure 0 if your consumption matches the actual production.

Yes, but the green clamps will never be able to read the total solar production, right? Thatā€™s why I also need to yellow onesā€¦
The green will just calculate at the moment how many is used from my solar when sun shines

Is it correct (from an electrical point of view) to sum the 3 fases? Is it that way that the Electric Utility charges the consumption^?

Correct. The green clamps to measure the sum of all in & out energy flows.

3kWh >> green clamp measures 3kWh >> house consumes ?kWh > yellow clamp measures -1kWh
you can calc your consumption by adding both clamp readings. 3kWh + - 1kWh = 2 kWh consumption

If your production is lower something like this could happen
1kWh > green clamp measures 1kWh > house consume ?kWh < yellow clamp measures 1kWh
consumption is again 1kWh + 1kWh = 2kWh

And yes if your unit which turns the solar DC into AC isnā€™t able to measure the production you need the yellow clamps Otherwise you only need the green ones.

1 Like

I love this solution and it worked like a charm until today.
Today I noticed an error with this and I just donā€™t know where i have the error:

I only produced 0.8kw but it tells me that I exported 3.5kw. the solar production value is correct.

Did I make a mistake with the Riemann sum?

# Sensor for Riemann sum of energy consumption (W -> Wh)
sensor:
  - platform: integration
    source: sensor.Netz_Total_Power_Consumed
    name: energy_imported
    unit_prefix: k
    round: 3
  - platform: integration
    source: sensor.Netz_Total_Power_returned
    name: energy_exported
    unit_prefix: k
    round: 3

Any ideas?

tbh I have no Idea.

My solution still works like a charm for me.
I created the Riemann Sum Sensors via the Helper UI and selected a left-sum as I have read somewhere those should be more preciseā€¦ however I never looked into it.

But if the Energy Export goes upā€¦ that would tell me something is wrong with the if-clauses in the sensors.
I mean its really just summing up your total measured power and then if its positive count it in the one value, if its negative count it in the other.

I have a doubt and wish an electric engineer could answer. Are you sure that total load is the sum of the 3 phases? The 3 phases arenā€™t differing in the phase, so is it correct to just simply sum them, without any compensation for the different wave?

Why if I put a single clamp on the 3 phase (1 clamp closing the 3 wires) I get totally wrong values?

Update on this one. This error only happened once and never happened again since then. Still donā€™t know what happened here.

on Christmas Eve I noticed that my values where through the roof as well.

Turned out the Shelly 1PM I use to measure my PV suddently reported bogus valuesā€¦ I gues the integers flipped or something. I could not get the numbers in HA fixed, not even with manipulating the Database directlyā€¦
So long story shortā€¦ I had to reset the entire database, lost all values from the last 3 months, and kinda started from scratch.
PRO TIP: Do not rely on your measurement devices to store the values for you. Use Riemann Sums, Utility meters and things like that to keep track of the values in HA.

So my Solution with Summing up the Power usage, splitting this into IN and OUT and calulating the Energy consumption from it saved me from having such dataloss for the values reported by the Shelly 3EM. But wellā€¦ that does not help if you end up discarding the entire Database gg

The power on a wire is defined by the instantaneous current and instantaneous Voltage. The current is measured with the external sensor, the voltage is measured with the additional contact at the Shelly. These values are digitized with a comparably high sampling rate (the voltage and current have a frequency of 50/60 Hz and are being sampled with >kHz). Things are easy to understand as long as voltage and current are in phase (ohmic load) and get more complicated when they differ.
In general, averaged values of apparent, reactive and active power are calculated and provided to you as the user (you do not get raw data), there are no phases in the averaged data any more. So, it is valid to just sum these values.
For the energy transferred over the wire, the instantaneous energy is calculated from the raw data and integrated (summed) over time, so that also measures quick changes.
However, if you put all 3 cables through a single sensor, you are adding the instantaneous currents (which are usually out of phase by ~120Ā°) and multiplying that with the instantaneous voltage of the phase that is connected to the corresponding contact of the Shelly. That can be completely different. Imaging a 3 phase motor connected to the cables, the summed current would be 0.

2 Likes

How did you identify that it was the shelly which reported the buggy data?

Werenā€™t you using Riemann Sums before in your solution?