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

So far the shelly seems to he measuring perfectly. Now the thing is…if I want to add it to my HA Energy Dashboard…

Do I add the “daily” helper or do I add the base input/output sensor? With my Poweropti, I had two sensors, “Bezug” and “Einspeisung” and the daily reset was essentially handled by HA in the Energy Dashboard.

Why would I need a daily-resetting counter for the shelly then?

And on a side note…to compare accuracy between the Poweropti (which reads the main energy meter directly) and the shelly, I created a special dashboard to compare the two.
To make it work, I created a “helper” for both the Shelly and the Poweropti with a daily reset so that I have a 1:1 comparison. Now, the Shelly is in sync with my energy meter, but the Poweropti is not updating correctly on this dashboard with the helper, but is working perfectly in the Energy Dashboard…:thinking:


Hi sensor.energy.import_daily is not available in the drop down menu of Grid Consuption


state_class: total_increasing
source: sensor.energy_import_sum
status: collecting
last_period: 0
meter_period: daily
cron pattern: 0 0 * * *
last_reset: 2022-10-17T17:48:09.050516+00:00
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: Energy Import Daily

It is available for me (though I had to create it from the UI to get it working) but I al bot sure I should use it. I added the “total” for now and will see if it works correctly with the Energy Dashboard

Have you restarted Home Assistant?
You can try removing and recreating the sensor.

The entities needs to be recorded, otherwise they will not appear

Also check {instance-host:8123}/developer-tools/statistics . For me it would not show up, because there was some wrong value. Clicking “Fix issue” resolved it for me.

1 Like

Hi, I do have Shelly3EM which I put to check solar production (exit from inverter), and I use the 3phase meter provided by the wallbox manufacturer (Prism cartender), below the general meter of the house.

The software sensor of the wallbox is not divided by phase (I just have one sensor instead of 3 I guess the wallbox does trhe math, which I called sensor.prism_power )

can someone help on how to change the code to adjust with single sensor?

Depends on how the prism_power operates, does it go negative for export and positive for import?
If so just remove the three shelly phases sensors L1, L2, L3 and replace with your sensor.

I did but the energy tab is not populating

