Adding gas to energy dashboard (solved)

I have been fighting this Gas stuff for days now. No matter what I do the sensor(s) will not show up for selection in the Add Gas section of the Energy config. I have forced it by editing the energy file as posted above, but it still doesn’t work right. My gas sensor set to output in cubic meters increases by like 0.2 per hour, but the energy chart will show I used 2 cubic meters of gas that hour instead of 0.2 like it should. ive tried cubic feet, as well which was even worst as my sensor would increase by 2 but the energy chart would increase by like 70. I’ve tried all this with the readings from a sensor, from a statistics sensor, and from a utility integration. Nothing works. The Gas option for the Energy page needs A LOT of work.

I finally figured out what it was doing, it was driving me nuts. So I set my sensor to cubic feet because I live in the US. The consumption comes in from my meter and is stored in the sensor as feet. However, in the statistics table it converts that number to cubic meters. The sum in the statistic table is also stored as cubic meters, however, it is displaying as cubic feet on the dashboard with a incorrect label. I did the math :slight_smile: Cubic meters in the database, the graph has cubic feet with a cubic meter label. It works this way as long as your sensor has cubic feet as unit of measure as far as I can tell…

- platform: mqtt
    state_topic: "readings/98103394/meter_reading"
    name: Gas Meter Rtl
    unique_id: gas_meter_rtl
    device_class: gas 
    state_class: total_increasing
    unit_of_measurement: ft³

Hopefully the next version of HA will better support cubic feet.

Hey, apologies as I am just getting into all of this, got my gas meter being read and would like to add my info to the energy.json, but I don’t know the location of energy.json within the file structure… Did you make a new one? I half assumed it was auto-generated, but if I need to make a new one where should I place it? I looked all over my config\ folder but didn’t see anything.

Thanks in advance!

Hmm crazy. I’ve renamed mine but not getting the expected results.

  - platform: mqtt
    state_topic: "readings/1234567/meter_reading"
    name: "Gas Meter 2.0"
    unit_of_measurement: "m³"
    device_class: "gas"
    state_class: "total_increasing"

It seems to be working correctly as an entity:

Any thoughts? Fully upgraded.

Same here, entity works fine, but not in energy. Add sensor in the json file, put is srill not presence i the setting

Hey, I have problem with gas sensor. I cannot select it in energy configuration. My sensor comes from esphome. This is esphome configuration:

sensor:
  - platform: template
    name: "iNode Gas"
    id: home_gas_m3
    unit_of_measurement: 'm³'
    accuracy_decimals: 2
    device_class: "gas"
    state_class: "measurement"

I see entity in home assistant with correct data. Only I cannot select it in energy configuration… Maybe someone had similar problem?

2 Likes

Hi,
I have slimme lezer for P1 port but unable to add it to energy dashboard. there is no device in the list not for gas not for energy.
Maybe im missing something?
Anyone idea?

I think state_class needs to be total_increasing for it to show up under energy configuration. I was able to get my fireplace gas consumption into HA with this setup, based on the time that switch.fireplace is on.

sensor:
  - platform: history_stats
    name: Fireplace runtime today
    entity_id: switch.fireplace
    state: "on"
    type: time
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"

template:
  - sensor:
      - name: Fireplace gas
        unique_id: fireplace_gas
        device_class: gas
        unit_of_measurement: "m³"
        # Rated at 15,800 BTU/hour = 0.4476 m³/h
        state: "{{ (states('sensor.fireplace_runtime_today') | float * 0.4476) | round(2) }}"
        state_class: total_increasing

Just piling on here, my experience matches that of @stogs

I’m using rtl_433 to read my gas meter, which outputs in cubic feet (the dials on the front of the meter report CCF, hundreds of cubic feet, but the ERT radio output has two more digits). My MQTT sensor uses a value_template to convert this to cubic meters, and has a unit_of_measurement of m³.

Though the entity is set up correctly, I had to hand-edit it into the energy json file. It seems to be working OK but for 3 issues:

  • The numbers displayed are in cubic feet despite the legend being cubic meters
  • I’m not seeing cost accounting despite having set up the energy price
  • The Energy configuration panel still doesn’t see the gas sensor despite it working.

I suspect the first two issues are both related to confusion over units. For the third, maybe the devs are intentionally excluding setups that use imperial units because of these bugs. With luck we’ll see improvement in a future version.

