Some of my utility meters show units in Wh instead of kWh

Hi,

I have set up several utility meters. Here are relevant parts from my configuration

# Utility meters
utility_meter:
  apartment_1_montly_energy:
    source: sensor.apartment_1_energy_kwh
    cycle: monthly
  apartment_1_daily_energy:
    source: sensor.apartment_1_energy_kwh
    cycle: daily
  apartment_2_montly_energy:
    source: sensor.apartment_2_energy_kwh
    cycle: monthly
  apartment_2_daily_energy:
    source: sensor.apartment_2_energy_kwh
    cycle: daily
  apartment_3_montly_energy:
    source: sensor.apartment_3_energy_kwh
    cycle: monthly
  apartment_3_daily_energy:
    source: sensor.apartment_3_energy_kwh
    cycle: daily
  apartment_4_montly_energy:
    source: sensor.apartment_4_energy_kwh
    cycle: monthly

Here is the sensors configuration

 - platform: mqtt
    name: "Apartment 1 power"
    state_topic: "panel/sensor/apartment_1_power/state"
    availability_topic: "panel/status"
    unit_of_measurement: "W"  
  - platform: mqtt
    name: "Apartment 1 energy"
    state_topic: "panel/sensor/apartment_1_energy/state"
    availability_topic: "panel/status"
    unit_of_measurement: "Wh"  
  - platform: mqtt
    name: "Apartment 1 power factor"
    state_topic: "panel/sensor/apartment_1_power_factor/state"
    availability_topic: "panel/status"
    unit_of_measurement: ""  

  - platform: mqtt
    name: "Apartment 2 power"
    state_topic: "panel/sensor/apartment_2_power/state"
    availability_topic: "panel/status"
    unit_of_measurement: "W"  
  - platform: mqtt
    name: "Apartment 2 energy"
    state_topic: "panel/sensor/apartment_2_energy/state"
    availability_topic: "panel/status"
    unit_of_measurement: "Wh"  
  - platform: mqtt
    name: "Apartment 2 power factor"
    state_topic: "panel/sensor/apartment_2_power_factor/state"
    availability_topic: "panel/status"
    unit_of_measurement: ""  

  - platform: mqtt
    name: "Apartment 3 power"
    state_topic: "panel/sensor/apartment_3_power/state"
    availability_topic: "panel/status"
    unit_of_measurement: "W"  
  - platform: mqtt
    name: "Apartment 3 energy"
    state_topic: "panel/sensor/apartment_3_energy/state"
    availability_topic: "panel/status"
    unit_of_measurement: "Wh"  
  - platform: mqtt
    name: "Apartment 3 power factor"
    state_topic: "panel/sensor/apartment_3_power_factor/state"
    availability_topic: "panel/status"
    unit_of_measurement: ""  

  - platform: mqtt
    name: "Apartment 4 power"
    state_topic: "panel/sensor/apartment_4_power/state"
    availability_topic: "panel/status"
    unit_of_measurement: "W"  
  - platform: mqtt
    name: "Apartment 4 energy"
    state_topic: "panel/sensor/apartment_4_energy/state"
    availability_topic: "panel/status"
    unit_of_measurement: "Wh"  
  - platform: mqtt
    name: "Apartment 4 power factor"
    state_topic: "panel/sensor/apartment_4_power_factor/state"
    availability_topic: "panel/status"
    unit_of_measurement: ""  

Because the sensor provided enrgy value is in Wh, I have created template sensors to convert it to kWh, as per suggestions in other threads:

  - platform: template
    sensors:
      apartment_1_energy_kwh:
        value_template: "{{ state_attr('sensor.apartment_1_energy') | int / 1000 | round(2)}}"
        unit_of_measurement: kWh
      apartment_2_energy_kwh:
        value_template: "{{ state_attr('sensor.apartment_2_energy') | int / 1000 | round(2)}}"
        unit_of_measurement: kWh
      apartment_3_energy_kwh:
        value_template: "{{ state_attr('sensor.apartment_3_energy') | int / 1000 | round(2)}}"
        unit_of_measurement: kWh
      apartment_4_energy_kwh:
        value_template: "{{ state_attr('sensor.apartment_4_energy') | int / 1000 | round(2)}}"
        unit_of_measurement: kWh

Now, I think I am getting the proper value from the utility meter, however, some of the utility meters have “unit_of_measurement” as Wh, and the rest of them don’t have “unit_of_measurement” at all
Please see following screenshots of the daily energy meters, the same happens with the monthly ones, 1 and 2 have units, and 3 and 4 don’t

For me, this doesn’t make any sense, as utility meter does not have units, as specified in the docs here:

Can anyone help me with this?
Thank you

2 Likes

I had the same issue… please take a look at this

After setting up new integration sensor and a new utility meter sensor called ‘test’, and that changed the unit.

Isn’t think because you have defined the units as “Wh” in the config?

image