Shelly 3EM 3-phases Energy sensor

Not a pro, but everything looks fine to me.

Sometimes one misses the easiest things do you have any other config in another file or did you forget to restart?

Hi!
My Shelly was installed yesterday. On the shelly webinterface all values are correct but I don’t receive any data in HA in the energy entity. Do you have any idea what I can have messed up?

Is the cloud still disabled? or did you perhaps re-enabled it?

Hi! Yes the Cloud is still disabled.

Dont sum up the Energy Values of the Shelly. It will allways give you false readings even if you deduct the return to the “Grid”(or whatever flows backwards through it) from it.
See my solution above on how to get reliable current Power and Energy measurements for further processing in HA.

Regarding your sensors it seems that the sensor.phase_1_power / sensor.phase_1_energy either simply do not exist or are not providing any number.
What name did you give to the sensors of the second Shelly 3EM that is measuring your heat pump?

@fridayAr I opened a new thread for the bogus values in the Dashboard:

I had another occurance today… so statisticaly I am at ~once per week
lets see what comes out of it…

As it seems to affect various different values this is definately not down to the Shelly 3EM and I would even go so far to say for the Shellies in general, as the numbers / “Dashboard” I calculate myself are rock solid and dont show these events.

@fridayAr

Here is how my code looks at the moment. The Riemann Sensors I created just via the UI… not sure where those are stored.

# ---- Netz Total Power ---- #
- sensor:
    - name: "Netz Total Power"
      unit_of_measurement: W
      device_class: power
      state_class: measurement
      state: >
        {{ (float(states('sensor.l1_power')) + float(states('sensor.l2_power')) + float(states('sensor.l3_power'))) | round(2) }}
      availability: >
        {{ is_number(states('sensor.l1_power')) and is_number(states('sensor.l2_power')) and is_number(states('sensor.l3_power'))}}
# ---- Netz Total Power ---- #

# ---- Netz Total Power Returned ---- #
- sensor:
    - name: "Netz Total Power Returned"
      unit_of_measurement: W
      device_class: power
      state_class: measurement
      state: >
        {% if float(states('sensor.Netz_Total_Power')) < 0 %}
        {{0 - float(states('sensor.Netz_Total_Power'))}}
        {% else %}
        {{ 0 }}
        {% endif %}
      availability: >
        {{ is_number(states('sensor.Netz_Total_Power')) }}
# ---- Netz Total Power Returned ---- #

# ---- Netz Total Power Consumed ---- #
- sensor:
    - name: "Netz Total Power Consumed"
      unit_of_measurement: W
      device_class: power
      state_class: measurement
      state: >
        {% if float(states('sensor.netz_total_power')) > 0 %}
        {{float(states('sensor.netz_total_power'))}}
        {% else %}
        {{ 0 }}
        {% endif %}
      availability: >
        {{ is_number(states('sensor.netz_total_power')) }}
# ---- Netz Total Power Consumed ---- #
1 Like

Hi,
today my PV has been activated and I am a little confused.

I have a three phase system in my house and have a three phase Inverter that expose a single entity with actual power produced and daily yeld.

Shelly 3EM is attached to all three phases and currently I have values going negatives when PV is producing (I cannot understand how my huawei inverter is managing phases but the technician told me that is automatic, giving power on the phase needing it).

I have build a template sensor with the sum of the three Shelly sensors (A+B+C) and I use it to split total energy to three different timing window because my provider is charging me with different prices during the day.

Currently I have an helper with total power from the three Shelly sensors (that could go negative when I am producing) and I use this as source for the Energy meter in my configuration yaml.

In Energy Dashboard I have added these Energy meters “from grid”, the three shelly “energy returned” “to grid”, and the “inverter daily yeld” for the PV section.

Is it correct?

I have some questions that can help me to use these sensors correctly (i am writing automation to charge my electric car only when there is a surplus of energy):

  • when the value of one or more of the three sensor is negative, is that the quantity of power “compensated” from PV?
  • is there any way in my configuration to have total house power consumption (currently I do A+B+C+PV)?

Thank you
Chris

I am having trouble doing this. I added the following template for my shelley em3

- sensor:
    - name: "Energy Total"
      unique_id: energy_total
      state: >-
        {{ states('sensor.phase_a_energy')|float + 
           states('sensor.phase_b_energy')|float + 
           states('sensor.phase_c_energy')|float }}
      unit_of_measurement: kWh
      device_class: energy
      state_class: measurement
      attributes:
        last_reset: "1970-01-01T00:00:00+00:00"
    - name: "Power Total"
      unique_id: power_total
      state: >-
        {{ (states('sensor.phase_a_power')|float + 
            states('sensor.phase_b_power')|float + 
            states('sensor.phase_c_power')|float) }}
      unit_of_measurement: W
      device_class: power
      state_class: measurement
    - name: "Power Factor Total"
      unique_id: power_factor_total
      state: >-
        {{ (((states('sensor.phase_a_power')|float) * (states('sensor.phase_a_power_factor')|float) +
              (states('sensor.phase_b_power')|float) * (states('sensor.phase_b_power_factor')|float) +
              (states('sensor.phase_c_power')|float) * (states('sensor.phase_c_power_factor')|float)) /
            (states('sensor.phase_a_power')|float + states('sensor.phase_b_power')|float + states('sensor.phase_c_power')|float))
            |int }}
      unit_of_measurement: "%"
      device_class: power_factor
      state_class: measurement

