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

Long story short:
The Shelly 3EM is not working like a accumulation meter (only sum of all three phases is counted) with a power source. This is why we do these calculations here.

I noticed some difference between my “energy_import_daily” and the readings from my official meter (ferraris/induction meter). The Shelly is measuring 10-15% less kWh than the meter.
Is it because we only get a measurement every x seconds (sometimes every 5 secs, sometimes no update for 30 secs) and there is too much missing in between?

I’m using the official Shelly integration and I assume it’s using CoIoT for pushing values. Is using MQTT giving more steady values?

I wonder if this could be done on-device using “shelly script” to perform net metering and present new sensors. It may be more accurate particularly if there are periods where the connection is lost (bad wifi etc). I might look into it.

It’s been a while, but for the benefit of others who are experiencing the same issue: I think this happens when there has not been any exported power for a while. Then the power_export template sensor will keep outputting exactly 0, thus no new values will be recorded by HA (as it only records changing values), leading to problems with statistics/meters.

To work around this, I added the following to the sensor template:

  attributes:
    minute_counter: "{{ now().minute }}"

This will force the state to change at least once a minute.

See also here:

1 Like

Hello, I have been having the problem for days that the sensor ‘energy_export_daily’ can be seen with a value in the developer tools, but it cannot be added in the Energy Dashoboard because it does not appear there under ‘Return to Grid’.
Only ‘Energy Export Monthly’ is available.
How can I tackle a problem like this?

1 Like

Hi Guys, new to HA and net monitoring. We have recently installed a new solar system with a goodwe inverter that has native HA integration for solar generation. Currently on 3 phase mains with a 3 phase inverter connected through an inverter circuit breaker. Can i use the shelly 3em to achieve net monitoring or should i go for the Pro instead?

No need for the Pro if your wifi at your installation spot is good enough.

Hello all,

I am trying for a while to setup the part “returned to the grid” of the Energy dashboard, without success.

I bought and installed a Shelly Pro 3EM with 3 pieces of 120A Current Transformers.
The Pro 3EM was well installed on the Shelly App and in HA.

I have solar panels, pluged on the phase A of the electric installation ; when I produce, I have a negative value on phase A, and positives values on B and C, which is normal. But the sensor “Total active energy returned” seems to calculate all of my solar production, not only what is returned to the grid.
I guess this is a parameter issue ; and of course if I tried to add this sensor on the Energy board in the “Returned to the grid” part, this is not correct.

I tried to follow your tutorial

But I am unable to make it work, so there should be an error somewhere, here is my config :

In the sensor.yaml :

