Shelly 3EM 3-phases Energy sensor

Thank you for getting back to me!" This may have been an issue with my HA as I had to restore a backup … I’ve now managed to set the proper state_class and will be monitoring if everything will work OK :slight_smile:

1 Like

hello, I try to give my calculation a positive value with “abs”. everything seems fine, apart from the value being negative. Any Idea why?

      - name: "Haus"
        unique_id: total-auto
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: >-
          {{ (states('sensor.ebl_stromzahler_total_energy')|float - 
              states('sensor.shelly_shem_3_ecfabcc7ed90_1_total_consumption')|float - 
              states('sensor.shelly_shem_3_ecfabcc7ed90_2_total_consumption')|float - 
              states('sensor.shelly_shem_3_ecfabcc7ed90_3_total_consumption')|float) | abs }}
        attributes:
          last_reset: '1970-01-01T00:00:00+00:00'
        availability: >
          {{ not 'unavailable' in 
            [ states('sensor.ebl_stromzahler_total_energy'), 
              states('sensor.shelly_shem_3_ecfabcc7ed90_1_total_consumption'),
              states('sensor.shelly_shem_3_ecfabcc7ed90_2_total_consumption'),
              states('sensor.shelly_shem_3_ecfabcc7ed90_3_total_consumption') ] }} 

My sensors look like this, but as soon as I add
state_class: measurment to either the total sensor or power sensor I get configuration error. state_class: total:_increasing is not allowed says Visual Code…?
Any suggestions please.

# bergvärme total energy
    bv_total_energy:
      friendly_name: 'BV total energy'
      unique_id: '57831d02-53cb-497e-be9e-624b8d42230e'
      unit_of_measurement: kWh
      device_class: energy
      value_template: "{{(
        (
          states('sensor.bv_energy1') | float + 
          states('sensor.bv_energy2') | float + 
          states('sensor.bv_energy3') | float 
        ) | round(2)
      )}}"
      availability_template: >
        {{ states('sensor.bv_energy1') not in ['unknown', 'unavailable', 'none'] and 
          states('sensor.bv_energy2') not in ['unknown', 'unavailable', 'none'] and 
          states('sensor.bv_energy3') not in ['unknown', 'unavailable', 'none'] }}
# bergvärme total power
    bv_total_power:
      friendly_name: 'BV total power'
      unique_id: '36eedbec-c0f3-4920-88a7-003c0fb543b1'
      unit_of_measurement: W
      device_class: power
      value_template: "{{(
        (
          states('sensor.bv_power1') | float + 
          states('sensor.bv_power2') | float + 
          states('sensor.bv_power3') | float 
        ) | round(0)
      )}}"
      availability_template: >
        {{ states('sensor.bv_power1') not in ['unknown', 'unavailable', 'none'] and 
          states('sensor.bv_power2') not in ['unknown', 'unavailable', 'none'] and 
          states('sensor.bv_power3') not in ['unknown', 'unavailable', 'none'] }}
1 Like

total_increasing without the “:” you currently have written inside.

Ha ha, such a stupid mistake :grin:. But id didn’t help:

Invalid config for [sensor.template]: [state_class] is an invalid option for [sensor.template]. Check: sensor.template->sensors->bv_total_energy->state_class. (See ?, line ?).

I’ll put it in the customize.yaml instead.

The is_number approach to availability is pretty neat!

And thanks for others as well in this topic. I was quite stuck with the false readings and couldn’t find out what was the problem with my calculated sensor.

Anyways, my code is as follows now:

  - platform: template
    sensors:
      total_main_energy:
        friendly_name: 'Total Main Energy'
        device_class: energy
        unit_of_measurement: "kWh"
        entity_id:
          - sensor.phase_1_energy
          - sensor.phase_2_energy
          - sensor.phase_3_energy
        value_template: "{{ (states('sensor.phase_1_energy')|float +
                             states('sensor.phase_2_energy')|float +
                             states('sensor.phase_3_energy')|float )|round(3) }}"
        availability_template: >-
          {{
            is_number(states('sensor.phase_1_energy')) and
            is_number(states('sensor.phase_2_energy')) and
            is_number(states('sensor.phase_2_energy'))
          }}


  - platform: template
    sensors:
      total_main_energy_returned:
        friendly_name: 'Total Main Energy Returned'
        device_class: energy
        unit_of_measurement: "kWh"
        entity_id:
          - sensor.phase_1_energy_returned
          - sensor.phase_2_energy_returned
          - sensor.phase_3_energy_returned
        value_template: "{{ (states('sensor.phase_1_energy_returned')|float +
                             states('sensor.phase_2_energy_returned')|float +
                             states('sensor.phase_3_energy_returned')|float)|round(3) }}"
        availability_template: >-
          {{
            is_number(states('sensor.phase_1_energy_returned')) and
            is_number(states('sensor.phase_2_energy_returned')) and
            is_number(states('sensor.phase_2_energy_returned'))
          }}

