Calculating actual return to grid

Hello all,

Since two weeks I have my home assistant up and running at my house (Running HA container v2021.12.10.) My current project is to measure our solar production, energy consumption and our return to grid.

I have a three-phase electrical installation with an older, analog, meter.
In order to measure energy usage and production I am using a Shelly EM and Shelly 3EM.
The EM is used to measure the solar production and the 3EM measures the three separate phases.
I have used the following energy setup.

For grid consumption I use two standard entities from the shelly 3EM (Meter channel A energy and Meter channel B energy). For the third phase Iā€™m using a custom sensor (since this is the phase where solar power is added and the standard Shelly value only delivers data per phase) For the return to grid, Iā€™m also using a custom sensor.
For the solar production Iā€™m using the standard energy returned entity from the Shelly EM.

The three custom sensors are constructed the following way:

  • Actual power phase C

    • In order to get the actual watts that are consumed on the phase where the solar energy is being added.
  • Actual consumption phase C

    • A corrected kWh sensor that cancels out the solar return to get the actual consumption on the phase where solar energy is being added.|
  • Actual return to grid

    • A sensor where I tried to record the actual return to grid.
      I used an If-statement to evaluate if we are in a return to grid scenario (solar power exceeds the power consumption of all power drawn by the three phases.
      If yes, then the states should record this excess.
      Else = 0.0
template:
  - sensor:
    - name: Actual power phase c
      state: >
        {{ (states ('sensor.meter_channel_c_power')|float(0) - states ('sensor.2_zonnemeter_channel_1_power')|float(0))|round(3) }}
      unit_of_measurement: "W"

  - sensor:
    - name: Actual consumption phase c
      state: >
        {{ (states ('sensor.meter_channel_c_energy')|float(0) - states ('sensor.2_zonnemeter_channel_1_energy')|float(0))|round(3) }}
      unit_of_measurement: "kWh"
      state_class: total
      device_class: energy

  - sensor:
    - name: Actual return to grid
      state: >
        {% if states("sensor.2_zonnemeter_channel_1_energy_returned")|float(0) + states("sensor.meter_channel_a_energy")|float(0) + states("sensor.meter_channel_b_energy")|float(0) + states("sensor.actual_power_phase_c")|float(0) < 0 %}
          {{(states ('sensor.2_zonnemeter_channel_1_energy_returned")|float(0) + states("sensor.meter_channel_a_energy")|float(0) + states("sensor.meter_channel_b_energy")|float(0) + states("sensor.actual_power_phase_c')|float(0))|round(3)}}
        {% else %}
          {{(states ('0.0')|float(0))|round(3) }}
        {% endif %}
      unit_of_measurement: "kWh"
      state_class: total
      device_class: energy

The code does not trigger a configuration error, however Iā€™m not getting any values in the ā€œActual return to gridā€. Yesterday we had sunny conditions and the Shelly app did mention some actual return to grid (phase a and b practically not consuming and phase c providing energy). However, it did not show up in the energy overview.

Does anyone see anything wrong in the sensor-code that was used?
(I did receive quite a few ā€œā€˜floatā€™ got invalid input ā€˜unknownā€™ when rendering templateā€- errors that I think got fixed by adding the ā€œ(0)ā€-argument.

Thank you in advance,
Kind regards

2 Likes

I have the exact same configuration and Iā€™m stuck as you. Any good news???

It appears the developers energy monitoring setups provide the needed inputs and therefore there is no issue for them. For my solar installation, simply putting energy measuring devices on available wires (as suggested) does not provide the needed ā€œReturn to Gridā€ information. My power company meter does provide this info but I have no way of extracting it. I suppose itā€™s may be possible to detect when my grid kwh begin to decrease ( excess solar power to grid) and do some math but wouldnā€™t is be far more practical to have an option for correct display with when this information isnā€™t readily available. Seem this is an issue for a number of users. Perhaps someone has long ago provide a solution but I havenā€™t run across it yet.

If using CircuitSetup system. Expandable-6-Channel-ESP32-Energy-Meter/6chan_energy_meter_house_solar_ha_kwh.yaml at 77519e8830a1b7e267dc4f9ac7628f99fa0e307a Ā· CircuitSetup/Expandable-6-Channel-ESP32-Energy-Meter Ā· GitHub

Unfortunately not yet :stuck_out_tongue:

potenza_ceduta:
        friendly_name: "Potenza Ceduta"
        unit_of_measurement: 'W'
        value_template: >
         {% if (states('sensor.power_shelly3em_total') | int - states('sensor.fotovoltaico_channel_1_power') | int) > 0 %}
           0
         {% else -%}
           {{ (states('sensor.power_shelly3em_total') | int - states('sensor.fotovoltaico_channel_1_power') | int) | abs }} 
         {% endif %}
        device_class: power 
		
		
		
		
potenza_prelevata:
        friendly_name: "Potenza Prelevata"
        unit_of_measurement: 'W'
        value_template: >
         {% if (states('sensor.power_shelly3em_total') | int - states('sensor.fotovoltaico_channel_1_power') | int) > 0 %}
          {{ (states('sensor.power_shelly3em_total') | int - states('sensor.fotovoltaico_channel_1_power') | int) }}
         {% else -%}
           0
         {% endif %}
        device_class: power