this my code, dop you see anything wrong? Perhaps multiply -1 should be removed? When the power is imported the value of the sensor is positive, when exported is negative

  power_import:
    friendly_name: "Power Import"
    unit_of_measurement: 'W'
    value_template: >-
      {% if (states('sensor.prism_power_grid')|float) > 0 %}
        {{ (states('sensor.prism_power_grid')|float) * -1 }}
      {% else %}
        {{ 0 }}
      {% endif %}
    

  # 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.prism_power_grid')|float) < 0 %}
        {{ (states('sensor.prism_power_grid')|float) * -1 }}
      {% else %}
        {{ 0 }}
      {% endif %}

      # 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.potenza_fotovoltaico_em3')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
          {% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.potenza_fotovoltaico_em3')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
            {{ (states('sensor.potenza_fotovoltaico_em3')|float(0)) - states('sensor.power_export')|float(0) }}    
          {% else %}
            {{ states('sensor.power_import')|float(0) + states('sensor.potenza_fotovoltaico_em3')|float(0) }}
          {% endif %}

My Import templates does not have a *-1 you need to remove it.
Only the export template has *-1!

Sensors will not show up in the energy dashboard until they are recoding data correctly.

What I really miss in the Energy Dashboard is the ability to display (and track) the current solar output. Sure, it shows the current production for the day so far, but there is no option to show how many W/KW are being generated by the solar panels at any given time…

You mean power? Yes, I have another page showing exactly that

Guys that’s amazing. You should do an HACK plug-in to keep it up to date and available to everybody via an easy UI and configuration process. Keep in consideration please. Everybody with a three phase system has the same problem…As me in Italy.

I’m sure that this job is amazing. But is still too complex for me. Is there anyone who could help me with the implementation?
I have two 3EM shellys that measure the Wh taken from the grid and the Wh produced by my solar system. Both three-phase

You mean a separate Dashboard? Or a Sub-Page for the Energy Dashboard?
The first one is easy, the second…is impossible AFAIK?

What exactly are you struggling with? I am sure we can help you, but we need to know what the issue is first…:wink:

My system is three-phase so I installed two Shelly 3EM sensors:

  • one that measures the three phases of the grid meter (i.e. the Wh I take from the grid) [G]
  • one that measures the three production phases of the solar panels (to get the total Wh I produce I have to add up the three phases) [P]

Currently, my problem is to create the sum/difference logic to correctly display the data on the Energy Meter screen, which uses a different logic from my home electrical system.

The Shelly 3EM that measures how much I draw from the grid only ever has a positive flow. Through that wiring I do not return anything to the grid.

To calculate how much electricity I feed back into the grid [R] I should take do:
[G]-[P]=[R].

I translate into words:

  • My house consumes tot Wh [G], solar production is tot Wh [P], if [P] > [G] then I am self-sufficient and return the difference, if [P] < [G] means I do not produce when I consume and return nothing to the grid because I exhaust my own production.

So I need to implement this though into home assistant to get from Energy Meter UI good insights. Now it’s a mess

If you look at the first post in this thread you will find a pretty comprehensive guide. Unfortunately there are a few issues with the new HA syntax and thus it’s not quite a Copy and Paste job.

If you look at my #Post99 in this thread, you could copy it and simply replace the names to match what you have in your system. Since you have two Shelly 3EM you have to do it for both of course.

The “utility meter” configuration posted in the first post did not work for me, and the Riemann Sum didn’t either, bur I managed to get it working easily by going to Settings->Devices–>Helpers and creating the Riemann Sum Sensor and also the Utility Meter through that.
It’s a bit hard to describe it all in one go, so I suggest you do it step by step and then post again here whenever you get stuck.

The first step would be to combine the three “Power” Sensors from your Shelly 3EMs.
I only have one Shelly, and named it “Verbrauch-Total” which is “Total Consumption” and is very easy to do.
You simply combine the three Phases “Power” Sensor in Watt and get the current total energy Consumption of your home. This can go both positiv and negative and will be your most important value when using automations later on.
Do the same for the second 3EM which should then give you the current solar production in Watt and would always be negative. You will likely have to turn that around by using "*-1“ for the calculation, but I am not sure since I don’t use that.

So I combined the three Power sensors. I’m not able to see them…

template:
  - sensor:
      - name: "consumo_totale"
        unit_of_measurement: "W"
        device_class: "power"
        state: >-
          {{ [ states('sensor.shellyem3_e8db84d67e87_channel_a_power'), 
              states('sensor.shellyem3_e8db84d67e87_channel_b_power'),
              states('sensor.shellyem3_e8db84d67e87_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.consumo_totale'))|float(0) > 0 %}
            {{ states('sensor.consumo_totale')|float(0) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
          [ states('sensor.consumo_totale')
          ] | 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.consumo_totale'))|float(0) < 0 %}
            {{ (states('sensor.consumo_totale'))|float(0) * -1 }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
          [ states('sensor.consumo_totale')
          ] | map('is_number') | min
          }}"



  - sensor:
      - name: "produzione_totale"
        unit_of_measurement: "W"
        device_class: "power"
        state: >-
          {{ [ states('ssensor.fase_a_current'), 
              states('sensor.fase_2_current'),
              states('sensor.fase_3_current')]
              | 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.produzione_totale'))|float(0) > 0 %}
            {{ states('sensor.produzione_totale')|float(0) }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
          [ states('sensor.produzione_totale')
          ] | 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.produzione_totale'))|float(0) < 0 %}
            {{ (states('sensor.produzione_totale'))|float(0) * -1 }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability: "{{
          [ states('sensor.produzione_totale')
          ] | map('is_number') | min
          }}"'

First of all…copy and paste the yaml text from your configuration.yaml to the Dev Options → Template and see if they the Template tester gives you valid data. Also check if you get any errors or warnings.

Once you have done that, go to Settings->Devices->Helpers and then create the Utility meter (Day and Month) and the Riemann Sum thingy for Returned and Received energy.