Energy Dashboard - Allow Gas as kWh

Hey there. I am aware of that issue but it’s not the same for all users. Some users seem to get kWh via this value while others get m3. We are still investigating on why that is.
There’s a github issue for that btw

I have opened a similar feature request to add more energy sources like wood, water and wind turbines etc. I don’t think the energy dashboard needs to calculate the kWh from the sensor input.

In my case I’m able to and willing to do the conversion outside of the energy dashboard in a sensor.

E.g. I’m connected to the city heat grid for heating and warm tap water.
I have an FHEM installation that get the reading from a wireless MBUS water meter. I have datapoints every other second in m3.
I assume a temperature of the cold water of 10 C. I use this formula: m3 * 2.5 * (60 (C of hot water) - 10 (C of cold water). 10 m3 * 2.5 * (60-10) = 1.250 kWh (which assumes about 50 % efficiency for heater the water).
I could calculate this in fhem and send it by mqtt or I could create a template sensore and calculate it. To balance the consumtion I would also create sensor that “consumes” it and can be displayed with the other indivdual power meters.

Does the Viessmann ViCare Viessmann ViCare - Home Assistant (home-assistant.io) work with the energy dashboard for Gas?

In UK meters measure in cubic meters but billing and tarif is done in kwh. This is for good reasons, first to align costs with electricity, and secondly the calorific value of gas is variable. There is a well established calculation to convert from one to another:

m³ * compensation for temperature and pressure * calorific value in megajoules / conversion factor

typically one cubic metre will be equivalent to:
1m³ * 1.02264 x 39.2 ÷ 3.6 = 11.14kwh
So when inputting your cost per m³ in to the energy integration in Home Assistant multiply your unit rate by 11.14 - This will be correct until the calorific value changes - which it does periodically - I have been doing this in a spreadsheet for multiple years and had the calorific value static, when my calculated billing was not matching the suppliers bill it took me a while to find that calorific value had changed.

The variability of the calorific value is a good enough reason for Home Assistant to accept kwh as a valid measurement for gas

1 Like

It looks like the development branch of HA now allows Gas in kWh.

Hi
Yes it does and it is nearly working .
Existing issues are:

  • Energy coming from grid and coming from gas in kWh are not added in the Total
  • « non fossil » is only the one of grid ( so is wrong as gas is 100% fossil) and calculation should consider « non fossil »/« Total »
  • Even if you choose kWh rather than m3, fixed unit prixe stay as €/m3 while it should be €/kWh
  • Even with an unit price, gas price stays equal to 0

Regards
Phil

Hi

Following my post above, as the displayed value reflects the actual consumption in m3 (using the wrong unit, with kWh), would it make more sense for the integration to force the unit to m3?

Would that not defeat the point of requesting kWh as a unit for gas consumption?

Mine is now plotting correctly the kWh consumption but as others have said the unit price is still in M cubed and does the cost remains £0.

I think we all have the same issue
Please add your comment to that PR or make yours

Phil

@arundalep
not really.
Vicare is one specific case.
some others may need kWh for gas

@pbranly
I don’t see the link between my comment and yours

I have resolved part of the cost issue for GAS in kWh in my development environment…

And have submitted a pull request: https://github.com/home-assistant/core/pull/58426.

1 Like

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