Energy Dashboard calculate "consumption - solar - return"

Hi,

Enmergy calculation of the three sensors

  • Grid Consumption - Shelly 3EM sensor
  • Production Solar Sensor Live, Daily & Total
  • Export ?? no Sensor available

Energy export is only when I produce more than I consume.
I’m still missing a sensor for the energy dashboard.
What is the best way to calculate this?

I currently have my solar sensor under “Production” & “Return”.
But that leaves the “Sefl-consumed” scale at 0% - logical in itself.
But I would like it to be 100% with this picture status, because I use the solar power myself.

Need help - thanks…

Hi,

I built a solution that should work.

If the “solar” value is greater than the consumption, the value is displayed in the “export” sensor.
If the value is smaller - the “export” sensor indicates a “0.0”.

Sensor config:

  - platform: template
    sensors:
      energy_shelly3em_total:
        unit_of_measurement: "kWh"
        value_template: "{{ states('sensor.shelly_a') | float | round (2) + states('sensor.sensor.shelly_b') | float | round (2) + states('sensor.sensor.shelly_c') | float | round (2)}}"
        device_class: energy
        
  - platform: template
    sensors:
      energy_export:
        unit_of_measurement: "kWh"
        value_template: >-
           {% if states('energy_shelly3em_total') | float(0) - states('sensor.energy_solar') | float(0) < 0 %}
              {{(states ('sensor.energy_solar') | float(0) - states('energy_shelly3em_total') | float(0)) | round (3) }}
           {% else %}
              {{(states ('0.0') | float(0)) |round(3) }}
           {% endif %}      
        device_class: energy

Maybe it is helpful for you…

2 Likes

hello, thanks for your suggestion, i can see the sensor, but it’s not shown on the combobox “return to grid” on the energy dashboard config.
i did something wrong? thank you,

Here is my current config - hope it helps.

sensor.yaml

#Shelly 3EM
  - platform: template
    sensors:
      energy_shelly3em_all:
        friendly_name: "Stromverbrauch"
        value_template: >
          {{ [ states('sensor.shelly3em_channel_a_energy'), 
               states('sensor.shelly3em_channel_b_energy'),
               states('sensor.shelly3em_channel_c_energy') ]
             | map('float') | sum }}
        availability_template: >-
          {{ 
            [ states('sensor.shelly3em_channel_a_energy'), 
              states('sensor.shelly3em_channel_b_energy'),
              states('sensor.shelly3em_channel_c_energy'),
            ] | map('is_number') | min
          }}
        unit_of_measurement: "kWh"
        device_class: energy
        
  - platform: template
    sensors:
      energy_export_all:
        friendly_name: "Grid_Export"
        value_template: >
          {{ [ states('sensor.shelly3em_channel_a_energy_returned'), 
               states('sensor.shelly3em_channel_b_energy_returned'),
               states('sensor.shelly3em_channel_c_energy_returned') ]
             | map('float') | sum }}
        availability_template: >-
          {{ 
            [ states('sensor.shelly3em_channel_a_energy_returned'), 
              states('sensor.shelly3em_channel_b_energy_returned'),
              states('sensor.shelly3em_channel_c_energy_returned'),
            ] | map('is_number') | min
          }}
        unit_of_measurement: "kWh"
        device_class: energy

  - platform: template
    sensors:
      power_3em_total:
        friendly_name: "WATT_Live"
        value_template: >
          {{ [ states('sensor.shelly3em_channel_a_power'), 
               states('sensor.shelly3em_channel_b_power'),
               states('sensor.shelly3em_channel_c_power') ]
             | map('float') | sum }}
        availability_template: >-
          {{ 
            [ states('sensor.shelly3em_channel_a_power'), 
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power'),
            ] | map('is_number') | min
          }}
        unit_of_measurement: "W"
        device_class: power

3 Likes