Adding gas to energy dashboard (solved)

All,

Previous release ( 2021.8) I struggled a bit getting my energy meters on the new dashboard, but the new state_class: 'total_increasing' solved my issues without requiring any workarounds.

I was very excited to see we can now also use gas meters. but now HA does not offer my gas meter as an option in the dashboard, the sensor looks like this:

  - platform: mqtt
    name: "Gas consumed"
    state_topic: "home/smart_meter/HOURLY_GAS_METER_READING"
    unit_of_measurement: 'm³'
    state_class: 'total_increasing'
    device_class: 'energy'

“Add gas source” does not give me any sensors to choose.

Am I missing something? I copied the from somewhere, unsure how to get that into a yaml fle using vim, so that could be it?

Highest regards.

Ok, that was quick… Solved by setting device_class: 'gas'

Apologies!

1 Like

Glad to see this is solved and apologies for hi-jacking, but out of interest how are you getting your Gas meter readings onto MQTT in the first place?

And where is this documented?
I’m finding the documentation for Energy Management and Long Term Statistics incredibly hard to use.
It seems sparse and confusing to me and that is when I can even find it.

I tend to end up back at the 2021.08 release notes every time.

I also found that i HAD to use the unit_of_measurement with the actual superscript 3 in and not just m3 as I had it before.

Soon as I changed that in my yaml, it appeared in the dropdown in my energy config.

1 Like

In the Sensor Entitiy developer docs

Hey there, Does anyone know how to add a sensor entity from a utility_meter to gas?
I’ve set up a pulse meter in an esphome device to measure, and it does the job. Total pulses also accessible via Energy settings, but not the utility meter I’ve set up based on that (because it resets if esp is reset, utility meter tracks the total)

1 Like

Im having the same issue but I have set the state_class and device_class, but it is still not showing up to be selected under the energy settings.

Im using a SDR and rtl_433 to capture my gas consumption to mqtt. The pulling it in with the following sensors.

sensor:
  - platform: mqtt
    state_topic: "rtl_433/xxxxxxxxxx/consumption_data"
    unit_of_measurement: ft³
    name: Gas Consumption
    icon: mdi:fire
    device_class: gas
    state_class: total_increasing

template:
  - sensor:
      name: Gas Consumption Metric
      state: >-
        {{ states('sensor.gas_consumption')|float*0.0283168 }}
      icon: mdi:fire
      unit_of_measurement: 'm³'
      state_class: 'total_increasing'
      device_class: 'gas'

Any hints as to why this wont show up?

I use my own (horribly coded) script and systemd service: https://github.com/freekvh/dsmr-mqtt-wrapper, running on a Pi1a plugged into the P1 port of my smartmeter.

Actually I see that it is about time I update it.

1 Like

Thanks.

I’ve just checked my meter and unfortunately I don’t have a P1 Port, I’ll start a thread to see what I can do…

Hey, Mine got resolved after doing some stupidity and rebuilt database, then restored old from backup and - all my utility meters appeared.
I guess at first try it did not read the unit_of_measurement from the device itself, but after these things it did… ?!..

I have the same setup and I also can’t get the gas stats to show up in the energy dashboard. I’ve tried different settings combinations of device_class and state_class, but nothing has worked yet. There was some update to gas validation in 2021.9.5, but it doesn’t seem to have changed anything for me.

1 Like

Same here. Nothing works.

1 Like

Same here. I had even purged my database in case it was saving the units to the database incorrectly based on some of the fixes in 2021.9.5: https://github.com/home-assistant/core/issues/55629

I also tried waiting 12 hours in case the statistics table wasn’t getting populated yet.

But I’m also trying to use ft3 because I think it’s supported based on the validator allowing it here: https://github.com/home-assistant/core/pull/55886

Edit: it looks like I can add it manually to the energy json file under .storage and get it to work. I think there was either an issue with the long term statistic table in my database or the validator to add it from the GUI.

