bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
968 stars 257 forks source link

More than 130 powercalc light entities per room. Why? #2418

Closed edmund-1 closed 2 months ago

edmund-1 commented 2 months ago

System Health details

System Information

version core-2024.7.3
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.4
os_name Linux
os_version 6.6.31-haos-raspi
arch aarch64
timezone Europe/Bucharest
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4982 Installed Version | 1.34.0 Stage | running Available Repositories | 1460 Downloaded Repositories | 40 HACS Data | ok
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 12.4 -- | -- update_channel | stable supervisor_version | supervisor-2024.06.2 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 57.8 GB disk_used | 16.7 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | rpi5-64 supervisor_api | ok version_api | ok installed_addons | File editor (5.8.0), Home Assistant Google Drive Backup (0.112.1), Duck DNS (1.18.0), Let's Encrypt (5.0.25), Samba share (12.3.1), Studio Code Server (5.15.0), Advanced SSH & Web Terminal (18.0.0)
Dashboards dashboards | 3 -- | -- resources | 28 views | 15 mode | storage
Recorder oldest_recorder_run | July 19, 2024 at 06:17 -- | -- current_recorder_run | July 28, 2024 at 22:02 estimated_db_size | 986.04 MiB database_engine | sqlite database_version | 3.45.3

Checklist

Describe the issue

Why Powercalc is creating so many entities? image

In integrations there are approx 130 times the group Bedroom and LivingRoom. Kitchen speaker has no issues image

image

Reproduction steps

  1. add lights
  2. group them by room
  3. wait couple of days ...

Debug logs

this is the only reference to powercalc found in debug logs

2024-07-28 22:02:36.438 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration powercalc which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

Diagnostics dump or YAML config

No response

bramstroker commented 2 months ago

Which version of Powercalc are you using? There was a similar bug reported some time ago, I think a month / 2 months ago. But this issue should be fixed. Let's first check if you are on the latest version? Otherwise we'll need to investigate further.

edmund-1 commented 2 months ago

I am on the latest build, isn't it? image

image

image

bramstroker commented 2 months ago

Yes you are on the latest. You are sure there are still new entries added? Could also be an old issue. Powercalc does not automatically clear it up, as HA raises an error when I try that. I can instruct you how to clean it up, but let's first validate if there are no new entries added anymore.

edmund-1 commented 2 months ago

How can I check if new entries are added?

edmund-1 commented 2 months ago

They are added. sensor.livingroom_lights_power_131 was created yesterday at 3:00 (UTC+3)/ At that time I rebooted the HA hardware image

edmund-1 commented 2 months ago

So, it makes sense to clean them up.

bramstroker commented 2 months ago

They are added. sensor.livingroom_lights_power_131 was created yesterday at 3:00 (UTC+3)/ At that time I rebooted the HA hardware image

Hmm ok, that a pitty, was pretty sure the actual issue was solved but apparantly it still persists. Could you provide diagnostics of this config entry? You can do by clicking three dots next to Configure and next click Download diagnostics.

Things can be cleaned up by editing config/.storage/core.config_entries file. Make sure to make a backup before you edit. You can remove all the duplicate entries from the JSON file and restart afterwards.

edmund-1 commented 2 months ago

They are added. sensor.livingroom_lights_power_131 was created yesterday at 3:00 (UTC+3)/ At that time I rebooted the HA hardware image

Hmm ok, that a pitty, was pretty sure the actual issue was solved but apparantly it still persists. Could you provide diagnostics of this config entry? You can do by clicking three dots next to Configure and next click Download diagnostics.

Things can be cleaned up by editing config/.storage/core.config_entries file. Make sure to make a backup before you edit. You can remove all the duplicate entries from the JSON file and restart afterwards.

I have 4 lights in Livingroom (group) and 2 in Bedroom (group). You have all the lights and the first group from each room. As a sidenote, the groups are created automatically, the devices remain the same.

I will let you know the output after the cleaning up procedure.

powercalc.zip

bramstroker commented 2 months ago

Powercalc does a check if config entry with certain unique_id already exists before attempting to create a new one:

https://github.com/bramstroker/homeassistant-powercalc/blob/master/custom_components/powercalc/sensors/group.py#L305

Looking at your diagnostics of the Livingroom Lights config entry I see unique_id is set, but apparently powercalc thinks there is no config entry yet. There must be some flaw in the logic. Could you please also check if unique_id is set for the duplicate entries? Either by looking at diagnostics JSON or directly in config/.storage/core.config_entries?

Screenshot 2024-07-29 at 18 29 26
edmund-1 commented 2 months ago

After cleaning config/.storage/core.config_entries file and deleting 1040 entities and entries in db for those entities, the integration is clean. Hopefully, it will remain that way :) I would wait a couple more days to be sure the issue was fixed before closing the issue.

Thank you @bramstroker for your quick response, fix and support.

image image

bramstroker commented 2 months ago

@edmund-1 glad its resolved for you. Did it stay clean or were new duplicates created again after new restarts?