Show or calculate self consumed solar energy or remove gauge

Here how I solved my problems, if someone fall in same trouble! And, if you find simple solution… share!

Because PVOutput.org integration don’t provide different ‘sensors’ for energy imported and exported, but only generated and consumed ‘instant power’ and ‘total energy’, I had to retrieve the required data as below.

A) Create 2 sensors, one for “instant power import”, another for “instant power export”. In templates.yaml define 2 sensors:

#The instant power consumed from grid'
- sensor:
    - name: 'power_from_grid'
      unit_of_measurement: 'W'
      state_class: measurement
      device_class: energy
      attributes:
       last_reset: '1970-01-01T00:00:00+00:00'
      state: >
          {% set generated = states('sensor.power_generated') | float (0) %}
          {% set consumed  = states('sensor.power_consumed') | float (0) %}
          {% set power_from_grid =  [0, consumed | int - generated | int ] | max  %}
          {{power_from_grid}}

#The instant power exported to grid
- sensor:
    - name: 'power_to_grid'
      unit_of_measurement: 'W'
      state_class: measurement
      device_class: energy
      attributes:
       last_reset: '1970-01-01T00:00:00+00:00'
      state: >
          {% set generated = states('sensor.power_generated') | float (0) %}
          {% set consumed  = states('sensor.power_consumed') | float (0) %}
          {% set power_to_grid =  [0, generated | int - consumed | int ] | max  %}
          {{power_to_grid}}

B) Then create 2 “HELPERS” , type “Integration – Riemann sum integral”, from the Input sensor defined above, for instance named “energy_from_grid” and “energy_to_grid”.

C) Because these helpers are incremental, we need to create 2 “Utility Meters” that reset starts from 0 every day:
In configuration.yaml add:

# Utility meters
utility_meter:
  daily_energy_from_grid:
    source: sensor.energy_from_grid
    name: Daily_import
    unique_id: 'energy_from_grid'
    cycle: daily      
  daily_energy_to_grid:
    source: sensor.energy_to_grid
    name: Daily_export
    unique_id: 'energy_to_grid'
    cycle: daily

D) Then use these 2 meters ( Daily_import / Daily_export) in Energy configuration.

immagine

5 Likes

Hi AndyIoT,

Thank you for posting this! I’ve copied it and tweaked it to make my setup make sense.

Note for others who follow the same path, the first two sensors needed to be changed to device_class power rather than energy. After that the device_class flowed correctly through to the Riemann Sum Integrations.

My setup has data coming from Iotawatt with CT for each circuit in my house (but no CT on the main supply). One circuit is the solar generation. I used your config to calculate the grid_export and grid_import values from the CT values.

Regards,

Jason

1 Like

Hi AndyIoT,

Thank you for your input.
I attempted to follow your example, but I seem to have not followed the instructions properly as I don’t see the integration into the graph nor can I get the gauge card to show a Daily figure as the error says Entity is non-numeric: sensor.daily_export.
This is my config entry.

#The instant power consumed from grid
template:
  - sensor:
    - name: 'power_from_grid'
      unit_of_measurement: 'W'
      state_class: measurement
      device_class: power
      attributes:
       last_reset: '1970-01-01T00:00:00+00:00'
      state: >
          {% set generated = states('sensor.power_generated') | float (0) %}
          {% set consumed  = states('sensor.power_consumed') | float (0) %}
          {% set power_from_grid =  [0, consumed | int - generated | int ] | max  %}
          {{power_from_grid}}
#The instant power exported to grid
  - sensor:
    - name: 'power_to_grid'
      unit_of_measurement: 'W'
      state_class: measurement
      device_class: power
      attributes:
       last_reset: '1970-01-01T00:00:00+00:00'
      state: >
          {% set generated = states('sensor.power_generated') | float (0) %}
          {% set consumed  = states('sensor.power_consumed') | float (0) %}
          {% set power_to_grid =  [0, generated | int - consumed | int ] | max  %}
          {{power_to_grid}}    

and this is the Utility Meters

# Utility meters
utility_meter:
  daily_energy_from_grid:
    source: sensor.energy_from_grid
    name: Daily_import
    unique_id: 'energy_from_grid'
    cycle: daily      
  daily_energy_to_grid:
    source: sensor.energy_to_grid
    name: Daily_export
    unique_id: 'energy_to_grid'
    cycle: daily

I have obiously done something daft, can you help me please

