# Shelly 3EM 3-phases Energy sensor

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?

sorry my " stupid answer " : you just created template.yaml and put it into the config directory ?

For those who haven’t seen this before.
Shelly Pro 3EM
https://www.shelly.cloud/en-de/products/product-overview/pro-3-em

I use Riemann sums for the Engery provided by the template sensors that measure the power going in and out as reported by the Shelly 3EM.
However for the Engery produced by the Solar Panels I directly used the Value reported by the Energy Sensor of the Shelly 1PM that is measuring my inverter. This was the mistake. Somehow it seems the Energy Sensor of the 1PM flipped back to 0 and thus messed up all my monitoring and statistics in HA.
Advise: Use whatever you need (Riemann Sums, Utilty Meters whatever) to track the values in HA directly. Do not rely on the Shelly Devices to keep track of your Measurements forever.

I hope that makes it more clear… strickly speaking it does not belong in this thread here, as it is unrelated to the Shelly 3EM, but as you mentioned you observed wiered readings in the Energy Dashboard and I wittnessed something very similar I thought I share it here.

There is also an option to create an energy sensor with `state_class: total_increasing`. It ignores the reinitialization of value.

Thanks for the hint @maxym
Good Point!

@fridayAr
I think I got the same that you had today.
The Engery Dashboard is just a buggy piece of junk.
According to it my 350 VA UPS (listed as a Battery system in the Dashboard) consumed 12kWh between 13:00 and 14:00 today.
What a nonsense…
Even better:
I have two Shellys measuring what goes into the Battery (UPS and Battery Charger. Values get combined into “UPS Energy to Battery”) and I have one Shelly that measures what comes out of the battery (named "UPS Output Energy).
The difference is calculated in a sensor (named “UPS Energy Loss” and listed as Consumer in the Energy Dashboard.
That number did not explode to some rediculous 12kWh…
Furthermore the Power Consumption of the two input sensory remained normal the entire day.
And how would a Battery Charger with 160Watts max. plus a UPS with ~350Watts max consume 12kWh in 1 hour?
My own statistiks in terms of Power consumption does not show that spike.
Even the Engery Dashboards own logic is flawed…

~1 kWh from Solar
~10 kWh from the Grid
and then
~15kWh went to the Battery
??

So the only conclusion I can draw from this is:
The Values of the Shellys are rock solid. I should not have tried to fix some values in my Database on Christmas eve and kill my Database in the Process. Its just that the Engery Dashboard is buggy and thus useless and should be ignored / removed.

And just in Case someone believes its anything but the Dashboard:
Here is the growth of the “UPS Energy to Battery” Sensor that exploded by over 12kWh between 13:00 and 14:00 on the 12.01.23 according to the Dashboard:

Pretty interesting. I’ll also look into it. I’ll keep you updated if I find a solution.

I’ve noticed another problem. My 1.5kw inverter is linked to a sonoff pow r3(tasmota). I recently turned off the circuit breaker and when I turned it back on again 3 days later there was 0.7kWh instantly for that day. (dark winters )

for some reason i always get it mixed up somehow

i get all my sensor right with the shelly integration thats fine … but

this is the content of my template.yaml

``````- sensor:
- name: "HausEnergy"
unique_id: energy_total
state: >-
{{
[ states('sensor.shellyem3_349454756d1a_channel_a_energy'),
states('sensor.shellyem3_349454756d1a_channel_b_energy'),
states('sensor.shellyem3_349454756d1a_channel_c_energy'),
] | map('float') | sum
}}
availability: >-
{{
[ states('sensor.shellyem3_349454756d1a_channel_a_energy'),
states('sensor.shellyem3_349454756d1a_channel_b_energy'),
states('sensor.shellyem3_349454756d1a_channel_c_energy'),
] | map('is_number') | min
}}
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- name: "HausPower"
unique_id: power_total
state: >-
{{
[ states('sensor.shellyem3_349454756d1a_channel_a_power'),
states('sensor.shellyem3_349454756d1a_channel_b_power'),
states('sensor.shellyem3_349454756d1a_channel_c_power'),
] | map('float') | sum
}}
availability: >-
{{
[ states('sensor.shellyem3_349454756d1a_channel_a_power'),
states('sensor.shellyem3_349454756d1a_channel_b_power'),
states('sensor.shellyem3_349454756d1a_channel_c_power'),
] | map('is_number') | min
}}
unit_of_measurement: W
device_class: power
state_class: measurement
- name: "WaermepumpeEnergy"
unique_id: energy_wp
state: >-
{{
[ states('sensor.phase_1_energy'),
states('sensor.phase_2_energy'),
states('sensor.phase_3_energy'),
] | map('float') | sum
}}
availability: >-
{{
[ states('sensor.phase_1_energy'),
states('sensor.phase_2_energy'),
states('sensor.phase_3_energy'),
] | map('is_number') | min
}}
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- name: "WaermepumpePower"
unique_id: power_wp
state: >-
{{
[ states('sensor.phase_1_power'),
states('sensor.phase_2_power'),
states('sensor.phase_3_power'),
] | map('float') | sum
}}
availability: >-
{{
[ states('sensor.phase_1_power'),
states('sensor.phase_2_power'),
states('sensor.phase_3_power'),
] | map('is_number') | min
}}
unit_of_measurement: W
device_class: power
state_class: measurement
``````

so i expect there to be 4 sensors
sensor.power_total → HausPower
sensor.energy_total → HausEnergy
sensor.power_wp → WaermepumpePower
sensor.energy_wp → WaermepumpeEnergy
with there according names

but for some reason i get

BUT

any idea why?

Not a pro, but everything looks fine to me.

Sometimes one misses the easiest things do you have any other config in another file or did you forget to restart?