Utility meter not picking up device_class of source sensor

Dear awesome community,

I have set up a gas sensor via ESPHome which I now want to use as source in a utility meter in order to use the “calibrate service” of the utility meter.
The sensor in ESPHome is configured like this:

globals:
  - id: total_pulses
    type: int
    restore_value: false
    initial_value: '0'

binary_sensor:
  - platform: gpio
    id: internal_pulse_counter
    pin: 
      number: 12
      mode:
        input: true
        pullup: true
    internal: true
    filters:
      - delayed_on: 100ms
    on_press:
      then:
        - lambda: id(total_pulses) += 1;

sensor:
  - platform: template
    name: "Gas gesamt"
    device_class: gas
    unit_of_measurement: "m³"
    state_class: "total_increasing"
    icon: "mdi:fire"
    accuracy_decimals: 1
    lambda: |-
        return id(total_pulses) * 0.1;

The sensor shows up completely right and with the following properties in dev tools:

In my configuration.yaml I have set up the utility meter for this sensor like this:

utility_meter:
  gas:
    name: "Gaszähler Stand"
    source: sensor.gas_gesamt

In dev tools the sensor doesn’t show the device_class. Here are the details:

The problem is that I simply cannot use the Gaszähler Stand utility meter as a gas usage source in the energy dashboard.
This freaks me out, I tried so much.

As I understand I need the correct device_class and unit_of_measurement set on a sensor in order to use it for the energy dashboard. This is true for the source sensor, but not for the utility meter.

Why do I use a utility meter to read a sensor?
The answer is simple: I can use the calibrate service every now and then when I notice that my sensor deviates from the correct reading on my real gas meter. Additionally in the beginning I calibrated the utility meter to the exact value of my gas meter in order to track if my binary sensor in ESPHome works reliably.

Every now and then when my ESPHome ESP32 looses connection or misses a reading I correct that by calibrating that utility sensor again, which in turn adds the correct readings of the ESPHome source on top of the calibrated value pretty reliably.

I just cannot calibrate the source sensor, which delivers absolute values (total_increasing), in home assistant, am I right? As soon as a new value gets delivered by the sensor it gets set in home assistant, no matter if I have set a higher value in the dev tools before (seems right to me).

Anyway, I need a solution for my sensor which is not always correct and I want to correct the readings in home assistant every now and then conveniently in the UI. My best take now is using a utility meter, but I cannot use this one in the energy dashboard and I do not want to use the ESPSensor in the energy dashboard as I cannot correct the value which then doesn’t flow back into the statistics - and that is what I ultimately want, correct statistics incorporating corrected sensor readings.

Go to Developer Tools → Statistics. Are there any “Fix Issue” buttons for you to press there?

I have the same problem!
I’ve created two utility meters, based on sensors. One for gas consumption, one for electricity. The sensors have the correct unit_of_measurement (m3 and kWh) and device_class (gas and energy). The utility meter (either created through the ui or in .yaml) for electricity works just fine and copies the information from the sensor. The utility meter for gas however, doesn’t create the attribute device_class. Since there is no way of adding this to the utility meter, it can’t be used for the energy dashboard.

Same happens to water utility meters…

Use customize to add the required device class to the utility meter sensor.

Thanks! This solved the problem for me!

I don’t see a way to edit the “Show as” (device class) of a Utility Meter in the UI. Did you mean through customize.yaml?

Yes.