Adding a mqtt gas meter to the energy page but getting "No matching statistics found"

Hi all,

I have a sensor, that counts my alway increasing gas meter based on an impulse reader and counter. The values are sent via MBus (MeterBus not Modbus) and MQTT to Homeassistant.

This sensor is perfect for the new feature in the energy page: “Add gas source”.

But i am banging my head; i do not get it working. The configuration page of the energy module always shows: No matching statistics found.

My version is: core-2021.9.2

The configuration is like this:

sensor:
  - platform: mqtt
    name: "Hauptgaszähler"
    state_topic: "My/Topic/Path/MainGasVolume"
    json_attributes_topic: "My/Topic/Path/MainGasVolume"
    value_template: "{{ value_json.Value | float | round(2) }}"
    unit_of_measurement: m³
    device_class: energy
    state_class: total_increasing
    #last_reset: 2021-08-26T00:00:00+00:00  # Is not valid for templates
    last_reset_value_template: "2021-08-26T00:00:00+00:00"
    last_reset_topic: "My/Topic/Path/DummyResetTopic"

I have read many posts about this topic, but I get not even one sensor, showing up in the energy page.

Can anyone give me a tip?

Thanks

Device_class: gas
Not energy for gas

I’m having the same issue as @klacol.

I’m also running core-2021.9.2 and my MQTT gas sensor is also not appearing in the gas pulldown. Here’s my sensor config:

  - platform: mqtt
    state_topic: "rtl_433/+/devices/SCM_/xxxxxxxx/Consumption"
    expire_after: 12000
    device_class: gas
    icon: mdi:fire
    force_update: true
    state_class: total_increasing
    unique_id: scm_plus_xxxxxxxx
    name: gas_meter_xxxxxxxx
    unit_of_measurement: 'ft³'

People have opened github issues for this problem:

Ok, thanks, that worked for me.

sensor:
  - platform: mqtt
    name: "Hauptgaszähler"
    state_topic: "My/Topic/Path/MainGasVolume"
    json_attributes_topic: "My/Topic/Path/MainGasVolume"
    value_template: "{{ value_json.Value | float | round(2) }}"
    unit_of_measurement: m³
    device_class: gas
    state_class: total_increasing
    #last_reset: 2021-08-26T00:00:00+00:00  # Is not valid for templates
    last_reset_value_template: "2021-08-26T00:00:00+00:00"
    last_reset_topic: "My/Topic/Path/DummyResetTopic"

I created a pull request to add gas to the available list of device_class. That PR was accepted and the documenation is now updated:

According to the docs here Sensor Entity | Home Assistant Developer Docs both m³ and ft³ are valid. I have not looked at the code to confirm.

I wanted the Energy integration to display my oil usage so piggybacked on the Gas section and converted oil consumption into kWh through a template entity. This couldn’t be input into the integration so I just used Node-Red to pass it to an MQTT entity which could.

This entity picks out from other entities the kWh of the day…

  - platform: template
    sensors:
      oil_energy:
        friendly_name: "Oil Energy Today (kWh)"
        unit_of_measurement: "kWh"
        value_template: "{{(states('sensor.burn_time_by_day') | float - (states('sensor.burn_count_by_day') | float * states('input_number.oil_burn_delay') | float)) | float * states('input_number.boiler_rating') | float }}"

The Node-Red flow is vary simple, just an “Events: State Changed” node to an “MQTT Output” node.

This entity then reads it back and is picked up by the Energy integration

- platform: mqtt
    unique_id: sunny_mqtt_0001
    state_topic: sensor.oil_energy
    name: "Oil Energy"
    unit_of_measurement: "kWh"
    device_class: energy
    state_class: total_increasing

Apart from the Energy integration describing it as Gas it works fine.