idea/confirming code location that energy sensor based on real power sensor (unavailable) to retain its kWh value #3966
Replies: 1 comment
-
|
Yep. that behavior is coming from Home Assistant’s core integration sensor, which Powercalc also uses under the hood. For Powercalc, that can indeed feel a bit counter-intuitive because the accumulated energy value is still “known” (stored) even if the source power drops out briefly. But the decision to mirror availability is a core HA design choice, likely made for consistency with other helpers/derived entities. The exact reasoning (and whether it should change) really needs a HA core maintainer perspective. So: I’d suggest you ask this on the Home Assistant Discord (dev/help channels) or open a HA Core issue/discussion (or comment on an existing one) focusing specifically on the integration helper’s availability. If core changes, Powercalc will automatically benefit. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it true that the code which causes...
the code which causes that behavior lies in the core HA integration. Specifically here:
https://github.com/home-assistant/core/blob/9b30fecb0c76c47a11a0d7218ee67216f8b65d98/homeassistant/components/integration/sensor.py#L537
I think that is the root cause after reading several issues, PwrCalc code, and then HA core integration component.
I'm inquiring because when I use PowerCalc (thank you!) to make a "Energy from real power sensor" and later that real sensor temporarily goes
unavailablethis causes the calculated energy sensor to beunavailable.This to me, is odd behavior since it isn't a real energy value coming from the real device. This isn't a real Shelly EM device which provides its own hardware-based real energy and power values. When that device is unavailable, I understand why both its power and energy are
unavailable.Instead, this PowerCalc energy entity is a constantly integrated and summed value which is stored within the calculated energy entity (its HA integration). And therefore, the energy value is always available to HA in memory and disk since HA does and stores the calculation. Why would HA deny itself data that it already has itself?
Yes, there are edge cases like when one of the endpoints during an integration time interval is
unavailable. Which I think would be resolved by using the already existing 'max_sub_interval' to throw away the one data point it did get when that sub_interval passes. That's how subintervals are designed to work according to https://www.home-assistant.io/integrations/integration/#yaml-configuration where "that at least every max sub-interval, the integral is updated."What are your thoughts on this topic area?
Beta Was this translation helpful? Give feedback.
All reactions