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

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.

So ok now the sensors are working. I created the Utility Meter (image_1) and Riemann Sum (image_2). I attached two images to check with you if they are set correctly.

  1. Let me know it they are set correctly
  2. Just for my info…Can you describe me why we are creating these sensors and helpers?
  3. I’m ready for the next steps :slight_smile:

[image_1]

[image_2]

Not sure what you are doing the instruction are pretty clear in the first post:

Copy and paste the templates into your configuration.yaml, restart homeassistant
Configure the energy dashboard as per the photo in post 9 Energy dashboard config

You have to set the value for “kilo” in the second one. Apart from that it looks fine…
The first one I am not sure…my Italian is not particularly good, but I almost think you chose the wrong kind of helper…but I might be mistaken.

If you have that all set, then you should see the Sensors you created and be able to add them to the energy dashboard.

Edit: it looks like you chose “counter” for the first one, but it should be “consumption counter”. In my list it is the choice directly above “counter” but my UI is set to German…
Also…your should choose “Left Riemann” and jot the Trapezoidal thingy!
Also…you should give the Helpers a nice name…and you need to create one for Input and Output separately of course…:wink:

If only it was that easy. I did exactly what was suggested in the first post, but it didn’t work at all. Only after changing the syntax and creating the “helpers” via the UI did I manage to get it working in the energy dashboard…:man_shrugging: