Utility Meter power graph

Hi, I have my AC connected to Sonoff POW R2 and I am getting reading in HA in W which is currently using and I need to know how much power it uses for a week/month.
So I added Utility Meter to my .yaml

    source: sensor.sonoff_power
    cycle: weekly

The reading seems weird, it adds 2.5kW every time it turns on,
Here is the real power graph below.
Can anyone help ?


It looks like your sensor is reporting in real time kW, while the utility sensor needs to use kWh. Check out the Integration Sensor component.

If you feed the sensor.sonoff_power into the Integration Sensor on an hourly basis, it’ll output kWh which you can then use in the Utility Meter component.


Yeah, So I tried to find it.

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

I added it, and I will wait to see if it works.

So if I want to have more sources or more info like consumption for a week and month, I just use Integration Sensor and set it for week and day, because Utility Meter cant be used separately for more sources.

There is still some problem I did not find out. The real consumption during the night was 5.5kWh but it says 15.9kWh. I did something wrong with the code.

Why didn’t I think of that… I’ve been trying to find out why my HASS utility meter is saying that I am using almost 1 MW!

You can use multiple Utility Meter sensors with the same input source, you don’t need to change the Integration Sensor for day/week/monthly as long as it’s hourly in kWh.

For example here is mine which appears to be working and pretty near what my meter is reporting (I think…). The sensor.house_consumption is the sensor reporting real time kW that I first integrate, then feed it into the various Utility Meter sensors.

  - platform: integration
    source: sensor.house_consumption
    name: energy_consumed

and then for the Utility Meter portion - Mine is a bit more complicated example as I have 3 TOU tariffs that I want to capture the quantities of to calculate the $$ for each.

    source: sensor.energy_consumed
    cycle: daily
      - superoffpeak
      - offpeak
      - peak
    source: sensor.energy_consumed
    cycle: weekly
      - superoffpeak
      - offpeak
      - peak
    source: sensor.energy_consumed
    cycle: hourly
      - superoffpeak
      - offpeak
      - peak

I had the same config, but my meter gives me the kW as real power. That was why I got weird reading.
I need to convert kW to kWh but everything I found shows at least 3 times more.

The sensor feeding into the utility_meter needs to be a running total of energy consumed - which implies it should be in (kilo) watt hours (kWh) and not (kilo) watt (kW).

As you are getting your data from a Sonoff device, you need to create a sensor reading the Total, not Power, and use that to feed your utility_meter.

I did the sensor reading total like this:

  • platform: statistics
    entity_id: sensor.sonoff_power
    name: 1
    sampling_size: 3000
    minutes: 60

and after 25 minutes of constant 2300W it gives me “469000”

sampling size
standard deviation
min value
max value
min age
max age
average change
change rate

It does not seems right to me, or is it right ?

How did you add sensor.sonoff_power to your configuration? Can you paste the code?

For instance, I flashed my Sonoff POW r2 with Tasmota, which sends out mqtt messages, and my sensor definition looks like this:

  - platform: mqtt
    name: "Sonoff Pow Total"
    state_topic: "tele/sonoff-powr2/SENSOR"
    value_template: "{{ value_json.ENERGY.Total }}"
    unit_of_measurement: "kWh"

You can see that in value_template I am reading the Total (NOT Power) value from the sensor data. This is the running total of kWh.
This is what should be fed into the utility_meter.

The sensor data also includes other data points such as Power but we don’t want that as it gives us the Watt at a single moment in time.
Trying to calculate the kWh from that will be highly inaccurate in almost all cases. I have configured the tasmotized Sonoff to send out mqtt messages every 2 minutes. HA will know nothing about the power readings in between two messages - for all you know the power might have dropped to 0 just 1 second after the message was sent. Tasmota/Sonoff will NOT give you the average power for these two minutes AFAIK.

Of course, your setup could be vastly different.

Thank you for that. Unfortunately, I am not using tasmota on these devices because I need them to be accessible outside of my wifi, so I am using the original firmware and Sonoff component to connect it to my HA. The component provides me the sensor.sonoff_power automatically.

Oh, I see. I was certainly not recommending to read the Total of the statistics sensor - that doesn’t provide anything meaningful.

Based on the docs it appears that the sonoff-ewelink component does indeed NOT provide a running total. That’s unfortunate.

Then to me it looks like the earlier advice given to you to use the integration component is the way to go. It seems it was built for exactly that purpose.

What’s interesting is that based on your statistics sensor output, there were 206 events in a time frame of roughly 53 minutes. That would equate to one event being sent every 15 seconds which should be a pretty good sample rate for a calculation of a device with a constant power that merely turns on and off (and doesn’t do that very frequently).

Not sure if I am interpreting the output correctly, though.
I also don’t have any actual experience with that approach, so don’t take my word for it.

