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

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

Hey James,

could you please see my last post, I really need urgend help with that!

You might need to do some googling and reading to understand how HA works, this is a bit advanced.

Essentially you need to add the templates to your configuration.yaml and restart Homeassistant.

This will give you the energy entities you can add to your HA Dashboard and use to configure the Energy Dashboard. If you are unsure how to do this google it there are many examples.

Thanks a lot!

I got it so far, the only thing is why it did between 9-10 this strange thing. How could it be to export more as prduced? Even we started working and must have used 90-95% of the Produced Energy.

Thats the Script, just change the names.

sensor:

  • 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.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float) > 0 %}
    {{ states(‘sensor.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float }}
    {% else %}
    {{ 0 }}
    {% endif %}
    availability_template: “{{
    [ states(‘sensor.hausverbauch_channel_a_power’),
    states(‘sensor.hausverbauch_channel_c_power’),
    states(‘sensor.hausverbauch_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: >-
    {% if (states(‘sensor.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float) < 0 %}
    {{ (states(‘sensor.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float) * -1 }}
    {% else %}
    {{ 0 }}
    {% endif %}
    availability_template: “{{
    [ states(‘sensor.hausverbauch_channel_a_power’),
    states(‘sensor.hausverbauch_channel_c_power’),
    states(‘sensor.hausverbauch_channel_c_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.solar_power’)|float(0) - states(‘sensor.power_export’)|float(0)) < 0 %}
    {% elif (states(‘sensor.power_export’)|float(0)) > 0 and (states(‘sensor.solar_power’)|float(0) - states(‘sensor.power_export’)|float(0)) > 0 %}
    {{ (states(‘sensor.solar_power’)|float(0)) - states(‘sensor.power_export’)|float(0) }}
    {% else %}
    {{ states(‘sensor.power_import’)|float(0) + states(‘sensor.solar_power’)|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: 1
    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: 1
    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: 1
    method: left

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

Why are you adding this twice sensor.hausverbauch_channel_c_power ?
Is there no sensor.hausverbauch_channel_b_power?

If you only have two phases, just remove the middle duplicated entry.

Ah, got it, did a mistake while rename it.

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.hausverbauch_channel_a_power, sensor.hausverbauch_channel_b_power, sensor.hausverbauch_channel_c_power for the three phases

Solar generation in W is used to calculate consumption via sensor.solar_power

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

sensor:

  • 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.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_b_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float) > 0 %}
    {{ states(‘sensor.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_b_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float }}
    {% else %}
    {{ 0 }}
    {% endif %}
    availability_template: “{{
    [ states(‘sensor.hausverbauch_channel_a_power’),
    states(‘sensor.hausverbauch_channel_b_power’),
    states(‘sensor.hausverbauch_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: >-
    {% if (states(‘sensor.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_b_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float) < 0 %}
    {{ (states(‘sensor.hausverbauch_channel_a_power’)|float + states(‘sensor.hausverbauch_channel_b_power’)|float + states(‘sensor.hausverbauch_channel_c_power’)|float) * -1 }}
    {% else %}
    {{ 0 }}
    {% endif %}
    availability_template: “{{
    [ states(‘sensor.hausverbauch_channel_a_power’),
    states(‘sensor.hausverbauch_channel_b_power’),
    states(‘sensor.hausverbauch_channel_c_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.solar_power’)|float(0) - states(‘sensor.power_export’)|float(0)) < 0 %}
    {% elif (states(‘sensor.power_export’)|float(0)) > 0 and (states(‘sensor.solar_power’)|float(0) - states(‘sensor.power_export’)|float(0)) > 0 %}
    {{ (states(‘sensor.solar_power’)|float(0)) - states(‘sensor.power_export’)|float(0) }}
    {% else %}
    {{ states(‘sensor.power_import’)|float(0) + states(‘sensor.solar_power’)|float(0) }}
    {% endif %}

Hi,

what entities do i neet for the Energy meter in HA.

  • network consumption
  • back to the electricity grid

Looks better, you will need to restart Home Assistant for it to take effect.

Consumption and Returned to grid, Import and Export in my scripts, see pic in post of the config:

thx for that.

you say “You need to supply your own daily solar generation data from your inverter for Solar Production.”. I have a shely em1 for the Solar. How can i create the “daily” data for the Solar?
Do i need a new Sensor?

i have only entities of Power (W) ,Energy (kWh) and energy Returned (kWh)

edit:

i create a sensor like this:

power_solargen:
        friendly_name: "Power Solar Generation"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.pv_600_wp_channel_1_power')|float(0)) < 0 %}            
          {% else %}
            {{ 0 }}
          {% endif %}

   - platform: integration
    source: sensor.power_solargen
    name: energy_solargen_sum
    unit_prefix: k
    round: 1
    method: left


  energy_solargen_daily:
    source: sensor.energy_solargen_sum
    name: Energy solargen Daily
    cycle: daily

but it doesn’t work. No value at power solar generation.

on my shelly em 1. The Power Value is negative (W). Is that a Problem?

where is my mystake?

Thanks James, it is working (after the red Line), tested also Battery Charger :slight_smile:
Last Question I have is, if and how could it be possible to integrade a Powergauge combined with all Phases (Net), like on the second Picture (Haushalt Energie, which is read with a Pulsmeter but dosent count if it is negative)

This is probably what you are looking for:

   - platform: integration
    source: sensor.pv_600_wp_channel_1_power
    name: energy_solargen_sum
    unit_prefix: k
    round: 1
    method: left

  energy_solargen_daily:
    source: sensor.energy_solargen_sum
    name: Energy solargen Daily
    cycle: daily

Create a gauge and use sensor.power_import, that with give you the Net import of all the phases.

thx a lot.
Now it works perfekt.

The negative Power from the shelly em 1 is not a Problem? If yes,i can Turn over the power clamp.

edit:
the “energy_solargen_daily” is after 3 Hours still empty. 0 kWh.
"energy solargen sum is “-1,8kWh”.
could it be that it takes more time for something to appear here or have I forgotten something else?
No sensor needed right
?

edit2:

i add on the utility meter “net_consumption: true”. This works for me.

But this one doest give me a Value

So at leat it works if the House Consumption is positiv (Gauge was set to -500 and +5000) but if it’s not that easy, let’s forget it

more important would be what and where I need to add to the YAML for a second solar array.

Background is that I have a battery, because I charge via a plug S on L2.

However, I can not specify a second sensor to discharge.

Since I still have a plug left I would want to make the feed into the house network simply via another Shelly plug.

Solar 1 is sensor.solar_power (L3)
Solar 2 schould be sensor.solar_power2 on L2

is this possible?

If you are metering the mains with the Shelly 3EM, you already have all of net import and export(this will include all of the solar on both phases) with my templates.

I believe HA usually wants Solar positive, at least that how mine is from my inverters integration, not sure if works correctly if negative.