# Shelly 3EM templates for 3-phase Net Import, Export and Consumption(if you have solar generation details)
# This uses the shelly instantaneous power sensors to achieve the best possible accuracy. 
# Shelly Sensors are  sensor.l1_power, sensor.l2_power, sensor.l3_power for the three phases
# Solar generation in W is used to calculate consumption via sensor.power_solargen
# V1.0 Initial release by Uksa007
# V1.1 add float(0) to Consumption template to stop log warnings.
# V1.2 add Friendly names to Utility Meter sensors
# V1.3 remove negative spikes from power consumption due to different update timing of solar sensor
# V1.4 change round: 2 for small value users.

  - platform: template
    sensors:

      # Template sensor for values of power import (active_power > 0)
      power_import:
        friendly_name: "Power Import"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.shelly_pro_edf_tri_phase_a_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_b_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_c_active_power')|float) > 0 %}
            {{ states('sensor.shelly_pro_edf_tri_phase_a_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_b_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_c_active_power')|float }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{
            [ states('sensor.shelly_pro_edf_tri_phase_a_active_power'),
              states('sensor.shelly_pro_edf_tri_phase_b_active_power'),
              states('sensor.shelly_pro_edf_tri_phase_c_active_power')
            ] | map('is_number') | min
          }}"

      # Template sensor for values of power export (active_power < 0)
      power_export:
        friendly_name: "Power Export"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.shelly_pro_edf_tri_phase_a_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_b_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_c_active_power')|float) < 0 %}
            {{ (states('sensor.shelly_pro_edf_tri_phase_a_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_b_active_power')|float + states('sensor.shelly_pro_edf_tri_phase_c_active_power')|float) * -1 }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{
            [ states('sensor.shelly_pro_edf_tri_phase_a_active_power'),
              states('sensor.shelly_pro_edf_tri_phase_b_active_power'),
              states('sensor.shelly_pro_edf_tri_phase_c_active_power')
            ] | map('is_number') | min
          }}"

      # Template sensor for values of power consumption
      power_consumption:
        friendly_name: "Power Consumption"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.total_production_solaire')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
          {% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.total_production_solaire')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
            {{ (states('sensor.total_production_solaire')|float(0)) - states('sensor.power_export')|float(0) }}    
          {% else %}
            {{ states('sensor.power_import')|float(0) + states('sensor.total_production_solaire')|float(0) }}
          {% endif %}


  # Sensor for Riemann sum of energy import (W -> Wh)
  - platform: integration
    source: sensor.power_import
    name: energy_import_sum
    unit_prefix: k
    round: 2
    method: left

  # Sensor for Riemann sum of energy export (W -> Wh)
  - platform: integration
    source: sensor.power_export
    name: energy_export_sum
    unit_prefix: k
    round: 2
    method: left

  # Sensor for Riemann sum of energy consumption (W -> Wh)
  - platform: integration
    source: sensor.power_consumption
    name: energy_consumption_sum
    unit_prefix: k
    round: 2
    method: left

In configuration.yaml :

utility_meter:
  energy_import_daily:
    source: sensor.energy_import_sum
    name: Energy Import Daily
    cycle: daily
  energy_import_monthly:
    source: sensor.energy_import_sum
    name: Energy Import Monthly
    cycle: monthly
  energy_export_daily:
    source: sensor.energy_export_sum
    name: Energy Export Daily
    cycle: daily
  energy_export_monthly:
    source: sensor.energy_export_sum
    name: Energy Export Monthly
    cycle: monthly
  energy_consumption_daily:
    source: sensor.energy_consumption_sum
    name: Energy Consumption Daily
    cycle: daily
  energy_consumption_monthly:
    source: sensor.energy_consumption_sum
    name: Energy Consumption Monthly
    cycle: monthly

I am not able to add the sensor “active_power_export” in the Energy part as it is not in the list.
All the created sensors are not showing anything.
But when testing them in Development tools, the datas are correct :

I don’t know where I am wrong, so don’t hesitate to tell me if you see an error or something missing.
Don’t hesitate if you need more details.

Thanks in adavnce for your help !
Franck

my wifi is excellent

Has anyone got a Shelly 3em hooked up with a powerwall with solar?

We had one installed but due to the way the powerwall balances the house usage it causes the Shelly to only see around 200W in use.

Not sure if the gateway is using some magic to calculate the load.

Im noticing this same issue, also it seems to think the house used more of the solar and exported less. The next day when i check my supplier’s dashboard, it’s exported more. Did you get to the bottom of this? Im also using native shelly integration. I have a 3 phase meter with 3 phase inverter

@uksa007 what is the point of this if condition when there are no steps for it, it just moves to the elseif statement. am i missing something?

{% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.power_solargen')|float(0) - states('sensor.power_export')|float(0)) < 0 %}

It removes incorrect negative spikes in the data due to timing differences between when the data arrives from the different sensors, eg when the solar quickly reduces due to clouds.

1 Like

thanks for the clarification mate.

If Goodwe smartmeter (normally supplied together with inverter) is installed at the grid connection point, there is no need for Shelly device. You should have sensors to figure out net metering you are looking for.

Net Metering support supposedly coming on the Pro 3EM … Shelly support group (English Version) | Those of you who use Shelly Pro 3EM to monitor photovoltaics in net metering situation, how it has been for you | Facebook

(should already be here based on this dates in that post!)

Would be new to me. The cloud is able to but not the device itself. Still some helper needed for net metering.