Integrating a power reading

Hello, first time poster here. I have just started using HA and am having some trouble getting my head around the language and how to do things.

I have set up HA on a RPi to take reading from my heat pump. The heat pump I have hacked the configurations.yaml file to read the voltage and the current and multiplied these together to get the power the unit is consuming. I then plot this onto a graph. The yaml code is this…

sensor:
  - platform: template
    sensors:
          ...some code here not shown...
      espaltherma_power:
        friendly_name: "Power consumption"
        value_template: "{{ state_attr('sensor.althermasensors','Voltage (N-phase) (V)') * state_attr('sensor.althermasensors','INV primary current (A)') * 0.001}}"
        unit_of_measurement: 'kW'

and an example of the graph it produces is shown here - so far so good:

I thought it would be more useful to see how much power I had used in the last hour and maybe the last 24 hours, but i can’t figure out how to do it and everything i try seems to result in garbage readings. Mathematically i want to integrate it over time, so i used the integration add-in (Integration - Riemann sum integral - Home Assistant) but this doesn’t reset and just gives a number that seems too high.

I also tried to use a global variable (well that is what I would call it in C++) where everytime the power was read I added the current reading to previous ones - but I couldn’t get that to compile?

Can anyone help me?

  1. Yes it will keep counting up forever, if you want hourly energy use, feed the Riemann Sum sensor to utility meter helpers with hourly and daily cycles
  2. Make sure to use the method: left option in your Riemann Sum sensor to reduce errors.
  3. Do not confuse Energy and Power.

Thanks for the reply. I think I am making some progress?

I have created 2 helpers. 1 called ‘energy_integration’ which is based on my ‘Power consumption’ entity. It has the integration method as ‘Left Riemann sum’, a precision of 3, no prefix and a Time unit of hours.

I then created a ‘Utility Meter’ called ‘hour’ and have set it to look at the ‘energy_integration’ helper.

image

I then created a ‘Sensor’ card for ‘energy_integration’ and set the display to 1 hour, and another ‘Gauge’ card called ‘Last Hour’ and pointed that at the ‘hour’ helper.

The integration card seems to count up as expected (I’m now expecting this to carry on counting up forever), but the ‘hour’ card is not working? it just says ‘Entity is currently unavailable: sensor.hour’

update: I have change the ‘Utility Meter’ settings so Delta Values is unchecked. I did originally check this but the integrater is doing that bit now.

So slight improvement i now get a reading but it’s zero!

image