hello, I also could not make the integration appear in the graph, something to be done?

  - sensor:
    - name: 'power_to_grid'
      unit_of_measurement: 'kW'
      state_class: measurement
      device_class: energy
      attributes:
       last_reset: '1970-01-01T00:00:00+00:00'
      state: >
          {% set generated = states('sensor.solarh_12748_today_eq') | float (0) %}
          {% set consumed  = (states('sensor.pzem_004t_v3_r_energy') | float (0) /1000) + (states('sensor.pzem_004t_v3_s_energy') | float (0) /1000) %}
          {% set power_to_grid =  [0, generated | int - consumed | int ] | max  %}
          {{power_to_grid}}

utility_meter:
  daily_energy_to_grid:
    source: sensor.energy_to_grid
    name: Daily_export
    unique_id: 'energy_to_grid'
    cycle: daily

but appears in entities:

The same here, not sure what I have missed either

Did you get it working there? Are you Brazilian too?

I also use the Hoymilles integration and I’m using PZEM to measure, just like you. I spent two weeks breaking my head to complete this panel, I didn’t understand the logic, but in the end it worked!

If you want help, enter the “Home Assistant Brazil” telegram and I or other members can help you better.

Hi,

Please help
I have this code and not working well. Where is the problem? Need sensor to garafana and want the same data which is on energy dashboard self consumed solar energy hourly and dayli and monthly.

template:
  - sensor:
      - name: "elfogyasztott_energy"
        unit_of_measurement: "kWh"
        state: >-
          {% if states('sensor.inverter_total_yield') | float(0) - states('sensor.energy_produced_luxembourg') | float(0) > 0 %}
            {{(states ('sensor.inverter_total_yield') | float(0) - states('sensor.energy_produced_luxembourg') | float(0)) | round (3) }}
          {% else %}
            {{(states ('0.0') | float(0)) |round(3) }}
          {% endif %}   
        device_class: energy
        state_class: total_increasing

and have this utility meter setup:

utility_meter:
  elfogyasztott_energy_hourly:
    source: sensor.elfogyasztott_energy
    cycle: hourly
  elfogyasztott_energy_daily:
    source: sensor.elfogyasztott_energy
    cycle: daily
  elfogyasztott_energy_monthly:
    source: sensor.elfogyasztott_energy
    cycle: monthly  

When I restart HA get a huge data about 487kWh. After ‘calibrating’ the utility meter sensors it start from 0 but not calculat the real data. So something wrong soewhere.

[edit: typo]

Sorry to revive this old thread, but i also ran into the same issue. Actually i have 2 questions:

  • Assuming (heh) you are using DSMR Reader as your integration, which DSMR entities are you using for your delivery/production in the dashboard setup? Are those the 'low tariff usage/high tariff usage´ and 'low tariff returned/high tariff usage´ ones (which correspond to the actual meter readings, so since the ‘beginning of time’)
    I also tried to use the ‘Power usage total’ and 'Power return total (daily) ones, which are i think some calculated daily values (so low+high), but i see some slight differences there.

  • Second question is actually your original problem. I have an entity that actually gives me the yield of the solar panels (i have Envoy PVs from which i read the actual daily yield in kWh) but the ‘Self consumed’ gauge is staying on 0%. Any ideas?

See images below for my setup.

I had the same issue with my energy dashboard and self-consumed solar energy gauge. It can be frustrating not being able to see that data, especially when it’s so useful. In my experience, you’re right that a template sensor would be the way to go. You could create one to calculate the consumed solar energy, and then add it to your energy dashboard. However, I’m not sure about HA’s magic - it might be worth looking into that as well. As for removing the gauge without removing the solar panel graphic, that’s a bit trickier. Have you tried looking for an option to hide or disable the gauge? Sometimes there are options like that in dashboard settings. On a related note, I recently stumbled upon an article that answered all my questions about how solar farms work. It was really informative and helped me understand more about solar energy in general. Maybe it could help you too!

Anyone found a simpler solution to this problem? One that can be done by using the HA UI?
Tried the above but it isn’t working for me. I have SolarEdge PV and converter, with tarif 1 and tarif 2.
TIA

I totally get the struggle with missing solar energy data. I had a similar issue when I first set up my energy dashboard. What worked for me was creating a template sensor in Home Assistant. You can use the ‘sensor’ platform and set up a template that calculates the consumed solar energy. There are some good examples in the Home Assistant documentation to guide you through it.