Shelly 3EM 3-phases Energy sensor

Thanks for your reply.
I am still waiting for some more sun to get a negative value in the consumption :wink:

My current code is as follows:

- sensor:
    - name: "Energy Total"
      unique_id: energy_total
      state: >-
        {{ states('sensor.phase_1_energy')|float(0) + 
           states('sensor.phase_2_energy')|float(0) +
           states('sensor.phase_3_energy')|float(0) }}
      unit_of_measurement: kWh
      device_class: energy
      state_class: total_increasing
      attributes:
        last_reset: "1970-01-01T00:00:00+00:00"
      availability: >
          {{ not 'unavailable' in 
             [ states('sensor.phase_1_energy'), 
               states('sensor.phase_2_energy'),
               states('sensor.phase_3_energy') ] }}
    - name: "Power Total"
      unique_id: power_total
      state: >-
        {{ (states('sensor.phase_1_power')|float(0) + 
            states('sensor.phase_2_power')|float(0) + 
            states('sensor.phase_3_power')|float(0) |round(1)) }}
      unit_of_measurement: W
      device_class: power
      state_class: measurement
      availability: >
          {{ not 'unavailable' in 
             [ states('sensor.phase_1_power'), 
               states('sensor.phase_2_power'),
               states('sensor.phase_3_power') ] }}
    - name: "Return Energy"
      unique_id: return_energy
      state: >-
          {{ 
             [ min(states('sensor.phase_1_energy')|float,0), 
               min(states('sensor.phase_2_energy')|float,0),
               min(states('sensor.phase_3_energy')|float,0),
             ] | map('float') | sum
          }}
      unit_of_measurement: kWh
      device_class: energy
      state_class: total_increasing
      attributes:
        last_reset: "1970-01-01T00:00:00+00:00"
      availability: >
          {{ not 'unavailable' in 
             [ states('sensor.phase_1_energy'), 
               states('sensor.phase_2_energy'),
               states('sensor.phase_3_energy') ] }}

All 3 phases are summed (Shelly 3M) and displayed as consumption in the Energy Dashboard.

The solar production is fed in via the Shelly Plug S.
Phase L2 return, on which the Shelly Plug S feeds in, I cannot use as “return to grid”, because this reads BEFORE the balancing electricity meter and the feed-in values are therefore incorrect.

Therefore I have to use the sensor “return_energy”. I’ll let you know if it works as soon as the sun shines a bit more again :slight_smile:

1 Like