homeassistant-powercalc icon indicating copy to clipboard operation
homeassistant-powercalc copied to clipboard

Energy sensors not updating

Open erkr opened this issue 1 year ago • 8 comments
trafficstars

System Health details

Ok

Checklist

  • [X] I have read the FAQ to see if there is a known solution to my problem.
  • [X] I have enabled debug logging for my installation.
  • [X] I have filled out the issue template to the best of my ability.
  • [X] This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • [X] This issue is not a duplicate issue of currently previous issues..

Describe the issue

I'm using the new feature to force energy calculations based on the group power. I noticed these energy sensors don't update as long the group power doesn't change. That is a know issue with riemann sensors, so I guess this group power value isn't updated by a timer (I think you are doing that for individu lights as I noticed this option: force_update_frequency)

Best Eric

Reproduction steps

This Is a config example:

enable_autodiscovery: false
create_energy_sensors: false
create_utility_meters: false

sensors:

    - create_group: woonkamer lights
      unique_id: powercalc_group_woonkamer_lights
      create_energy_sensor: true
      force_calculate_group_energy: true
      entities:
      - entity_id: light.tv_lamp
      - entity_id: light.leeslamp
      - entity_id: light.bureau_koof
      - entity_id: light.zithoek
     ...

Debug logs

Na

Diagnostics dump or YAML config

No response

erkr avatar Apr 08 '24 13:04 erkr

For the individual power sensors Powercalc forces a state update to let the Riemann sensor do it's work. The group sensors doesn't however. I saw some developments at HA core where there will be a time based implementation. So I suggest to wait for that development (probably next month release), as there would probably not be a hack needed which I implemented for the virtual power sensors.

bramstroker avatar Apr 08 '24 14:04 bramstroker

Yes the real issue is definitely in the riemann integration. And the author initially (two years ago) even didn't agree it was a bug. I'm following that timer fix for months now, but don't share your optimism when it will be in 😏 If it is a lot of work for you I agree to wait! Otherwise it would be helpful as a temporary fix

erkr avatar Apr 08 '24 14:04 erkr

There is actively being worked on seeing the latest pull requests:

https://github.com/home-assistant/core/pull/110685 https://github.com/home-assistant/core/pull/113932

bramstroker avatar Apr 08 '24 14:04 bramstroker

Yes, we are monitoring the same change 🤞

erkr avatar Apr 08 '24 14:04 erkr

Didn't make it for 2024.5.0 😳

erkr avatar May 01 '24 19:05 erkr

The Riemann pull request finally made progress 🥳

erkr avatar May 30 '24 16:05 erkr

The Riemann pull request finally made progress 🥳

Nice!

bramstroker avatar Jun 02 '24 06:06 bramstroker

I didn't update yet, but I guess it's in the release.

erkr avatar Jun 08 '24 17:06 erkr

Hi @bramstroker The configuration option 'max_sub_interval' finally made it into core 2024.7🥳 Reading the power calc release notes, I didn't spot it you already use them, in particular for these energy group sensors that monitor the group power instead of summing up individual energy sensors. If you can confirm it is in, I will switch over from my manual Riemann sensors and evaluate 🤗

erkr avatar Jul 07 '24 18:07 erkr

Hi @erkr. nice I did notice it, but didn't adapt the powercalc configuration yet to it.

Just made a PR which should do it. #2365

Essentially it just sets max_sub_interval to same value as Powercalc's force_update_frequency option. https://homeassistant-powercalc.readthedocs.io/en/latest/configuration/global-configuration.html

This will make both the riemann group sensor made with force_calculate_group_energy and all other riemann sensors created by powercalc set the max_sub_interval to the same value, and enabling timed based updates.

You can try it out by installing master branch.

bramstroker avatar Jul 07 '24 19:07 bramstroker

Hi nice you are working on it. I can't install the master version for some reason. It seems that the Riemann sensors have a default for max-sub-interval , as the group energie sensors now seem to update already. In the picture below at the arrow I updated to 2024.7 image

The various light groups now have more continuous energy values per hour.

Left of the arrow, the energy values are more in big chunks. Only reported when a value was changed

erkr avatar Jul 07 '24 21:07 erkr

I replaced my manual Riemann entities with powercalc groups. Interesting that latest powercalc version without adaptions already works in 2024.7. Some nice examples: image image

Feel free to close the issue once you read this 🥳

erkr avatar Jul 08 '24 06:07 erkr

Ah cool, it's a bit strange however, because looking into the code it should only enable timed based integration when explicitely passed. https://github.com/home-assistant/core/blob/dev/homeassistant/components/integration/sensor.py#L336

bramstroker avatar Jul 08 '24 07:07 bramstroker

I don't understand that code well enough to judge. I noticed in your latest version you set that attribute to None, could that trigger the default?

erkr avatar Jul 08 '24 10:07 erkr

That code means max sub interval is set to None # disable time based integration, when passed as none or when timedelta equals 0. So I don't see how it can enable timed interval. But hey... it works ;-) I'll have a look in a few days when I have some more spare time to see why.

bramstroker avatar Jul 08 '24 17:07 bramstroker

I did have a look into the rieman helper code. One other change besides forces periodic integration (on time), also the energy sensor is calculated when a state change is "reported". This means the power sensor reports a state change to the state machine. Previously this was only handled when the power sensor state actually was recorded and actually changed.

So that would be the reason it was working for you already because powercalc power sensors report there state every know and then, this triggers the integration now.

But with my change also the scenario is covered when the power sensor stays fixed but does not report frequent state.

bramstroker avatar Jul 12 '24 06:07 bramstroker

Well that explains. I didn't know your group power sensors where reporting state as that requires some extra timer as well. Thanks for looking into this 😁

erkr avatar Jul 12 '24 08:07 erkr