Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions addon_meterstoha/build.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion addon_meterstoha/config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions apps/meters_to_ha/meters_to_ha.py
Original file line number Diff line number Diff line change
Expand Up @@ -3515,6 +3515,41 @@ 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()}:"
Expand Down
Loading