From 95a5cd26bf04bdc2c7ad25401b2ee7a9a5b9f0b6 Mon Sep 17 00:00:00 2001 From: Jonathan Keljo Date: Mon, 4 Sep 2023 19:11:26 +0000 Subject: [PATCH] Take absolute value of net metered channel Previous versions of this integration were taking the polarized value when net metering was on. Switching to taking the net value resulted in some installations starting to report negative values. While that may have been technically correct, Home Assistant expects positive values to be flowing into the energy dashboard, so we'll take the absolute value. --- custom_components/greeneye_monitor/manifest.json | 2 +- custom_components/greeneye_monitor/sensor.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/greeneye_monitor/manifest.json b/custom_components/greeneye_monitor/manifest.json index c4090e7..91904c0 100644 --- a/custom_components/greeneye_monitor/manifest.json +++ b/custom_components/greeneye_monitor/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/jkeljo/hacs-greeneye-monitor/issues", "loggers": ["greeneye"], "requirements": ["greeneye_monitor==4.1"], - "version": "2023.09.03" + "version": "2023.9.4" } diff --git a/custom_components/greeneye_monitor/sensor.py b/custom_components/greeneye_monitor/sensor.py index 80a1698..6e00d3a 100644 --- a/custom_components/greeneye_monitor/sensor.py +++ b/custom_components/greeneye_monitor/sensor.py @@ -363,6 +363,8 @@ def extra_state_attributes(self) -> dict[str, Any] | None: """Return total wattseconds in the state dictionary.""" if self._net_metering: watt_seconds = self._sensor.net_watt_seconds + if watt_seconds: + watt_seconds = abs(watt_seconds) else: watt_seconds = self._sensor.absolute_watt_seconds @@ -425,7 +427,8 @@ def __init__( def native_value(self) -> float | None: """Return the total number of kilowatt hours measured by this channel.""" if self._net_metering: - return self._sensor.net_kilowatt_hours + net_kwh = self._sensor.net_kilowatt_hours + return abs(net_kwh) if net_kwh else None else: return self._sensor.absolute_kilowatt_hours