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

I have compared with my Electricity provider smart meter data daily totals for usage and solar feedin, using the templates energy_import_daily and energy_export_daily.

It’s better than I expected, it’s about 1% different so that’s pretty good!, given there would also be Shelly measurement accuracy in play.

For your consideration I do the same with the min/ max function instead of the if statement, and the same for export using min/ abs.

      # Template sensor for values of power import (active_power > 0)
      power_import:
        friendly_name: "Power Import"
        unit_of_measurement: 'W'
        value_template: >-
           {{ max(0,states('sensor.shelly_channel_a_power')|float + states('sensor.shelly_channel_b_power')|float + states('sensor.shelly_channel_c_power')|float )}}

        availability_template: "{{
            [ states('sensor.shelly_channel_a_power'),
              states('sensor.shelly_channel_b_power'),
              states('sensor.shelly_channel_c_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: >-
           {{ min(0,states('sensor.shelly_channel_a_power')|float + states('sensor.shelly_channel_b_power')|float + states('sensor.shelly_channel_c_power')|float)|abs}}
        availability_template: "{{
            [ states('sensor.shelly_channel_a_power'),
              states('sensor.shelly_channel_b_power'),
              states('sensor.shelly_channel_c_power')
            ] | map('is_number') | min
          }}"
3 Likes

Hi,

My brain just works better with if statements and it can add flexibility if you need further conditions eg elif.

Is there any advantage of max and min over if?

Thanks.

I presume it is faster as it doesn’t have to lookup the same sensors multiple times. Also reduces errors when entering yaml as it is simpler/ shorter as you don’t need to duplicate sensors entries.

But as with most things there are many ways to achieve the same outcome.

1 Like

@Uksa007

Can you please share a screenshot of your the dashboard and sensor used?

Use Energy Import Daily for Grid Consumption and Energy Export Daily for Returned to grid.
You need to supply your own daily solar generation data from your inverter for Solar Production.

3 Likes

I also find Solcast works well to estimate solar production in Australia.

135556872-ff5b51ac-699e-4ea5-869c-f9b0d0c5b815

1 Like

Thanks, this was the missing info for me.

Hello everyone,

i’m having trouble with getting the integrations up and running.
I copied the above sensor: section into my sensors.yaml (which is referenced in configuration.yaml) and the utility_meter: section directly into my configuration.yaml. I also changed the shelly 3em entities according to my config, of course.

Now while i’m seeing all the new entities successfully created, the energy_*_sum integrations are not updated - even though the “Power *” templates are showing the correct values.

Is there something i did wrong/miss?

If they are showing up they should be updating, it can take an hour or so for them to start populating.

you were right (at least in part?)

As you can see in the screenshots, the import sensors work good (consumption doest too).
But the export ones is not moving.

Or am i still impatient and just have to wait longer? :slight_smile:
(I’m new to this)

Ok, so i waited for almost two days now :slight_smile:
It managed do update exactly 3 times

What can cause such delays? Anyone has a suggestion?

your production power is low and there is a rounding setting round: 1 to 1 digit ( == 0.1 kWh) you see steps when 0.1kWh was produced.

If you change to round: 2 you will see more updates.

My god - I feel so stupid now, that was it.
THANK YOU!

no worries, I also had to learn it the hard way :wink:

@uksa007 Thanks for your work!

I´ve implented this but i have 2 Solar Sensors. It seems that is will not work? could you please check my code? (i´m not good with coding…) :frowning:

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

Thanks for your help!

Looks ok, does it work as expected?
I also have two solar inverters and I have a template that adds the two together so I can see my total solar generation.

      # Template sensor for values of energy Solar generation (solar_power > 0)
      power_solargen:
        friendly_name: "Power Solar Generation"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.pv_power')|float(0) + states('sensor.pv_power_2')|float(0)) > 0 %}
            {{ (states('sensor.pv_power')|float(0) + states('sensor.pv_power_2')|float(0)) }}
          {% else %}
            {{ 0 }}
          {% endif %}
1 Like

solved paypal.me

it seems to be not work at the beginning, but this was because i´ve not exported eny energy.

In the end of a day i have 4 different stats.

offical power meter from house (10kw)
Shelly (11,3kw)
HomeAssitant (11,2)
Your Script (8,9kw)

So what should i trust? :slight_smile: I guess this is due to the update cycle of the values. guess nothing is accurate like the official power meter?

Is there any way for a step by step explanation on how to set this up?
Unfortunately I am not yet so fit in HA.

That would be very nice!

1 Like