Integration sensor shows Wh instead of kWh

My integration sensor named sensor.office_energy shows Wh instead of kWh. I am using a Zigbee plug that provides a constant W measurement. The documentation of the integration sensor states that if the device provides a power reading in W that the integration sensor will provide a readout in kWh. As I am writing this I am using 116 W through the Zigbee plug. I don’t have any high current devices connected to it. They are a PC, printer, RPi4, phone charger, and speakers. So I never use a whole kWh in any hourly period. Since I use about 230 Wh the integration sensor seems to assume that there device is reporting kW and doesn’t have to divide by 1000 to give me 0.230 kWh. Is this a bug with integration sensor ? Does documentation need to be updated to correct this error? How do I fix this so that sensor.office_energy reports the kWh correctly? This error affects the utility meter since it expects the source to be in kWh.

I am also using an Aotec Zwave Smart Switch 6 that has readings for voltage, current, power and energy. It is connected to the living room entertainment center. The voltage shows to be 124.15 V. The current shows 1 A. The power shows 137.02 W. For some weird reason the device itself shows 238.54 kWh. Since energy measured in W is voltage x current which in this case is 124.15 x 1 then the W is 124 W I can accept the 137.02 W. However, the kWh is way off. What gives?

Please show the config for your integration sensor.

It’s important that you have the following in the config:

unit_prefix: k

I did already have that

sensor:

  - platform: integration
    source: sensor.peanut_office_electrical_measurement
    name: office_energy
    unit_prefix: k
    round: 4
    method: left

Remove it. You are not recording kWh, just Wh.

So why does the documentation say the following? Does the documentation need to be updated?

Energy

An integration sensor is quite useful in energy billing scenarios since energy is generally billed in kWh and many sensors provide power in W (Watts).

If you have a sensor that provides you with power readings in Watts (uses W as unit_of_measurement ), then you can use the integration sensor to track how much energy is being spent. Take the next configuration as an example:

sensor:
  - platform: integration
    source: sensor.current_power
    name: energy_spent
    unit_prefix: k
    round: 2

YAML

This configuration will provide you with sensor.energy_spent who will have your energy in kWh.

I have a plug reporting power in W (sensor.power_dishwasher) and the following config works fine:

sensor:
  # Convert power (W) to energy (kWh)
  - platform: integration
    source: sensor.power_dishwasher
    name: energy_dishwasher
    unit_prefix: k
    round: 2

# Utility Meter Dishwasher
utility_meter:
  energy_daily_dishwasher:
    source: sensor.energy_dishwasher
    cycle: daily
  energy_quarterly_dishwasher:
    source: sensor.energy_dishwasher
    cycle: quarterly
1 Like

So why is my integration sensor not reporting correctly if we basically have the same setup? Is there something else in my HA setup that messes up the calculation?

I have also recently created a integration sensor for the same purpose. Initially without the prefix and the sensor reported Wh. I have updated the sensor, it is now correctly stating kWh, but I believe it took some time and maybe a reboot to be correct. Unfortunately there is no way to reset the integration, so it is showing a huge number now.

1 Like

I am more concerned about the number than the displayed prefix. I can easily ignore the prefix. The number is what I need to be accurate.

I guess I will have to live with data and add a division by 1000 in the value template that the utility meter feeds. I guess the band aid is my only option.

Can you please show some graphs of the power sensor and the integration sensor for the same time period?

Yes, but I think that T1ppes pointed to the likely cause. It seems that the integration sensor doesn’t start reporting a lower number when it is edited with unit_prefix: k So I guess I didn’t always have unit_prefix: k and was so long ago that I added it that I initially thought that I always had it.

Now I am really confused. The utility meter office_kwh_energy_hourly reports correctly even though the integration sensor does not. Since utility meter uses the integration sensor as a source I figured it would show the amount with the decimal in the wrong location but it does not. So I don’t need to adjust my value template after all.

I finally understand what is going on. It is cumulative. Here is it is since the beginning.

Right.

When I read this:

I knew you had a small error in your understanding.

Watts are the measure of the instantaneous power that you are using right now. it’s calculated by volts x current (basically, ignoring the power factor)

Watthours are the measure of how much energy you have used over time. It’s calculated by watts x hours

1 kwh = 1000 watts for 1 hour

So if you are using 137 watts and that is constant for 1 hour then you would have used 137 wh or .137kwh.

And if you maintained that power consumption for the next hour you would have used a total of .274 kwh.

1 Like

All I needed to know was that the kWh from the integration sensor is cumulative over hours, days, months, and years. I figured it reset every hour.

If you want to delete a thread, flag the post. Don’t change the title. Also, why do you want to delete this when others can find the information useful?

1 Like

I’m surprised that the thread could be found useful. I feel it is too simple a problem that almost no one else would jump to the conclusion that I did. I just wasn’t thinking clearly until I realized that the integration sensor is cumulative.

You’d be surprised. Unit conversions aren’t easy for everyone.

2 Likes

OK. I changed title back to original title.

If one (you) can make that “mistake”, anyone could do so as well… :wink:

In Germany we have a saying: “No one is useless, he can always be a bad example!” :smiley: :smiley: :smiley: :smiley:

Just leave it, it will help someone, I’m 100% sure. :smiley: :smiley: :smiley: And don’t take it personally, HA can be complicated, and it is always better to ask, then going further without knowing. The most dangerous people are the ones, that don’t ask. :slight_smile:

2 Likes

Hi, Im pulling my hair out over something that I know when I find the answer I will feel silly :slight_smile: but here goes:

I have two sensor values, one is in Wh and the other is in kWh. I want to add the two values together to be a sensor ‘solcast_latest_today_forecast’ value. Here is my yaml:

sensor:
  - platform: template
    sensors:
        solcast_latest_today_forecast:
             friendly_name: "Solcast Latest Today Forecast"
             unit_of_measurement: 'Wh'
             value_template: "{{ states('sensor.hauxtonenvoy_today_s_energy_production') | float + states('sensor.solcast_forecast') | float }}"

This gives me the wrong total value, lets say that sensor #1 has a value of 18,820 Wh and sensor #2 has a value of 0.03kWh. Then with the above is get a total value of 18,820.03 rather than 18,850 Wh (or 18.82kWh). The numbers get bigger at the start of the day for the Solar forecast so this seemingly small difference will make big errors at other times.
I have tried many versions of the above value_template to ‘/ 1000’ the Wh value and then ‘* 1000’ the kWh value in my attempts to normalise the two values, I can get it and I would really appreciate some help on this probably silly little thing.

Thank you in advance…