Energy Management in Home Assistant

Under ‘Configuration’ → ‘General’ you will find a setting for currency. The default is EUR


Hi, I have published a new project that might be a nice complement to this Energy management dashboards. It is a project that I created using an optimization technique to maximize auto-consumption with PV+battery+hass. The topic can be found here:

With the github of the project here:

1 Like

As it’s recommended to use a energy sensor providing a “total_increasing” state, I integrated my solar-panels using Integration - Riemann sum integral - Home Assistant - so far so good.

But: My solar inverter delivers a daily value in 0.1 kWh increments / steps during the day, that is then retest on the next morning (starting again from 0). Between the actual inverter value and the integrated value there is a difference of around 0.3 kWh to 0.5 kWh per day …

Question: is there an easy way to have a “daily reset sensor” configured as an “total_increasing sensor”? If I use the “daily reset sensor”, there is a huge spike each morning (due to the reset on the following day)


I found it a little tricky as a template sensor is required so that all the required attributes can be set but the template sensor will be reset whenever there is a restart. So I use an input_number to hold the value for a restart and a python script to set the value of the template sensor.

Others reading this might have a more elegant/simple way to do this.

The python script is here: How to manually set state/value of sensor?

I have all the folllowing in a package. sensor.energy_generation is updated every five minutes in my case from the pvoutput integration.

  - sensor:
      - name: "Solar Energy Running Total"
        unit_of_measurement: "kWh"
        state_class: "total_increasing"
        device_class: "energy"
          last_reset: "1970-01-01T00:00:00+00:00"
        unique_id: solar_energy_running_total
        state: '{{ states.input_number.retains_sensor_solar_energy_running_total.state }}'

    step: .001
    unit_of_measurement: kWh
    min: 0
    max: 30

    step: .001
    unit_of_measurement: kWh
    min: 0
    max: 30000

  - alias: calculate_running_solar_generation
    id: calculate_running_solar_generation
      - platform: state
        entity_id: sensor.energy_generation
      - service: python_script.set_state
          entity_id: sensor.solar_energy_running_total
          state: "{{ (states('sensor.solar_energy_running_total') | float) + (((states('sensor.energy_generation') | float) - (states('input_number.solar_generation_daily_last_update') | float)) | max(0))}}"
      - service: input_number.set_value
          entity_id: input_number.solar_generation_daily_last_update
          value: "{{ states('sensor.energy_generation') | float }}"
      - service: input_number.set_value
          entity_id: input_number.retains_sensor_solar_energy_running_total
          value: "{{ states('sensor.solar_energy_running_total') | float }}"

Hate to burst your bubble but this is probably relevant Energy Management in Home Assistant - #765 by OzGav

How did you get this working? I can authenticate, and get my current reading, but it doesn’t appear to be a valid sensor for the energy page?

Show the states page with the state and attributes.

wow, this is exactly what Ive been looking for. Rephrase, what we all would be looking for. Not simply monitor the energy, but HA advising us on when to use and not to use, given several current and forecast parameters… great! I imagine this to be the way forward for the new HA Energy panel.

Have you already contacted the HA dev team on this? I would certainly hope so, and if not, please do. You could check in on Discord #dev_energy for starters.

1 Like

Quick question. Does everything on the energy dashboard have to be in the same units or can I feed in some sensors in Wh and some in kWh and does the dashboard do a conversion for a common display?

Should be fine, try it and see.

Sorry but that doesn’t make any sense. If it resets daily, it’s a daily reset sensor, not a total increasing sensor.

Can’t you just change the kWh into M3 in the customisations menu? I think that would solve it.

Indeed. And that’s why I was asking to have a “daily reset sensor” configured / adapted into a "total_increasing sensor”. E.g. templating a 2nd sensor, that keeps the value over time… sorry if I was being unspecific…

Did you see my answer Energy Management in Home Assistant - #891 by OzGav

Ah. I don’t know. But Home Assistant should work with your resetting sensor so it might be better to focus on getting that fixed instead of looking for a workaround.

The “daily reset sensor” does work (sort of) and I can use it to configure the solar production.

But: The sensor value is increasing during the day and stays on a final daily value once the sun sets - the value of the sensor now stays on that value until the next morning once the inverter is powered on again (and then starts from 0), resulting in a huge spike in the energy dash board on that following day (the spike with the solar production of the day before). See also: Energy Management in Home Assistant - #392 by JayTee75 (and the following answers).

Or are there better solutions than using a “total_increasing sensor”?

Thank you! I’d like to have a HA solution without relaying on an external script though :neutral_face: maybe set the value via automation?

It is a HA solution. The script is added to HA Python Scripts - Home Assistant

Thats exactly what the script is for…

Exactly! I have contacted them but still no answer. I will try on discord :+1:

I’m having the same issue and also using MariaDB…

Did you get anywhere with getting it working?

Are you recording all the sensors in the recorder? If not I think you will find that is the problem.