But now I have a question, how to correct the data on my energy dashboard?

I would be ok if i can just delete those few “bad” days or at least the peaks.

3 Likes

I would like to know that as well, how to delete just a few bad days/readings.

What the benefit with the “is_number”?
My sensor looks like this:

    hd_total_energy:
      friendly_name: 'HD total energy'
      unique_id: '47962c0d-e871-465f-ab89-b3810d399416'
      unit_of_measurement: 'kWh'
      device_class: energy
      value_template: "{{(
        (
          states('sensor.hd_energy1') | float + 
          states('sensor.hd_energy2') | float + 
          states('sensor.hd_energy3') | float 
        ) | round(2)
      )}}"
      availability_template: >
        {{ states('sensor.hd_energy1') not in ['unknown', 'unavailable', 'none'] and 
          states('sensor.hd_energy2') not in ['unknown', 'unavailable', 'none'] and 
          states('sensor.hd_energy3') not in ['unknown', 'unavailable', 'none'] }}

I found a way to reset/delete faulty values with success! Have a look here.
https://community.home-assistant.io/t/energy-management-in-home-assistant/326854/455?u=thelordvader

Just shorter code, nothig else. “not in [‘unknown’, ‘unavailable’, ‘none’]” vs is_number

1 Like

I have a docker installation of HA, so need to find out how to install SQLite Web…

EDIT: It was pretty easy. Just add sqliteweb to docker compose yaml and voila.

  sqliteweb:
    image: tomdesinto/sqliteweb
    ports:
      - 8089:8080
    volumes:
    - ${USERDIR}/docker/homeassistant/home-assistant_v2.db:/db/home-assistant_v2.db
    command: home-assistant_v2.db    
1 Like

Thanks for the is_number recommendation!
I’ve updated the original post at the top of this thread to include it.
Here is how the sensor looks now (IMHO, quite clean):

template:
  - sensor:
      - name: "Energy Total"
        unique_id: energy_total
        state: >-
          {{ 
            [ states('sensor.phase_a_energy'), 
              states('sensor.phase_b_energy'),
              states('sensor.phase_c_energy'),
            ] | map('float') | sum
          }}
        availability: >-
          {{ 
            [ states('sensor.phase_a_energy'), 
              states('sensor.phase_b_energy'),
              states('sensor.phase_c_energy'),
            ] | map('is_number') | min
          }}
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing

(Note: the “min” filter returns False if one the elements in the list is False. If all elements are True, it returns True.)

3 Likes

Hi,
One quick doubt : If the Shelly 3EM allows to monitor 3 lines, I could buy and install 2 Shelly 3EM to monitor 6, and so on, right ?
I have the main line and 6 sub-lines I’d like to be able to monitor independently, that would mean 14 CTs to install, I’m not sure this module would be the best / most affordable way… But I am a newby in electricity monitoring so…

Thanks

Yes, you are correct.
I have currently 3 Shelly 3EM. They measure one heat pump, a two log houses independently. To measure the property’s total grid/import/export I use modbus via the my SolarEdge inverter and a meter connected that way.

1 Like

Ok so I guess I’d also need 3x 3EM for 9 circuits all in all (I have 1 phase at home). Main circuit from public network and 8 sub-circuits in house.
I would not know how to use the modbus but I guess I wouldn’t have to anyway as I would only be monitoring the circuits the simple way (one CT for each, 3 circuits on each 3EM, all of that going to HA and configuring HA to make sense of all the data).

Are there good tutorials on how to connect everything ? I’m no electrician but it does not seem so complicated (apart from knowing where to connect each cable on N, VA, VB, VC, I and O)

@amitfin You seem pretty familiar with the 3 phase version. Can you explain what it going on with mine?

Why is there ‘energy returned’? I have no solar or anything like that .
Why is power negative sometimes ?

Is my house wired wrong?

shelly 3phase

@ianadd, the wiring is probably wrong. My bet is that VA, VB, and VC are not synchronized with A, B, and C.
I’ve asked a question about 3EM wiring, and you can find in the comments the relevant explanation (here).

Thanks, I’ll try asking questions there.

A small amount of returned energy can be leaked, if you have (like me) a heat pump or something with an inverter connected to the Shelly 3EM. That’s inevitable. But in your case try to just turn the clamps the other way…?

If the clamps were the wrong way round then surely the reading would always be negative. But I can get negative and positive power values on the same channel depending on what I am using. Current and volts always show positive. The shelly app shows the same problem. The issue is not in HA.

@amitfin Having re-read your comment I am going to have to check if the wiring is mismatched between clamps and the device’s three supply lines.