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

oh okey. So i greate a new sensor with positive Values.

Hi - so how i get this running ?

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

What should i change ? I dont get it :confused:
Evrything else works… okay the energy dashboard works also not 100% but yeah…
python is to complicated :sob:

Could u please tell me how u configure the Energy Dashboard ?

Add the templates to your configuration.yaml and configure the dashboard as per photos in post 9

1 Like

Okay - this is my configuration now… but the acutal consumption goes in the negative value…
i tested all constellations… but i have no luck …
Also the value doesnt match - it will be added what make no sense to me…

what´s wrong with my code :confused:

it doesnt make sense that the import + solar power are summed up… i dont get it.

The Problem exist only if i´m importing. if i´m exporting the value is correct…mmhpf

#Shelly3EM
  - platform: template
    sensors:
      # Template sensor for values of power import (active_power > 0)
      power_import:
        friendly_name: "Aktueller Import"
        unit_of_measurement: 'W'
        value_template: >-
           {{ max(0,states('sensor.shelly3em_channel_a_power')|float + states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float)}}
        availability_template: "{{
            [ states('sensor.shelly3em_channel_a_power'),
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power')
            ] | map('is_number') | min
          }}"

      # Template sensor for values of power export (active_power < 0)
      power_export:
        friendly_name: "Aktueller Export"
        unit_of_measurement: 'W'
        value_template: >-
           {{ min(0,states('sensor.shelly3em_channel_a_power')|float + states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float)|abs}}
        availability_template: "{{
            [ states('sensor.shelly3em_channel_a_power'),
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power')
            ] | map('is_number') | min
          }}"

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

Why power import and power solar are added ? this make no sense (see picture)
The entire Power consumption calculation doesnt match.

1

EDIT EDIT EDIT

So, i tested another change:

#Template sensor for values of power consumption
      power_consumption:
        friendly_name: "Aktueller Verbrauch"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.shellypv_power')|float(0) - states('sensor.power_export')|float(0)) < 0 %}
          {% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.shellypv_power')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
            {{ (states('sensor.shellypv_power')|float(0)) - states('sensor.power_export')|float(0) }}    
          {% else %}
            {{ max(0,states('sensor.shelly3em_channel_a_power')|float + states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float)}}
          {% endif %}

This looks good in Import Modus - its now too late to test it with export… i give feedback tomorrow…
I hope anyone can help me with this.

Consumption is total power your house is using, so if you are importing you are using all of the solar power + whatever you are importing, this looks correct to me.

Ah okay - yes if u say it so this make sense.
I assumed that it is the current consumption without solar. So the pure house consumption without calculating the yield.

Is it possible to add a template / sensor - which only shows me the pure house consumption or the self-consumption?

I’m still practicing and can’t really get any further :frowning:

Consumption without the solar is the import power, which you already have.
I’m not sure what you are wanting?

Hi James,

thanks for your script, that works for me better as my solution :slight_smile:
just a short question:
why you are using the utility meters for the energy dashboard?
Currently I added for grid consumption “sensor.power_import” and for Return “sensor.power_export”

Do i have to use the daily values or can it also yes with the import/export sensors?

Hi James, additional question to understand how the sensor power_consumption should work.
to explain my question better, lets have a look at these lines:

{% if (states('sensor.power_export')|float(0)) > 0 and (states('sensor.solar)|float(0) - states('sensor.power_export')|float(0)) < 0 %}
{% elif (states('sensor.power_export')|float(0)) > 0 and (states('sensor.solar')|float(0) - states('sensor.power_export')|float(0)) > 0 %}
            {{ (states('sensor.solar')|float(0)) - states('sensor.power_export')|float(0) }}    
{% else %}
            {{ states('sensor.power_import')|float(0) + states('sensor.solar')|float(0) }}
{% endif %}

The first If checks, if the export >0 AND Solar - Export<0. How can this check be true?
In my case that is always false, because the Solarvalues can only be positive (in my case from 0-600W).
The values from sensor.export can also only be positive, calulated via ShellyEM3.
So thererfore my Solar is part of the ShellyEM3 Monitoring it cannot be greater than the value of sensor.export.
So why is that first line implemented, I think there is something what I not note at the moment?

And second question:
if in my case the the first if always be not true (that means >0) which reaction in that loop will happen? The Solar - export value OR the Import + Solar value?

thanks for helping :slight_smile:

1 Like

Because the data for Solar Generation and Export are often provided by different sources on different update intervals(inverters and shelly), there can be times when the data is out of sync, say the clouds come over and reduce the solar quickly, this can produce large negative spikes.
The first if statement detects this and does not process this incorrect data and waits till the next update of the sensor values.

If that first if statement is not true it will process the rest and calculate depending on if you are importing or exporting at that time.

3 Likes

The Energy dashboard requires Energy(kWh) not power(W) as per the instructions and prompts:
“Grid consumption is the energy that flows from the energy grid to your home.
Consumed Energy (kWh)”

Sure, my mistake: I meant the Riemann sensors of export/import.
energy_import_sum for Consumption and
energy_export_sum for Return.

That is an incrementing counter that doesn’t reset, it does not show in the list of acceptable sensors.
I suspect that will cause issues.
Just click the upside down triangle on the energy dashboard configuration when you try add a Gird consumption, it shows you what is acceptable.

I’ve added at the template sensors the device_class “power”, so the Riemann integration sensors getting automaticly device_class “energy” :wink:
so it’s choosable in energy dahsboard.

1 Like

Not sure why you would go out of your way to configure it incorrectly.

is it possible to extend the script in such a way that I can see what I have saved on costs per day/month jan-dez? I would then have total consumption - calculate consumption right? * my kwh price … the result then in a variable January e.g

It is really outside of aim of the scripts, which is NET metering.

It’s not so easy to come up with a “calculate consumption” as the true savings are a also tied to how much solar you self-consume and export. The energy dashboard provides $ amounts for import, export and totals for daily/monthly/yearly. If you want more detailed analysis I suggest you send your data to pvoutput.org, it’s what I use for solar system payback etc.

Hi @uksa007,

I’ve watched the behaviour of the script the last couple days and it seems to be working - mostly.

but, sometimes there seems to be an error (in the script or in my mind):


legend:
violet: power_import
blue: power_export
turquoise: solar power

what fits for me is the timeframe 13:41 - 13:45:
power_import is high (>1300W), solar generates about 480W and therefor no power_export (0).

if I look at timeframe 14:08 - 14:18, power_import is also high (>2000W), solar generates about 560W and power_export is 300W.
That makes no sense to me.
what can I check regarding this behaviour? what can be wrong?

thanks for helping?

Check that you have included all of your shelly 3 phase sensors correctly in the power_import and power_export templates. (names in the templates you will need to change to your sensor names, sensor.l1.power, sensor.l2.power, sensor.l3.power)

Check the Shelly power sensors for each phase are reporting the correct values, you could have one of the current clamps installed backwards.