Some sensors with kWatth and others with kWh

I have done quite a lot in Home Assistant, but now I am facing a wall …

In my configuration I am converting switches with attribute with a template sensor to extract the power consumption and using sensor.integration to convert from W to kWh.
But my problem is that for some sensors this works without problem, but for others it ends up in kWatth instead of kWh (which the energy dashboard doesn’t like…)

One example where it works:
Original sensor data:

Then I use the following to extract the power:

template:
  - sensor:
      - name: elforbrukning_ateljen_luftvarmepump
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        state: "{{ float(state_attr('switch.ateljen_luftvarmepump_21', 'current_power_w')|float(0)) }}"

So I get this sensor:

Then using integration to convert from W to kWh:

sensor:
  - platform: integration
    source: sensor.elforbrukning_ateljen_luftvarmepump
    name: elforbrukning_ateljen_luftvarmepump_int
    unit_prefix: k
    unit_time: h
    round: 2

and I get this resulting sensor


Which is exactly what I expect.

Then I have one example where it doesn’t work:
Original sensor data:

Then I use the following to extract the power:

template:
...
  - sensor:
      - name: elforbrukning_teknik_ateljen
        unit_of_measurement: W
        device_class: power
        state_class: measurement
        state: "{{float(state_attr('switch.ateljen_teknik_ateljen_23', 'current_power_w')|float(0))}}"

So I get this sensor:

Then using integration to convert from W to kWh:

sensor:
...
  - platform: integration
    source: sensor.elforbrukning_teknik_ateljen
    name: elforbrukning_teknik_ateljen_int
    unit_prefix: k
    unit_time: h
    round: 2  

and I get this resulting sensor

And now I got unit_of_measurement kWatth instead of kWh

The original switches both comes from the same fibaro Home Center integration and looks exactly the same as seen above, so I don’t think it is related to this.
It feels like it is related to the sensor.integration

I have searched online but can not find anyone else mentioning this problem and I can’t see the difference between the cases where it work and where it doesn’t.

I hope it is a simple mistake…

Running Home Assistant core-2021.12.10

Why are you dong this when the switches already report daily energy?

I have many different switches / lights through different integrations reporting in different ways and I want to get a better structure of the energy reporting.

I only took the two above as an example of where it goes wrong.

@Jonas_Engstrom, I have the same problem. There were suggestions on community to change unit_of_measurement in home-assistant.db. I did, but in developer site those sensors still have kWatth.
Let me know if you find a solution.

Rather than messing about with the Riemann Sum all you have to do is this:

template:
  - sensor:
      - name: elforbrukning_ateljen_luftvarmepump
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: "{{ state_attr('switch.ateljen_luftvarmepump_21', 'today_energy_kwh') }}"

The energy attribute already exists.

I have actually a similar problem:

A sensor provided by the Homematic integration reports Watt as unit of measure. That gets aggregated to kWatth, which can not be used in the energy dashboard.

Any suggestions?

Try using customize to change the unit to kWh.

If you can’t do it via the UI, use the manual YAML instructions further down the page.

1 Like

Thank you for the instruction, I did it in the configuration.yaml and the settings seem to be correct, when I inspect in developer tools. However the device still does not appear in the energy devices list. What am I missing.

These are the settings now:

state_class: total
source: sensor.homematic_sv_wp_leistung
unit_of_measurement: kWh
icon: mdi:chart-histogram
friendly_name: Wärmepumpe Energie
device_class: energy

You might have a problem with the Statistics of the sensor.
See: The entity must not have any statistics errors and check it in Developer tools -> Statistics.

1 Like

Go to Developer Tools → Statistics and see if there is a FIX ISSUE button beside the entity. If so, click it and read your options. It’s probably the old unit messing things up.

1 Like

Thanks a lot, that fixed it!