Shelly 3EM 3-phase Net Metering templates for Import, export and consumption

There won’t be any import when you are exporting, so you will have to wait till the sun goes down and there is no export then you should see the Energy Import Daily increment.

Did you manage to add Energy Import Daily to the Energy dashboard config under grid consumption?

Please include a screen shot of the energy dashboard after the sun has set and there is import, it may take an 1-2hours for the energy dashboard to show the import.

i know but i dont get an energy sensor/entity/template in the energy dashboard, the import and export works fine in my UI, but cannot select them in the energy dashboard that is the problem HA energy dashboard wont recognize the sensor/enity/template.

in the pictures below are the only sensor/entity/template that are available



I can see the data in the UI no problem, just can’t select them in de energy dash

The sensors are there but not selectable in energy dashboard
( screenshot is from homeassistant Ui)

You need to search from them by typing Energy in the box in the Energy dashboard configuration.

If that fails remove all of the config, reboot HA, start again.
Copy and paste the scripts from the top of the thread, only modify the values for your shelly.

Thanks for being so helpfully, i guess i got a nice error in my fist couple of scripts.

Finally

Thanks, I’m glad we got it sorted in the end!

Thanks for the code! Everything works quite proper. I´m super new to HA and it´s the first time for me programming.

One remark, I´m not sure and till now where not able to double check and evaluate all results.

I´m using a small PV generator with approx. 600W max. This gen is suppling on channel B of my 3EM. So for example the generator is producing 3kWh the day, I´m using 500Wh direct on the same channel. That means as a result Shelly shows me returned energy of 2.5kWh on channel B. Is this considered in the code/calculation?

Thanks
Christian

The templates are designed to calculate Net Metering in 3-phase installations.
If you only have 1 phase you probably don’t need to use them.

Maybe I was not clear enough, I´m working with 3-phase of course. but my Solargen is only on L2 installed. That means my 1PM installed to the PV gen. is measuring for example 2kWh but the Shelly is counting only 1.5kWh as 0.5 where used direct in the house.

Self consumption of solar is not relevant for Net metering, but is used to calculate consumption.
Net metering is the sum of all the phases, so if you are using each phase:
100w+ -1500w(solargen)+200w= -1200w(- indicates export)

My Consumption sensors works out how much the house is using, taking into account the solar production.

Question… could shelly be faulty?
I have solarpanels and they are shared on all 3 phases(equally)
Have checked that it’s correctly installed… Seems import energy is quite ok but export is wierd.
I have checked from the energy company(or what you call it) what is shows there:
Import:
1 October: 22.78 kWh (real) 23.52 (shelly) 3%
2 October: 30.59 kWh (real) 30.05 (shelly) 2%
3 October: 25.69 kWh (real) 26.51 (shelly) 3%
4 October: 30.19 kWh (real) 30.76 (shelly) 2%
5 October: 37.33 kWh (real) 37.46 (shelly) 0%
Export:
1 October: 8.29 kWh (real) 9.01(shelly) 8%
2 October: 0.15 kWh (real) 0.71 (shelly) 130%
3 October: 0.79 kWh (real) 1.52(shelly) 63%
4 October: 0.25 kWh (real) 0.77 (shelly) 102%
5 October: 0 kWh (real) 0 (shelly) 0%

For me this does not look like around 1%…at least export values.
Or, is this something to do with the decimals? I use 2
Biggest thing is who does it show so different on export, but not on import.

The difference between net metering and adding up each phase independently could be the explanation.

By default Shelly 3EM treats each phase as an independent circuit for both power and energy counters.

Many power companies meter 3 phase services as net metering meaning if you are exporting on one phase and importing on another they cancel each other out (which is generally in the consumers favour). The Shelly power sensors in this case are correct but to calculate the net metering energy you need to do an intermediate calculation using the Riemann Sum integral integration to calculate net metering energy (kWh) from the instant power (kW), which are generally different to the Shelly energy sensors.

Have a look earlier in this thread for some examples.

I’m assuming you are using my templates to calculate net import/export?
I would say your issue may be because your export is so small.
Shelly maynot be very accurate when the overall current is very small, it is hard to be accurate reading small currents with the current clamp used in the shelly designed to read larger current.

Exactly, I use your template. :slight_smile:
I just started to think about the same thing, seems the bigger the value it is, the closer it is.

Perhaps a bit of both, when I round up the values and also the export is small now(because of time of the year and also worse weather) , unfortunate if this is the case. Was hoping that this would only show about the 1% difference.

