With the release of the 2021.9 of Home Assistant, the software can now show your gas usage on the new Energy screen in addition to mains consumption and solar electric production. The new update also added battery storage to the system.

There seems to be a lot of confusion online about how to add the new gas data to the Energy screens and so below is the code I have used and is currently working on my Home Assistant install.

Gas Meter pulse sensor
The gas Meter pulse sensor

Our gas meter is monitored via a Gas Meter Hall Effect Sensor which sends pulses to a datalogger ESP8266 Mains Energy Monitor which in turn sends the data to our MQTT server.

The current documentation on the Home Assistant website home-assistant.io/docs/energy/gas/ doesn’t show any examples of the code needed and only refers to using third-party P1 readers.

I have my Home Assistant config files separated into subfolders and in my sensors.yaml file I have the following to retrieve the gas meter number from the MQTT server:

- platform: mqtt
  state_topic: "/home/power/gasmeter"
  name: "Gas Meter"

To be able to access the data with the new Energy screen the data needs additional attributes, and these are added using a template sensor:

- platform: template
  sensors:
    gastocubicmeter:
      value_template: "{{ states('sensor.gas_meter') | float / 100 }}"
      unit_of_measurement: m³
      device_class: gas
      attribute_templates:
        state_class: total_increasing

For the sensor to be used by the Energy screen it needs the unit of measurement attribute to be in cubic meters, the device_class needs to be "gas" and the state class needs to be "total_increasing" I tried other values on the Home Assistant documentation for these attributes, but they did not work.

Our gas meter records one pulse for every 0.01 of a cubic meter of gas used and so we need to divide the gas meter reading by 100 to give the correct cubic meters used of gas. This is done in the value_template attribute.

Energy Config Page
Energy Config Page
Adding new sensor to Home Assistant
Adding new sensor to Home Assistant
Energy page with gas data
Energy page with gas data

With the new template sensor added you need to restart Home Assistant and then in the Energy settings page, select the new sensor on the Energy config screen at /config/energy

On the Energy screen, the new graph for Gas Consumption will appear with a message saying: "There is no data to show. It can take up to 2 hours for new data to arrive after you configure your energy dashboard."

After a few hours, your gas consumption should appear on the graph.