DSMR sensor.gas_meter_gas_consumption disappeared

Has anyone encountered the same issue that the sensor.gas_meter_gas_consumption is changed to sensor.gas_meter_gasverbruik?

I use the DSMR integration to read tha gas consumption.

I’m curious why a sensor name can change. Hope someone can help me to find out why this happened.

Frank

I have the same problem, I have now added “a new entity”. I have to leave the old one, otherwise I will lose my entire history.
gas

Same issue here, HA 2024.8.0 created a new sensor.gas_meter_gas_consumption_2 Would be great if someone has a fix for having the new sensor continue on the original gas_meter_gas_consumption sensor data.

Take a look here: DSMR Breaking after update HA to 2024.8

Same Here, Mine changed from gas_consumption to gas_meter_gas_consumption

Does anyone know how to merge the data from
The old and the new one ?

@Antiloop you can merge them in SQLITE (other methods available).

Most likely you did not notice this “shit can happen” straight away and depending which version you are on you even might not have returned to the default value of the gas meter. v2024.8.2 at least returned to the old situation.

The default value is (in Dutch *) is “sensor.gas_meter_gasverbruik”.
If your situation was like mine you might have a “_2” variant.

From this point onward we should take a copy of our database or even better HA instance and do further testing there, because you might like the challenge you can ignore this remark.

Now it might become tricky:
You might need to delete the entity “sensor.gas_meter_gasverbruik”
and rename entity “sensor.gas_meter_gasverbruik_2” into without “_2”. But please check your present DSMR integration.

Assuming we want to the merge the table “sensor.gas_meter_gasverbruik_2” into “sensor.gas_meter_gasverbruik” we first want to update the SUM values so it is continuous. We can can adjust the sum value with this query:

UPDATE "statistics"
SET sum =  state - <your_start_value>
WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.gas_meter_gasverbruik_2');

Where “your_start_value” is (most likely) equal to the sum value of your first entry of table “sensor.gas_meter_gasverbruik”.

Second step is to merge you tables:

UPDATE "statistics"
SET metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.gas_meter_gasverbruik')
WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.gas_meter_gasverbruik_2');

This actions is most likely to fail due to “UNIQUE constraint failed: statistics.metadata_id, statistics.start_ts” in other words some keys cannot be added twice. To solve this you most likely have to delete the first and/or last record of table ‘sensor.gas_meter_gasverbruik_2’

A delete query is tricky so be careful !!!

DELETE FROM  "statistics"
WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.gas_meter_gasverbruik_2') 
AND start_ts = '<entry to be deleted>'

When you omit one or both where statements you will delete more entries from your database than you want, this is your 2nd warning!!!

If you solved this retry second second step again.

Most likely your table ‘sensor.gas_meter_gasverbruik’ restarted with a zero sum again and this will disrupt your energy dashboard, locate that moment when this happens and use the ‘<start_ts_value>’ in the following two queries:

UPDATE "statistics"
SET sum =  state - your_start_value
WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.gas_meter_gasverbruik') 
AND start_ts >= '<start_ts_value >'

The next query is also required:

UPDATE "statistics_short_term"
SET sum =  state - your_start_value
WHERE metadata_id = (SELECT id FROM statistics_meta WHERE statistic_id = 'sensor.gas_meter_gasverbruik')
AND start_ts >= '<start_ts_value >'

After these actions my energy dashboard was in good shape again, hope yours is also.