and I tried to add ‘total power’ to my config, but I get this:

I noticed that my TOTALE- channel B energe seems a little different than the Yaml file. Any way to get this working? I am running

Home Assistant 2023.3.5
Supervisor 2023.03.1
Frontend 20230309.1 - latest

Anything need to be changed on the YAML file?

Here are my error logs:

2023-03-17 23:55:56.125 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-03-17 23:56:05.300 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.energy_total (<class 'homeassistant.components.template.sensor.SensorTemplate'>) is using state class 'measurement' which is impossible considering device class ('energy') it is using; expected None or one of 'total_increasing', 'total'; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22
2023-03-17 23:56:15.856 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ states('sensor.phase_a_energy')|float + 
   states('sensor.phase_b_energy')|float + 
   states('sensor.phase_c_energy')|float }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1771, in forgiving_float_filter
    return float(value)
ValueError: could not convert string to float: 'unknown'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 458, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2007, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 2, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1774, in forgiving_float_filter
    raise_no_default("float", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1472, in raise_no_default
    raise ValueError(
ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ states('sensor.phase_a_energy')|float + 
   states('sensor.phase_b_energy')|float + 
   states('sensor.phase_c_energy')|float }}' but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 576, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 460, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ states('sensor.phase_a_energy')|float + 
   states('sensor.phase_b_energy')|float + 
   states('sensor.phase_c_energy')|float }}' but no default was specified
2023-03-17 23:56:15.871 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ states('sensor.phase_a_energy')|float + 
   states('sensor.phase_b_energy')|float + 
   states('sensor.phase_c_energy')|float }}' but no default was specified') while processing template 'Template("{{ states('sensor.phase_a_energy')|float + 
   states('sensor.phase_b_energy')|float + 
   states('sensor.phase_c_energy')|float }}")' for attribute '_attr_native_value' in entity 'sensor.energy_total'
2023-03-17 23:56:15.887 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{ (states('sensor.phase_a_power')|float + 
    states('sensor.phase_b_power')|float + 
    states('sensor.phase_c_power')|float) }}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1771, in forgiving_float_filter
    return float(value)
ValueError: could not convert string to float: 'unknown'

I also looked at my sensor values and they seem to use this:
sensor.totale_channel_a_energy etc.

I got it working, FYI the entities are wrong in the examples provided here. I just replaced with correct entities and it worked. Here is a beginning config that worked for me:

- sensor:
    - name: "Munn Total Power"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      state: >
        {{ ([ states('sensor.totale_channel_a_power'),
              states('sensor.totale_channel_b_power'),
              states('sensor.totale_channel_c_power') ]
              | map('float') | sum) | round(2) }}
      availability: >
        {{ not 'unavailable' in
           [ states('sensor.totale_channel_a_power'),
             states('sensor.totale_channel_b_power'),
             states('sensor.totale_channel_c_power') ] }}

Here is my final config: hopefully someone can tell if I am in error for simple Kwh/Total power.

- sensor:
    - name: "Munn Total Power"
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      state: >
        {{ ([ states('sensor.totale_channel_a_power'),
              states('sensor.totale_channel_b_power'),
              states('sensor.totale_channel_c_power') ]
              | map('float') | sum) | round(2) }}
      availability: >
        {{ not 'unavailable' in
           [ states('sensor.totale_channel_a_power'),
             states('sensor.totale_channel_b_power'),
             states('sensor.totale_channel_c_power') ] }}
- sensor:
    - name: "Munn Total Kwh"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      state: >
        {{ ([ states('sensor.totale_channel_a_energy'),
              states('sensor.totale_channel_b_energy'),
              states('sensor.totale_channel_c_energy') ]
              | map('float') | sum) | round(2) }}
      availability: >
        {{ not 'unavailable' in
           [ states('sensor.totale_channel_a_energy'),
             states('sensor.totale_channel_b_energy'),
             states('sensor.totale_channel_c_energy') ] }}

This has my total Kwh and Power. If the math is wrong, I would welcome help. At least they look right.

Hello, I have this and it works fine, sometimes it reports state_class: measurement warning but it has no effect on operation

[image]