You can check in ‘Developer tools/Statistics’ if there is something wrong with unit of measurement in your database.
It worked for me.

1 Like

@parkercat @Kyle @wonderslug I am using hertzg/rtl_433 docker as well, but I don’t see my gas meter in MQTT Explorer. I only see my 433 devices. How did you get this working?

Currently I am using allangood/rtlamr2mqtt docker for my gas meter and it works. But would love to have it so I could pull it all from one docker and not have to have two rtl-sdr devices.

I’m simply running rtl_433 with:

rtl_433 -R 149 -f  916000000 -M level -F  "mqtt://$MQTT_HOST:1883,retain=0,devices=rtl_433[/id]"

For the record I’m in eastern Massachusetts, USA with National Grid as my gas provider.

I chose 916 MHz as the frequency in my location with the best signal/noise ratio for my gas meter – the meters broadcast the same thing redundantly, hopping among frequencies between 910 and 920 MHz. In particular, 915 MHz is what’s used by Insteon so was not a good choice for me. If you need to listen to different frequencies you’ll either need multiple SDR dongles or frequency-hop over time, which you can find examples of in the docs.

You may need different values for the -R param depending on what protocol your meter sends. Run rtl_433 -R alone to see the list.

The -M level option adds signal strength etc. to the data being published.

Then, all the devices’ info is published via MQTT on topics rtl_433/<id>/*. You can see what’s being sent with mosquitto_sub -v -t \#. Evidently you can get JSON instead with events= instead of devices= but I had not found that tidbit when I set this up; see Basic rtl_433 operation | rtl_433

I’m doing something similar to what @parkercat mentioned.

I have another container running just for the 913MHz to always listen in to my gas meter with hertzg/rtl_433.

You can have it hop around frequencies, but I don’t do that since I have some single-event devices on the 433MHz band that I don’t want to miss when they send an event.

Can you share an example of your value_template for the mqtt sensor, I’m getting lost in trying to create one to convert my CCF gas meter to cubic meters.

To be fair, if your prefs select imperial units you’re better off using cubic feet not cubic meters. At least I think that’s why my energy panel says “m³” but the numbers are in cubic feet (it’s just cosmetic though). But here’s my MQTT sensor for cubic meters (my MQTT sensor publishes in cubic feet):

  - platform: mqtt
    name: "Gas Meter Direct"
    state_topic: "rtl_433/REDACTED/consumption_data"
    value_template: "{{ value | float(0) * 0.02831684659 }}"
    device_class: gas
    unit_of_measurement: "m³"
    state_class: total_increasing

I’m lost

I re-read this thread and can’t get it to work. My electricity consumption shows up but the gas doesn’t.

- platform: mqtt
  name: "value_json.Energy_Delivered"
  state_topic: "dsmr/p1/energy"
  unit_of_measurement: "kWh"
  value_template: "{{ value_json.Energy_Delivered }}"
  state_class: total_increasing
  device_class: energy
  

- platform: mqtt
  name: "value_json.Gas_Delivered"
  state_topic: "dsmr/p1/energy"
  unit_of_measurement: "m³"
  value_template: "{{ value_json.Gas_Delivered }}"
  state_class: total_increasing
  device_class: gas

When I watch the mqtt-stream I can see the raw values increasing…

{
    "Timestamp": "211122124805W",
    "Energy_Delivered": "50091.527",
    "Energy_Returned": "0.000",
    "Gas_Delivered": "14902.84",
    etc etc
....
}

ok, found It, sorry for spamming this topic, but at the first try I had kWh for the gas unit (copy-paste error) and thanks to Pablo I fixed it now: Adding gas to energy dashboard (solved) - #31 by pbadmin

The elektricity works, but not the gas meter. I have some strange value’s (see image below).
What can this be?

image

Hi!
i am try to get my gas sensor on energy dashboard …but does not appear
any ideias???

  • platform: template
    sensors:
    gas_consumption_m3_day:
    unit_of_measurement: ‘m³’
    device_class: gas
    value_template: >-
    {% set impulse_unit = 0.01 %}
    {% set impulse_count = states(‘sensor.contador_impulsos_gas_day’) %}
    {{ ‘unknown’ if impulse_count == ‘unknown’ else (impulse_count|int * impulse_unit|float) | round(2) }}