Edit: it looks like I can add it manually to the energy json file under .storage and get it to work. I think there was either an issue with the long term statistic table in my database or the validator to add it from the GUI.

Cool. What do your changes to the json look like for the gas attributes?

Can you share exactly what your added to the energy? I’ve tried adding it manually in the past and while it does show up as being a source, it never recorded usage.

Sure. Under the energy_sources array, I put this:

{
	"type": "gas",
	"stat_energy_from": "sensor.gas_meter_rtl",
	"entity_energy_price": null,
	"number_energy_price": null,
	"stat_cost": null
}

I’m avoiding adding prices yet until I know the UI will properly match and recognize $/ft3 rather than $/m3

This is my sensor coming from my cheap software defined radio picking up the gas meter using hertzg/rtl_433 based on merbanan/rtl_433.

- platform: mqtt
  state_topic: rtl_433/SCM_/12345678
  name: "Gas Meter"
  unique_id: gas_meter_rtl 
  unit_of_measurement: ft³ 
  device_class: gas
  state_class: total_increasing
  value_template: "{{ value_json.Consumption }}"
  json_attributes_template: "{{ value_json | tojson }}"
  json_attributes_topic: rtl_433/SCM_/12345678
My full energy config file
{
    "version": 1,
    "key": "energy",
    "data": {
        "energy_sources": [
            {
                "type": "grid",
                "flow_from": [
                    {
                        "stat_energy_from": "sensor.energy_meter_main_consumption_daily_energy",
                        "stat_cost": null,
                        "entity_energy_from": "sensor.energy_meter_main_consumption_daily_energy",
                        "entity_energy_price": "sensor.utility_electricity_cost",
                        "number_energy_price": null
                    },
                    {
                        "stat_energy_from": "sensor.energy_meter_subpanel_total_kwh",
                        "stat_cost": null,
                        "entity_energy_from": "sensor.energy_meter_subpanel_total_kwh",
                        "entity_energy_price": "sensor.utility_electricity_cost",
                        "number_energy_price": null
                    }
                ],
                "flow_to": [
                    {
                        "stat_energy_to": "sensor.energy_meter_main_return_daily_energy",
                        "stat_compensation": null,
                        "entity_energy_to": "sensor.energy_meter_main_return_daily_energy",
                        "entity_energy_price": "sensor.solar_return_price",
                        "number_energy_price": null
                    }
                ],
                "cost_adjustment_day": 0.0
            },
            {
                "type": "gas",
                "stat_energy_from": "sensor.gas_meter_rtl",
                "entity_energy_price": null,
                "number_energy_price": null,
                "stat_cost": null
            }
        ],
        "device_consumption": []
    }
}

My sensor.gas_meter_rtl is in ft3 so it doesn’t show the correct units in the UI yet.

If you have a problem (like I did) where you changed units on a sensor after you created the sensor, you can either delete the data from the database statistics and long term history using the links below to help:

  1. Database - Home Assistant
  2. https://data.home-assistant.io/docs/statistics

Orrrrr, the easier way is to just create a new sensor that always had the correct units to begin with (or else the long term statistics will stop recording).

Here my dashboard is still showing in m3 even though the unit is ft3 and the numbers are in ft3 (just with the wrong units here). But again, this is probably because we’re forcing it into the config when it isn’t ready to support showing ft3.

If I had to speculate, they might add a “gas” units to the config kinda like how they do with “currency” (or they’ll just default to ft3 when using imperial units).

I hope that helps!

3 Likes

Thanks, I just manually added mine as well into the energy json.
Says it might take two hours to show up in the dashboard so we’ll see.

From looking at the 2109.0.5 notes, it looks like they addressed ft³ but like you I don’t see evidence of any support in the GUI. Not sure how they could roll out support for gas without supporting imperial as well as metric, I hope they don’t make the same omission when they start supporting water meters as well (hint: those are measured in gal in the US)

Thanks. This got it working for me. My billing is done in ft3 as well. Hopefully that will be an option in the future.

I have the Gas Consumption chart now but still not showing any data for the period.