Energy Dashboard - Allow Gas as kWh

I’m using the SmartThings energy meter with Bulb and I get cumulative electricity (energy) in kwh but I also get a cumulative gas kwh.

Originally the gas came through as energy but I read something saying I needed to set the device_class to gas, which I did as you can see above, but that didn’t work. I also had an error message saying I needed a last_reset so I added that as per some other forum posts, but still no joy. Finally the state_class was originally “measurement” and I read something saying that needed to be total_increasing (as the electricity one already was) however this made no difference either.

I’m on the latest version of 2021.12.7 but it seems gas will still not allow kwh?

Unexpected unit of measurement

The following entities do not have the expected units of measurement ‘Wh’, ‘kWh’ or ‘MWh’ for an energy sensor or ‘m³’ or ‘ft³’ for a gas sensor:

  • sensor.bulb_energy_meter_gas_meter (kWh)

I have the same problem… My Vaillant boiler give me consuption gas in kWh. But in HA i get the same info that must be in m3. When add in kWh consuption on energy card for GAS is not show. I also has the same version of HA as you.

Have you ever configured an m3 sensor.
HA seems to remember that, and thus dislike you adding kWh at a later stage.
I had to delete my historic m3 data.

1 Like

Today only change in sensor mqtt to m3 than again change to kWh. Now i change device_class to energy and show me gas in kWh… But in my opinion this is not full solution.

Device_class should be as GAS. My provider also on biling convert read meter in m3 to kWh and than calculate it in kWh.

but how i can clear historic data in m3 ?

If you do not need ANY historic data, you can delete the SQL database, and a new one will be created on restart.
If you DO need data (as I did), I went into the database with SQLite and deleted the m3 data.
WARNING do this at your own risk, it can result in a corrupted database, and the loss of data.

Hi

No this is the first time I tried the energy functionality, and the only sensor I’ve used for gas was the one detailed above in kWh.

Seems like it’s still expecting gas values of m3, ft3 etc.

Many thanks

Andy

What’s the easiest way of deleting old data?

I have a load of historical data in m³ and am happy to convert it but have no idea how to get in the database directly currently!

The very easy way is to delete ALL data, by editing configuraton.yaml (or maybe recorder.yaml) and adding:

recorder:
  db_url: sqlite:////home/user/.homeassistant/new_database_file_name

Then restarting HA will create new database of the given name, removing all old historic data (no configuration will be lost - AFAIK)
To revert to the old data, delete the config line, restart HA - the old data should reappear.

The other option I have used is to run sqlite3 from the command line, and poke around.

Something like…

$ sqlite3 home-assistant_v2.db
SQLite version 3.36.0 2021-06-18 18:36:39
Enter ".help" for usage hints.
sqlite> select * from statistics_meta where statistic_id like 'sensor.gas%' ;
23|sensor.gas_consumption_today|recorder|kWh|0|1|
33|sensor.gas_consumption|recorder|m³|0|1|
...

which should help find the right data table. Then

sqlite> select  * from statistics where metadata_id = 33 limit 10;
19972|2021-09-06 22:12:00.196918|33|2021-09-06 21:00:00.000000|||||0.220212499706642|0.220212499706642
20003|2021-09-06 23:12:00.209314|33|2021-09-06 22:00:00.000000|||||0.223174999706642|0.223174999706642
...

will help explore the data and identity what to delete.

To find out what the columns are we can use:

sqlite> pragma table_info(statistics)                                                         ...> ;
0|id|INTEGER|1||1
1|created|DATETIME|0||0
2|metadata_id|INTEGER|0||0
3|start|DATETIME|0||0
4|mean|FLOAT|0||0
5|min|FLOAT|0||0
6|max|FLOAT|0||0
7|last_reset|DATETIME|0||0
8|state|FLOAT|0||0
9|sum|FLOAT|0||0

The issue is HA seems to merge M3 and KWH data into the same table, and there in no easy way I can see of identifying just old M3 data.

So maybe something date based…
Use at your own risk, this could result in a corrupted HA database.

delete * from statistics where metadata_id = 33 and created < '2021/12/31'

The key to sucess will be finding the right table to delete from, and finding the right select statement to remove only the M3 data.

2 Likes

Anyone know when this is coming to live?
Running HA in VM

  • Core 2023.11.2
  • Supervisor 2023.11.0
  • Operating System 11.1
  • Frontend 20231030.2

Energy Dashboard still not allowing me to select my Gas entity reported from Company as kWh

1 Like