Personally, I’d setup a short test: Run your load for x minutes, and then compare the calculated consumption (of the integration sensor) with what ewelink measured (using their “stopwatch”-like feature, not the daily stats.)

Unfortunately, the refresh time is quite random, mostly it’s about 1 minute. Sometimes it refreshes once in a minute, like 6 refreshes every second and then 1 minute of pause.

I would like to ask about this, the kWh is like that it consumes 3000W right now or that it consumed like 1500W during 1 hour when it was half of the time off (3000W appliance)? The sensors provide me how much it draws “W” when it refreshes when I turn it off, then it shows 0W immediately.

Apologies for my slow response rate. Hopefully I’ll be more attentive to the email notifiers going forward :slight_smile:

I would like to ask about this, the kWh is like that it consumes 3000W right now or that it consumed like 1500W during 1 hour when it was half of the time off (3000W appliance)?

Watt Hours (Wh) is a measurement of “momentary” power over time (aka energy consumed). A machine that draws 3000W (“momentary” power) over 1 hour has consumed 3000 Wh (=3kWh).
And as you point out, a 3000W machine that was turned on only 30 minutes in the last hour will have consumed 1500Wh during that time. Of course, some machines can also run on a fraction of the maximum power. Thus a 3000W machine running at 50% load (=1500W) for 1 hr will also have consumed 1500Wh. If it ran only 30 minutes at 50% it will have consumed 1500W x 0.5h = 750Wh.

The sensors provide me how much it draws “W” when it refreshes when I turn it off, then it shows 0W immediately.

The statistics that you posted earlier show that during the observed time period your machine drew power between 714W to 2366W at an average of ~2280W. Because the average is close to the max, and the standard deviation is low, I’d say that it probably ran at a more or less constant load most of the time with minor fluctuations. The 714W were probably measured at the beginning or end when the machine was ramping up and down.
Remember, Power (W) is only a momentary snapshot of the power draw. So if the machine continuously increased the power draw in the first few seconds of being turned on until it reached its full load, you might get some measurements of anything between 0 and 23xx W during that time.

You should be able to look at a graph over the sensor data in order to understand how the machine behaves.

Unfortunately, the refresh time is quite random, mostly it’s about 1 minute. Sometimes it refreshes once in a minute, like 6 refreshes every second and then 1 minute of pause.

It’s possible that the device adjusts its reporting interval based on how often (or how much) the power draw has changed. Which is good because it will provide higher accuracy but avoids generating heaps of data/messages when it’s not necessary (e.g. power machine sits idle).

The way you would calculate the energy consumption (Wh) is to look at every data point in your sequence, and calculate the Wh for the “time slot” between the current measurement, and the previous based on the timestamps:
Power (W) x (Timestamp - TimestampOfPreviousDataPoint) (h) = Wh.
E.g. 2310 W x (3s / 3600) h = 1.925 Wh.
(The time in the example is 3 seconds converted to hours.)

Then you add up the calculated Wh for all of your data points in the sequence, and you will have your (estimated) energy consumption over the entire time period.

I think that’s what the integration component (https://www.home-assistant.io/integrations/integration/) does for you!

Thank you a lot for helping me, here is what I have done.


  - platform: integration
    source: sensor.sonoff_power
    name: nove
    source: sensor.nove
    cycle: hourly
    source: sensor.nove
    cycle: daily
    source: sensor.nove
    cycle: weekly
    source: sensor.nove
    cycle: monthly
    source: sensor.nove
    cycle: quarterly
    source: sensor.nove
    cycle: yearly

When I started it, it jumped right to 350Wh and then it seemed to work ok. I calculate how much it should consume in a minute after a few minutes the integration matched my calculations.
The following morning I was surprised that it was not working as I thought it would be. You sen see it on the graph.

The “nove” is this integration:

When the load was applied at 5:00 it jumped from 3500kW fo 6500kW
I must be missing something right ?

thats weird jumps indeed, since you want kwh you should add unitprefix, right? Can you post the sensor code?

  - platform: integration
    source: sensor.sonoff_power
    name: nove
    unitprefix: k
    round: 2

doublecheck your numbers too, it seems a bit much

For what it’s worth…I get the same jumps in HA v0.105.5 whenever I restart HA. Same sensor config worked fine on 0.100 up to 0.103.2. But after I upgraded HA I can no longer trust the utility meter sensors :frowning:

It seems like it is adding the stored state value (taken from .storage/core.restore) with the incoming value (which will be the same as the stored state) resulting in these big jumps.

1 Like

I have this jumps also randomly when i restart HA. Today after the HA update from 105.5 to 106.4, it jumped from 1580 kWh to 7750 kWh instantly. I am using Aoetec ZWave Home Energy Monitor. I also use a Sonoff POW mqtt connection; which never does that…

I am using this sonoff-ewelink-component
It gives me the sensor, without any code in config.