Convert kWh to Watt

There are Millions of Threads and HowTo’s out there to convert Watt into kWh. Even if you search “convert kWh into Watt” you always receive the opposite.
My power-meter adaptor sends only kWh, but I need the live Watt number for the Power Flow Card Plus. I tried to do it with a helper, but failed because I am to stupid to do so …

Who can help me.

For Information:

Power [Wh] is the rate at which Energy is being used. Watts are equivalent to Joules per second.

To get energy from power we use the Reimann approximation as the integration or sum of the area under a power-time curve.

To get power from energy we use the Derivative or slope (rate of change) of an energy-time curve.

Differentiate ↔ Integrate

with either being the inverse of the other.

You can create a Helper > Derivative to create a sensor that is the change in energy (KWh) sensor over a time period (sample interval). This does require a bit of experimentation to find a suitable time period setting.

The smaller the time sample, the closer to ‘live’ but the more variation in the result.

For the calculation you need two values, the difference of power-meter values and the time since the last read.
Luckily the statistics sensor calculates that itself with the change_second option. Put the sampling size to 2 and pick a precision of at least 5. Then you will see the calculated value after 2 new values of the source sensor which ist something like 0.00116 kWh/s. h/s ist not really helpful but h/h solves itself, so create a template sensor which multiplies the statistic sensor by 3600 (one second * 60 * 60 = one hour) and if you want Watts also times 1000.

I already know (in theory) that Watt is the integration of the kWh in a certain time …
But I don’t know how I can calculate this with a helper. I tried the integration and also a template … but failed.

Watts, as a rate, is the Derivative (not integral) of Energy.

Try “derivative” helper…

1 Like

You can use this KWh to Watts Calculator

And how can I implement this into a HA-helper?

Refer to the HA docs on how to create a derivative helper.

For example, I have an energy meter that updates every 5 minutes, so I created a derivative helper that calculates the rate of change over a 5-minute moving average. Since the energy sensor is in kWh, the derivative sensor specifies hours as the time unit, so it appears as kWh/h, i.e. kW.

Under Settings, devices and services, click Helpers, then create helper, then Derivative sensor:

UPDATE: here’s a graph of the derivative sensor overlaid with a wattage sensor for the same meter for the past hour. Obviously it’s not an exact copy, but the values mainly match up.

That’s exactly what I did!
The .JSON of the device is updated every second (even the “EnergyCounterIn” value). I tried with a time window of up to 5 Minutes - but i don’t receive any value.

The starting point is a Home Assistant sensor, where the state value is the energy, the sensor has device class ‘energy’ and units of either Wh or kWh.

The state value should change regularly, and it should either increase all the time (total energy used like a utility meter) or it should go up some of the time and down at other times (energy passed to a solar battery as charged and discharged energy)

If you have some other complex data structure in JSON then additional work may be required to get the starting energy value, perhaps from a sensor attribute.

Without knowing exactly what your data source is, further suggestions on what you can do to make this work may be unhelpful.

I am in the exact same situation. It’s little comfort, I know. There has never been any sign of life in my derivative helper:


This washing machine only reports kWh, which doesn’t match with my power graphs.

I assume Homeassistant is just kidding me …

After the 3rd time setting up and deleting the identical helper … it suddenly sends data :imp:

I am acutally struggeling calculating different values from the few information I get from the reader. And why are the values shown differently in the Power Card Plus and the sensor cards?

But generally the helper works.

Thanks so far … i tried different things, but nothing helped. I always receive rubbish. So now a completely new approach:

This is the .json output:

Wheras:

“power” is the actual usage in W
“powerAVG” is the average power of the last minute (useless in my case) in W
“energyCounterIn” is the delivery from the grid in kWh
“energyCounterOut” is the supply from all home devices (PV, Battery …) in kWh

As there is no integration, the sensors are defined directly in the config.yaml. Here’s how (sorry, it’s partially german):

  - sensor:
    - name: "Ecotracker Aktueller Verbrauch"
      unique_id: ecotracker_verbrauch
      device_class: "power"
      state_class: "measurement"
      unit_of_measurement: "W"
      state: >
            {{ state_attr('sensor.ecotracker', 'power') }}

    - name: "Ecotracker Bezug"
      unique_id: ecotracker_bezug
      device_class: "energy"
      state_class: "total_increasing"
      unit_of_measurement: "kWh"
      state: >
            {{ iif(state_attr('sensor.ecotracker', 'energyCounterIn'), (state_attr('sensor.ecotracker', 'energyCounterIn') | float/1000)| round(2)) }}

    - name: "Ecotracker Einspeisung"
      unique_id: ecotracker_einspeisung
      device_class: "energy"
      state_class: "total_increasing"
      unit_of_measurement: "kWh"
      state: >
            {{ iif(state_attr('sensor.ecotracker', 'energyCounterOut'), (state_attr('sensor.ecotracker', 'energyCounterOut') | float/1000)| round(2)) }}

What do you think of the idea of just adding some additional sensors here in the config.yaml, that just calculate their states from the corresponding .json entry. Like this:

    - name: "Ecotracker Bezug in W"
      unique_id: ecotracker_bezug_W
      device_class: "energy"
      state_class: "measurement"
      unit_of_measurement: "W"
      state: >
            {{ energyCounterIn +-*/ blablabla }}

This should finally work. But how should the statement look like?