From e0a3d013c4efb29ce8fa11a155d7b1079cd3a816 Mon Sep 17 00:00:00 2001 From: Vibe Nuage Agent Date: Sun, 24 May 2026 18:50:14 +0000 Subject: [PATCH 1/3] Fix #3: Preserve gas_daily_kwh sensor on reboot or no new data When there is no new GRDF data or on reboot, the gas_daily_kwh sensor was disappearing. Now it preserves the last known value by reading it from Home Assistant and updating the sensor. This ensures the sensor remains available even when no new data is received. --- apps/meters_to_ha/meters_to_ha.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apps/meters_to_ha/meters_to_ha.py b/apps/meters_to_ha/meters_to_ha.py index b5aaf33..fbd1d43 100755 --- a/apps/meters_to_ha/meters_to_ha.py +++ b/apps/meters_to_ha/meters_to_ha.py @@ -3515,6 +3515,36 @@ def update_grdf_device(self, json_file): update_state_file( self.configuration[STATE_FILE], {"grdf": entity_data} ) + + # Preserve gas_daily_kwh sensor on reboot or no new data (issue #3) + # Try to get the last known value from HA + for daily_sensor in ( + sensor_name_daily_pce_kwh, + sensor_name_daily_generic_kwh, + ): + try: + response = self.open_url(HA_API_SENSOR_FORMAT % (daily_sensor,)) + if isinstance(response, dict) and "state" in response: + # Preserve the last known value + last_daily_kwh = response["state"] + last_attributes = response.get("attributes", {}) + + # Update the sensor to preserve its value + preserve_data = { + "state": last_daily_kwh, + "attributes": { + **last_attributes, + "last_check": now_isostr, + }, + } + r = self.open_url( + HA_API_SENSOR_FORMAT % (daily_sensor,), preserve_data + ) + self.mylog(f"Preserved {daily_sensor}: {last_daily_kwh}") + break + except RuntimeError: + # Sensor doesn't exist yet or is unavailable + pass else: self.mylog( f" update value is {date_time.isoformat()}:" From 4359dd845adefe666ca5047f8d5a9349400c1664 Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 24 May 2026 23:36:11 +0200 Subject: [PATCH 2/3] :bug: Preserve gas_daily_kwh sensor value on reboot or no new data The changes address issue #3 by preserving the gas_daily_kwh sensor value when the application reboots or when no new data is available. This is achieved by retrieving the last known value from Home Assistant and updating the sensor to maintain its state. The changes include formatting improvements and added logging for better debugging. Fixes #3 --- apps/meters_to_ha/meters_to_ha.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/meters_to_ha/meters_to_ha.py b/apps/meters_to_ha/meters_to_ha.py index fbd1d43..438cbad 100755 --- a/apps/meters_to_ha/meters_to_ha.py +++ b/apps/meters_to_ha/meters_to_ha.py @@ -3515,7 +3515,7 @@ def update_grdf_device(self, json_file): update_state_file( self.configuration[STATE_FILE], {"grdf": entity_data} ) - + # Preserve gas_daily_kwh sensor on reboot or no new data (issue #3) # Try to get the last known value from HA for daily_sensor in ( @@ -3523,12 +3523,14 @@ def update_grdf_device(self, json_file): sensor_name_daily_generic_kwh, ): try: - response = self.open_url(HA_API_SENSOR_FORMAT % (daily_sensor,)) + response = self.open_url( + HA_API_SENSOR_FORMAT % (daily_sensor,) + ) if isinstance(response, dict) and "state" in response: # Preserve the last known value last_daily_kwh = response["state"] last_attributes = response.get("attributes", {}) - + # Update the sensor to preserve its value preserve_data = { "state": last_daily_kwh, @@ -3538,9 +3540,12 @@ def update_grdf_device(self, json_file): }, } r = self.open_url( - HA_API_SENSOR_FORMAT % (daily_sensor,), preserve_data + HA_API_SENSOR_FORMAT % (daily_sensor,), + preserve_data, + ) + self.mylog( + f"Preserved {daily_sensor}: {last_daily_kwh}" ) - self.mylog(f"Preserved {daily_sensor}: {last_daily_kwh}") break except RuntimeError: # Sensor doesn't exist yet or is unavailable From c75c8a359ce1d14fd0b7d56983e247ad738e525d Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 24 May 2026 23:48:47 +0200 Subject: [PATCH 3/3] :wrench: Update base image versions for MetersToHA add-on Updated the base image versions from 18.1.1 to 20.1.1 for aarch64, amd64, and armv7 architectures. Also updated the add-on version from v2025.9.3 to v2026.5.3. --- addon_meterstoha/build.yaml | 10 +++++----- addon_meterstoha/config.yaml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/addon_meterstoha/build.yaml b/addon_meterstoha/build.yaml index d92637f..e3cc2a4 100644 --- a/addon_meterstoha/build.yaml +++ b/addon_meterstoha/build.yaml @@ -1,10 +1,10 @@ --- build_from: - aarch64: ghcr.io/hassio-addons/base:18.1.1 - amd64: ghcr.io/hassio-addons/base:18.1.1 - # armhf: ghcr.io/hassio-addons/base:18.1.1 - armv7: ghcr.io/hassio-addons/base:18.1.1 - # i386: ghcr.io/hassio-addons/base:18.1.1 + aarch64: ghcr.io/hassio-addons/base:20.1.1 + amd64: ghcr.io/hassio-addons/base:20.1.1 + # armhf: ghcr.io/hassio-addons/base:20.1.1 + armv7: ghcr.io/hassio-addons/base:20.1.1 + # i386: ghcr.io/hassio-addons/base:20.1.1 # codenotary: # base_image: dummy@dummy.com # signer: dummy@dummy.com diff --git a/addon_meterstoha/config.yaml b/addon_meterstoha/config.yaml index 0838699..7611f96 100644 --- a/addon_meterstoha/config.yaml +++ b/addon_meterstoha/config.yaml @@ -1,6 +1,6 @@ --- name: MetersToHA -version: "v2025.9.3" +version: "v2026.5.3" slug: meterstoha description: MetersToHA add-on for Home Assistant url: https://github.com/mdeweerd/meterstoha