- sensor:
    - name: "Sh Energy Total"
      unique_id: sh_energy_total
      state: >-
        {{ states('sensor.shellyfaza1_red_energy')|float + states('sensor.shellyfaza2_white_energy')|float + states('sensor.shellyfaza3_blue_energy')|float }}
      unit_of_measurement: kWh
      device_class: energy
      state_class: measurement
      attributes:
        last_reset: "1970-01-01T00:00:00+00:00"
    - name: "Sh Power Total"
      unique_id: sh_power_total
      state: >-
        {{ (states('sensor.shellyfaza1_red_power')|float + 
            states('sensor.shellyfaza2_white_power')|float + 
            states('sensor.shellyfaza3_blue_power')|float) }}
      unit_of_measurement: W
      device_class: power
      state_class: measurement
    - name: "Sh Power Factor Total"
      unique_id: sh_power_factor_total
      state: >-
        {{ (((states('sensor.shellyfaza1_red_power')|float) * (states('sensor.shellyfaza1_red_power_factor')|float) +
              (states('sensor.shellyfaza2_white_power')|float) * (states('sensor.shellyfaza2_white_power_factor')|float) +
              (states('sensor.shellyfaza3_blue_power')|float) * (states('sensor.shellyfaza3_blue_power_factor')|float)) /
            (states('sensor.shellyfaza1_red_power')|float + states('sensor.shellyfaza2_white_power')|float + states('sensor.shellyfaza3_blue_power')|float))
            |int }}
      unit_of_measurement: "%"
      device_class: power_factor
      state_class: measurement
    - name: "Sh Current Total"
      unique_id: sh_current_total
      state: >-
        {{ states('sensor.shellyfaza1_red_current')|float + states('sensor.shellyfaza2_white_current')|float + states('sensor.shellyfaza3_blue_current')|float }}
      unit_of_measurement: A
      device_class: current
      state_class: measurement
    - name: "Sh Energy Returned Total"
      unique_id: sh_energy_returned_total
      state: >-
        {{ states('sensor.shellyfaza1_red_energy_returned')|float + states('sensor.shellyfaza2_white_energy_returned')|float + states('sensor.shellyfaza3_blue_energy_returned')|float }}
      unit_of_measurement: kWh
      device_class: energy
      state_class: measurement
      attributes:
        last_reset: "1970-01-01T00:00:00+00:00"

Hi guys, I’m new HA user, I’m trying home Assistant and I’m still very new to it. I have a question for you, during the first installation (Raspberry 4 on an operating system installed on SD with the whale software) it offered me devices found on the net, including all the Shellys scattered around the house. All right, but I noticed that the Shelly 3Em (gen1) didn’t show the A and B calipers, but only the C. Why? They don’t even appear in the entities, and I’m only using the A. I tried deleting them all to reintegrate them, and now instead of looking for them, it asks me for the ip and inserts them one by one. The 3Em again with only one clamp, the C…


Where am I wrong? If you help me understand something I would be grateful :pray:

Do they apear in the WebConfig of the Shelly itself?

Hi all,

For the last 7 months my Shelly 3EM has been working fine.
However, I noticed an issue/errror yesterday. As you will see it thinks I’m returning energy. I don’t have solar PV and whilst I’d love a refund of £400 this is clearly an error.

Any idea what is causing this and any idea if I can retrospectively fix it as it’s making everything else look wrong.

Thanks!

I wonder if this correction could be done automagically by HA itself. I have the same “issue”. I dont tried the templates here but I also submitted a ticket. Id like a solution, not a workaround. Any new user will face the same issue, right?

Was there any statement from Allterco? I read that some users created tickets.

Hello Guys,

ineed your help, I can’t select the created sensor (total energy) in the energy dashboard. Does anyone have an idea?

template:
  - sensor:  
     - name: "Wärmepumpe Verbrauch aktuell" 
       unique_id: Wärmepumpe_Verbrauch_aktuell
       state: >-
            {{ states('sensor.shellyem3_485519d7a7b9_channel_a_energy')|float(0) +
               states('sensor.shellyem3_485519d7a7b9_channel_b_energy')|float(0) +
               states('sensor.shellyem3_485519d7a7b9_channel_c_energy')|float(0) }} 
       unit_of_measurement: kWh
       device_class: energy 
       state_class: total_increasing
     - name: Batterie_Umrechnung 

thank you

I included mine below as a comparison. The only thing that stands out is that you have Upper Case letters in the unique_id name, and I didn’t think those were allowed, or at least HA will convert those to lower case. And I’m not sure how the ä character is handled. Does the wärmepumpe_verbrauch_aktuell entity show up in HA and have a valid value? I also recall that it takes some time (about an hour) before it can collect enough data to generate the statistics for it to show in the Energy Dashboard.

(I’m only using 2 of the 3EM channels)

template:
  - sensor:
    - name: "Total Energy Used"
      availability: >
        {{ states('sensor.channel_1_energy') not in ['unavailable', 'unknown'] and
        states('sensor.channel_2_energy') not in ['unavailable', 'unknown'] }}  
      state: >-
        {% set state1 = states("sensor.channel_1_energy")|float(0) %}
        {% set state2 = states("sensor.channel_2_energy")|float(0) %}
        {% if is_number(state1) and is_number(state2) %}
        {{ ( state1|float(0) + state2|float(0)) | round(2) }}
        {% endif %}
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing

yes the name in unique id is the problem,.

thank you :slight_smile:

took me quite a while, but I ended up getting 3 helpers to define time of use. It’s been working solid for months now. here was my project Power management with CT clamp's 3P meter + PV Solar and TOU tarrif

2 Likes