Shelly 3EM 3-phases Energy sensor

yes it works perfectly, but since the auto discovery changed from kwh to wh, i had to had the conversion.
the latest version looks like this

  - name: "House Energy kWh"
    unique_id: sensor.house_energy_kwh
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing
    state: >
      {% set val1 = ((states('sensor.shelly_3em_meter_total_0')|float(0))/1000)|round(2) %}
      {% set val2 = ((states('sensor.shelly_3em_meter_total_1')|float(0))/1000)|round(2) %}
      {% set val3 = ((states('sensor.shelly_3em_meter_total_2')|float(0))/1000)|round(2) %}
      {{ val1 | float(0) + val2 | float(0) + val3 | float(0) 
        if 
          is_number(val1) and 
          is_number(val2) and 
          is_number(val3)
        else 
          None
      }}
    availability: >- 
      {{ 
        is_number(states('sensor.shelly_3em_meter_total_0')) and 
        is_number(states('sensor.shelly_3em_meter_total_1')) and
        is_number(states('sensor.shelly_3em_meter_total_2'))
      }}

I just set kWh in shellies discovery settings and reset everything so shouldn’t be a problem. You wanted to preserve historical data? Thanks for help

nothing to do with historical data, i updated the script and the sensors changed from kwh to wh, so did that change. that’s all

2 Likes

I have the Shelly 3EM enroute at the moment and have been looking at how to implement it with my 3-phase and 2 x solar single phase inverters (on different phases), with NET metering.

I found the details of the CoIot, which I think the new Shelly native integration uses here:
https://shelly-api-docs.shelly.cloud/gen1/#shelly-3em-coiot

Wondering if it would be better to use the total energy counter, which I think is an inclining counter given:

“Note, that energy and returned_energy do not survive power cycle or reboot – this is how the value is implemented on other Shellies. Shelly 3EM features a persisted version which is not affected by power cycling or lack of connectivity. To get the persisted counters use total and total_returned .”

total, number, Total consumed energy, Wh
total_returned, number, Total returned energy, Wh

So for Net metering: (*concept yaml need to turn into sensor templates once assumptions are verified)

Import:
{if (total - total_returned) > 0}
  {{(total - total_returned)}}
{else } 
  {{0}}

Export:
{if (total - total_returned) < 0 }
  {{(total - total_returned) * -1}} 
{else} 
  {{0}}

Consumption:
{if  (total - total_returned) > 0}   #importing
   {{total + solargen - total_returned}} 
 {else}
   {{solargen - total_retured + total}}   # exporting

This assumes that total does not already have the solar(total_returned) removed, solargen is total solar generation from inverters not form Shelly 3em

if total and total_returned are inclining and don’t reset daily, might have to use a utility sensor template to create one for daily. monthly etc.

Can anyone confirm the following:?
If the total and total_returnred sensors are included as part of the default Shelly core integration?
If there are total and total_returnred sensors, are they incline counters that don’t reset?
How often are the sensors updated using the Shelly core integration?

Thanks.

i can export data for 2 mounth?
i want to calc how many money i need to get bill for example
9.10.2021 - 8.12.2021
how i can do it?

I agree that using the total & total_returned would simplify, they are currently not available via the core Shelly integration, but shouldn’t be too difficult to include with future revisions of the integration. First step is to raise an issue against the current integration and then work out how to access those sensors, as they are persistent across power cycles they are pretty important to include.

I have posted my working configuration for a net metering settlement period here:

That’s an big oversight that they are not in the core integration
I wonder why they didn’t include those, maybe because they are unique to the 3EM?

How often are the sensors updated using the Shelly core integration?

Thinking MQTT might be a better option, as I have read you can get the data every second, that would increase accuracy.

I am also going to see if we can get shelly to add these NET counters to the firmware so they are accurate: total_import, total_export
Have started a thread at shelly, if you could add support that would be great.

1 Like

There are two shelly integrations, so far I have only used the core integration which ships with HA.

There is also a custom component, installable via HACS, which looks like it exposes total & total_returned. But doesn’t cover the three phase net metering calculations.

They are both available via coIot, I’m guessing they should be trivital to add to the core plugin.
Just wondering if the Shelly core plugin is maintained by Home Assistant team or Shelly?

Any info on the update rate of the 3em sensors using the core plugin, I read that minimum is 15s using coIot and MQTT is 1s?

Update rate seems to be variable, I think it is event driven by the Shelly device when something changes.

I have seen updates every 15 seconds, but sun set was 2 hrs ago so there hasn’t been any energy returned from my PV.

Yea for Energy returned I would expect to stop once the sun goes down.

However the Energy sensors I would expect to update inline with Power sensors but they don’t seem to. That Energy update interval of 4+ minutes is never going to be accurate for Net metering calculations.

Is it always that slow?

I can see a number of incorrect connections in your pictures. For example, the ground fault circuit interrupter is incorrectly connected. Just as “schneemensch” says, the third clamp is also incorrectly mounted. Can you arrange a picture where you see the lower connections on the bottom line?

Hi there,

where can I integrate the skript from the first post?
I cannot find the template editor in the new design :smiley:

Hi, i think you must check again…and again.
I have also at first a mismatch clamp and power cable… you can measure it, on Shelly VA and the other side to cable with clamp A, is it ok, you measure zero Voltage.

2022.02 broke my energy integration :angry: I fixed it by changeing my template sensor from state_class: measurement to state_class: total_increasing
Didn’t find any information in breaking changes of ths release :pleading_face:

I wasn’t able to bring the energy integration back to work after the upgrade. I decided to restore a full backup. :frowning:
It started to work within seconds with the old version of HA

Even changing to “total_increasing” didn’t help.

  - sensor:
    - name: "Hausanschluss"
      unique_id: energy_total
      state: >-
        {{ states('sensor.shelly3em_hausanschluss_channel_a_energy')|float + 
           states('sensor.shelly3em_hausanschluss_channel_b_energy')|float + 
           states('sensor.shelly3em_hausanschluss_channel_c_energy')|float }}
      unit_of_measurement: kWh
      device_class: energy
      state_class: measurement
      attributes:
        last_reset: "1970-01-01T00:00:00+00:00"

My power sensor was not affected… :woozy_face:
Anyone else facing similiar problems?

I think that “total_increasing” is a better choice.
You might need to wait a few hours after making the change (the statistics engine has a built-in latency).
A good post which explains the difference between “total_increasing” and “measurement” can be found here. Based on this post, it seems that “measurement” is not an option anymore, but maybe “total” can be used in a combination with “last_reset” (but I didn’t test it as we use “total_increasing”.)
(BTW, we use the sensor as it’s defined at the top of this thread, here, and it’s working well with 2022.2.2.)

1 Like

:thinking:

  - sensor:

space,space

  - sensor:
      - name: "Hausanschluss"
        unique_id: energy_total
        state: >-
          {{ states('sensor.shelly3em_hausanschluss_channel_a_energy')|float + 
             states('sensor.shelly3em_hausanschluss_channel_b_energy')|float + 
             states('sensor.shelly3em_hausanschluss_channel_c_energy')|float }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: measurement
        attributes:
          last_reset: "1970-01-01T00:00:00+00:00"

I had no issue, but i used before 2020.9 and use state_class: total_increasing

Thank you very much for your advice.
Your sensor is working with 2022.2.3 without any problems.
I still have a lot to learn and read :slight_smile:

1 Like