I wonder, didn’t you wrote a request to shelly about the improvment? How they should calculate the export and import? Have you got some reply in that case for that?

Another thing, would a neutral clamp help? It’s optional…and seems it’s for leakage.
I can see in the shelly app that it “complains” about it:
“neutral current transformer missing or not calibrated”

They never answered and just closed my request, so I don’t think they care about it.
I’m not sure that a neutral clamp would help maybe contact Shelly and ask them.

Can you check if the Shelly webpage total at the top matches the sensor.power_export when you are exporting.

Hah… so much for that then. 3 EM is supposed to be a “pro” device, at least it looks like that on the webpage.

Sure perhaps I send them a question about it…let’s see if I get any answer :slight_smile:

Sure, will try to check that. Thanks, James! So, export should be the same as the total? I thought they it was calculated wrong? Anyways, haven’t had the time yet to check but I will.

Edit: James, did you mean export or import? Import it looks similar, Shelly show 4.8kW and in sensor.power_import it show 4 836,8 W
Export is 0 at the same time.

Yes as export is your problem

Export seems similar at least when I took the screenshot:
Perhaps not as exact as power_export.

Btw. I also wrote on shelly forum about this, but there I used the values from shelly instead of template that you shared.

Import

1 October: 22.78 kWh (real) 24 (shelly)
2 October: 30.59 kWh (real) 32.1 (shelly)
3 October: 25.69 kWh (real) 27.3 (shelly)
4 October: 30.19 kWh (real) 31.4 (shelly)
5 October: 37.33 kWh (real) 37.5 (shelly) almost correct…

And export(returned) is even worse

1 October: 8.29 kWh (real) 9.51 (shelly)
2 October: 0.15 kWh (real) 1.6 (shelly)
3 October: 0.79 kWh (real) 2.3 (shelly)
4 October: 0.25 kWh (real) 1.4 (shelly)
5 October: 0 kWh (real) 91.4 (shelly) ???

Return is even more wrong than daily export sensor. But probably because of the reason that you have mentioned there and here.

I must admit that I am a bit confused about all this…

The thing I don’t really understand is this:

If I split the Shelly results into “Positive” and “Negative” (taken from the overall consumption figuresin Watt) and sum them up over time, then that should give me accurate readings without having to add a solar input, right?
Solar input is something I add in the HA Energy Dashboard anyway, so that would be in there twice if I add it to the Shelly 3EM calculations? Or am I completely wrong???

Solar is not part of calculating the Net import and export, it is only used to calculate consumption (how much power the house used, which is a combination of solar and import)

Thanks! In that case it makes sense. I use the built-in function in the energy dashboard for that, so I don’t need to calculate it myself.

I tried getting the import/export templates working that that I found in Post 1 of this thread yesterday, but it doesn’t work for me so far. Probably made some mistakes somewhere…will go over it with a fine-toothed comb later today. I already added the “float(0)” that is required by the newer HA syntax, but there appears to be something more basic that isn’t working because the new sensors don’t show up as a choice in the energy dashboard at all for me right now.

Edit:
I got it working now…had to change a lot of stuff here and there and ended up doing the utility meter and riemann stuff from the UI…but now it seems to be working.
Will check accuracy against my PowerFox Poweropti now.

Here is my version…maybe it can be of use to someone here:

template:
  - sensor:        

  
      - name: "verbrauch_total"
        unit_of_measurement: "W"
        device_class: "power"
        state: >-
          {{ [ states('sensor.stromzahler_channel_a_power'), 
               states('sensor.stromzahler_channel_b_power'),
               states('sensor.stromzahler_channel_c_power')]
               | map('float') | sum | round(2) }}
 
               

  
    
  

     # Template sensor for values of power import (active_power > 0)
      
      - name: "Power_Import"
        unit_of_measurement: 'W'
        state: >-
          {% if (states('sensor.verbrauch_total'))|float(0) > 0 %}
            {{ states('sensor.verbrauch_total')|float(0) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
            [ states('sensor.verbrauch_total')
            ] | map('is_number') | min
          }}"

   
      # Template sensor for values of power export (active_power < 0)
      
      - name: "Power_Export"
        unit_of_measurement: 'W'
        state: >-
          {% if (states('sensor.verbrauch_total'))|float(0) < 0 %}
            {{ (states('sensor.verbrauch_total'))|float(0) * -1 }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
            [ states('sensor.verbrauch_total')
            ] | map('is_number') | min
          }}"