Keep track of solar overproduction

Hi I have two solar panels and a hoymiles DTU.
Now I want to find out if a battery makes sense.
My idea to do so is to keep track of my solar power overproduction (power I generated but did not use) over time and how much power I use from the grid because I produce no or too less solar power.

Basically I want a card on which I can see what is my overproduction in kWh over time (daily, weekly monthly, yearly, total) and the same for the grid usage.
I.e. in April I “wasted” 20 kWh and took 40kWh from the grid.

Sry if this is a very basic question but I was not able to do this on my own

ATM I track my powerusage with a set of smartmeters and some base usage (like the fridge that runs 24h):

template:
  - sensor:

      # 24h Base Power Consumption (Always 21.5W)
      - name: "24h Base Power Consumption"
        unique_id: 24h_base_power
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement
        state: 21.5  # Constant power usage

      # Lights Power Consumption (80W from 08:00 - 23:59)
      - name: "Lights Power Consumption"
        unique_id: lights_power_consumption
        unit_of_measurement: "W"
        device_class: power
        state_class: measurement
        state: >
          {% set hour = now().hour %}
          {% if 8 <= hour < 24 %}
            20
          {% else %}
            0
          {% endif %}
      - name: "Total Power Consumption"
        unit_of_measurement: "kW"
        device_class: power
        state_class: measurement
        state:  >
          {{ (
              states('sensor.24h_base_power_consumption')|float +
              states('sensor.lights_power_consumption')|float)
              / 1000 }}
      - name: "Total Power Consumption Combined"
        unit_of_measurement: "W"
        state: >
          {% set plugs = [
            states('sensor.unbenannt_p110_derzeitiger_verbrauch') | float(0),
            states('sensor.unbenannt_p110_derzeitiger_verbrauch_2') | float(0),
            states('sensor.unbenannt_p110_derzeitiger_verbrauch_3') | float(0),
            states('sensor.unbenannt_p110_derzeitiger_verbrauch_4') | float(0)
          ] %}
          {{ (plugs | sum) + states('sensor.total_power_consumption') | float(0) }}
      - name: "Solar Overproduction"
        unit_of_measurement: "W"
        state: >
          {% set consumption = states('sensor.total_power_consumption_combined') | float(0) %}
          {% set solar = states('sensor.wechselrichter_ac_leistung') | float(0) %}
          {{ [solar - consumption, 0] | max }}

      - name: "Grid Usage"
        unit_of_measurement: "W"
        state: >
          {% set consumption = states('sensor.total_power_consumption_combined') | float(0) %}
          {% set solar = states('sensor.wechselrichter_ac_leistung') | float(0) %}
          {{ [consumption - solar, 0] | max }}
      - name: "Solar Overproduction Hourly"
        unit_of_measurement: "kWh"
        state: >
          {% set stats = state_attr('sensor.solar_overproduction_energy', 'statistics') %}
          {{ stats['sum'] if stats else 0 }}
      - name: "Solar Overproduction Energy"
        unit_of_measurement: "kWh"
        state: >
          {{ (states('sensor.solar_overproduction_energy_wh') | float(0)) / 1000 }}

Ah and a OT question:
how to stretch a card over multiple columns?

Hello,

Answer to second question, if it is a section dashboard:
In the card editor, Layout tab, full width card.

Question nr 1 I am not sure to understand what do you want to achieve?
Do you want a cumulative result? If yes you can use integral helper maybe.

Hope it helps.

thanks.
I had a custom card and that had no layout tab but I was able to copy it from standard card.
this did the trick:

grid_options:
  columns: full

I created two integral helper and atm they show nothing but maybe they needs some time to gather data. I will expect a result tomorrow.

what I want:

  • the orange graph shows the overproductoin in watts at some time of the day (ie 600watts at 13 oclock)
  • I want the volume of the graph added up for a time range (ie week or day) and as watts per hour (ie 22.04.2025 1.5 kWh)

Hello,

For one day, or one week or any defined time you can use:

You have no feature to have dynamic update, so you can’t select a certa start date and end end date and get data.
This will keep increasing the total based on input sensor and resets to zero based on the reset period.

Hope it helps.