Closed gribber closed 1 year ago
Which version of powercalc are you running? 1.8.0 or 1.8.1?
Which version of powercalc are you running? 1.8.0 or 1.8.1?
1.8.1
I think the problem is not related to the change in configuration, but the change in the way auto discovery is working now.
2023-07-16 09:49:59.133 ERROR (MainThread) [custom_components.powercalc.sensor] Could not resolve any entities in group 'outdoor parking driveway'
You are expecting entities in this area right?
Previously entities were magically created even if you have enable_autodiscovery: false
. In new version this is not the case anymore.
So you just have to add a few lines of yaml to register a library supported entity for powercalc registration.
For example assume you have a light light.parking_light
.
Just add:
sensors:
- entity_id: light.parking_light`
That should create the powercalc sensors for this light, and than it also should be included in the group again when you use the include
option.
I think the problem is not related to the change in configuration, but the change in the way auto discovery is working now.
2023-07-16 09:49:59.133 ERROR (MainThread) [custom_components.powercalc.sensor] Could not resolve any entities in group 'outdoor parking driveway'
You are expecting entities in this area right? Previously entities were magically created even if you have
enable_autodiscovery: false
. In new version this is not the case anymore. So you just have to add a few lines of yaml to register a library supported entity for powercalc registration. For example assume you have a lightlight.parking_light
.Just add:
sensors: - entity_id: light.parking_light`
That should create the powercalc sensors for this light, and than it also should be included in the group again when you use the
include
option.
I have literary hundreds of lights, parking lights consists of about 25, that's why I include lights by area, as some tends to be added/removed all the time
So there is no way to automatically add them without define them all one by one and update the configuration by hand every time somethings changes? Or could I just enable enable_autodiscovery? Not sure why I have that at the moment, I think it was added earlier when we debugged some other issue
EDIT: Enable autodiscovery did not help
hmm I see your issue. I'm sorry that you are bothered dealing with some extra configuration now. This change had been made to make the behaviour more consistent and also the code easier to maintain. When you enable auto discovery items should appear in the GUI, you can just click configure for these and then everything should return to work correctly hopefully.
EDIT: Enable autodiscovery did not help
You'll have to accept the discovered item. As that will make the configuration registered to HA, and powercalc knows it need to setup powercalc sensors for the entity.
When you ignore it powercalc will not setup power entities for that entity.
And also don't include it when using the include
option. Previously it would still setup power sensors, that's one of the reason this change was made.
I see, I guess that's doable Is it possible to rename a energy sensor? When I configured a light, it created duplicates (energy and energy_2, where the only one is unavailable), the power sensor was possible to rename but not the energy as in turned unavailable when I did I want to keep the same name to have the history/statistics left
Not a big problem, just have to remove all old unavailable sensor before I configure each auto discovered light
I'm not sure why you get duplicates. As the unique id of the entities should have stayed the same, and not cause any duplicates.
How were the power sensors named? old and new one?
Could you have a look in config/.storage/core.entity_registry
?
old one
{
"config_entry_id": null,
"entity_id": "sensor.bedroom_left_energy",
"id": "e0965b35fdb6900850b3494d1c518704",
"orphaned_timestamp": 1689498450.8782144,
"platform": "powercalc",
"unique_id": "0x2c1165fffe038a92_light_zigbee2mqtt_energy"
},
new one:
{
"aliases": [],
"area_id": null,
"capabilities": {
"state_class": "total_increasing"
},
"config_entry_id": "65aece4746e2eb662155c8156719de4e",
"device_class": null,
"device_id": "1d9edc4c88480e4de6cc5c34f2fdbd8b",
"disabled_by": null,
"entity_category": null,
"entity_id": "sensor.bedroom_left_energy_2",
"hidden_by": null,
"icon": null,
"id": "6b9435d10a4609ccc8fd1315145f98ca",
"has_entity_name": false,
"name": null,
"options": {
"conversation": {
"should_expose": false
},
"sensor": {
"display_precision": null
}
},
"original_device_class": null,
"original_icon": "mdi:lightning-bolt",
"original_name": "bedroom_left energy",
"platform": "powercalc",
"supported_features": 0,
"translation_key": null,
"unique_id": "pc_0x2c1165fffe038a92_light_zigbee2mqtt_energy",
"unit_of_measurement": null
},
Ah I see.
The unique id should start with pc_
, that's a change I made a long time ago.
Apparently the automatic created entities did not had this unique id structure yet.
HA tries to create entity with id sensor.bedroom_left_energy
, but because it's already taken by the old one, with unique_id 0x2c1165fffe038a92_light_zigbee2mqtt_energy
it renames the entity to _2
.
I will have a look into the code if I can automatically modify the unique id to match the correct pattern, whenever I see an entity which has the old legacy unique_id pattern.
In the meantime you could try doing this yourself manually for an entity by modifying core.entity_registry
file. And change the uniqueid's of powercalc entities to `pc`.
Changing the uuid before works and does not create duplicates
After changing that on one light, I expected the group energy sensors to come online as well, that did not happen, those nested groups are still unavailable outdoor lights (group) -> outdoor ambiance (group) -> conservatory_1 (entity) first two unavailable
root@homeassistant:~# hass-cli state get sensor.outdoor_lights_energy
ENTITY DESCRIPTION STATE CHANGED
sensor.outdoor_lights_energy Utomhusbelysning unavailable 2023-07-16T10:25:38.672963+00:00
root@homeassistant:~# hass-cli state get sensor.outdoor_ambience_energy
ENTITY DESCRIPTION STATE CHANGED
sensor.outdoor_ambience_energy outdoor ambience energy unavailable 2023-07-16T10:25:38.673905+00:00
root@homeassistant:~# hass-cli state get sensor.conservatory_1_energy
ENTITY DESCRIPTION STATE CHANGED
sensor.conservatory_1_energy conservatory_1 energy 0.3206 2023-07-16T10:29:42.416088+00:00
Are the entities shown correctly on the powercalc integration page. Where all the GUI setup entries are shown?
Yeah, that works fine
Ok that looks fine. Do you have debug logs again? I suspect you still have the Could not resolve any entities in group
error.
When you have full debug logs since startup hopefully I can figure out what the issue is.
hmm yes, I see the problem. It's a kind of chicken / egg issue. I see in your logs / and also I see that during debugging that the HA yaml setup routine is always executed first before the GUI config entries are setup. I might have an idea how to resolve. Let me give it a thought and do some testing.
No unfortunately when having a further look into it and debugging you cannot reference powercalc entities defined with the GUI in the YAML include functionality. As during evalutation of the include
options the entities are just not created and not known to powercalc.
So unfortunately I don't really have an easy solution for you now. I will give it some more thought. Might reintroduce the old logic somehow. But it's a hard one as there are so many systems, configurations and setups to consider.
You can either define the entity_id
's explicitely in the YAML which you want to include in your system, or downgrade to 1.7.* for now.
Downgraded, it would be too much to maintain to keep the configuration updated for each light to be worth it
I hope you find a way to solve it, thanks in advance
I wrote some code to correctly include the GUI powercalc sensors when using the YAML include options.
Are you able to test that by installing the master branch?
When this works correctly you'll only have to click the blue button to configure (adopt it in your HA system) when a new light is added and supported by powercalc. Or when a non supported light gets supported. Than it will automatically be added to the group you created with YAML.
Tested, don't think I can see any difference against 1.8.1, groups still not created, attaching the debug log home-assistant_powercalc_2023-07-16T13-12-59.473Z.log
Could you verify first that you are on latest master. Should be commit ec66a909732363d00800b4cac9cd03da4dd98da7
.
You also did still have some entities setup using the GUI right?
When the answer on above both is true I might need to add some extra debug logging to the code.
It is (fell for that one before so I made sure I got the correct one this time :) )
Haha, ok good to know we are on the right version.
Let's focus on 1 entity / area in debugging this.
Which individual entity do you expect in which area group?
For this entity you have setup using discovery now, right? Could you lookup the JSON for that in config/.storage/core.config_entries
?
Let's focus on conservatory_1 then The defined area for that one is dekoration_ute which is included in the sub-group "outdoor ambience" as below: https://github.com/gribber/ha/blob/main/integrations/powercalc.yaml#L3-L17
Added by autodiscovery:
the json for that light (energy):
{
"aliases": [],
"area_id": null,
"capabilities": {
"state_class": "total_increasing"
},
"config_entry_id": "bd9ee80f8dce1e30798d6624545d8db4",
"device_class": null,
"device_id": "2e5f990fc475fa0f1edb75f39cfb806b",
"disabled_by": null,
"entity_category": null,
"entity_id": "sensor.conservatory_1_energy",
"hidden_by": null,
"icon": null,
"id": "385ecf2f868012e2d3f8e4d4fd80c6cd",
"has_entity_name": false,
"name": null,
"options": {
"conversation": {
"should_expose": false
}
},
"original_device_class": null,
"original_icon": "mdi:lightning-bolt",
"original_name": "conservatory_1 energy",
"platform": "powercalc",
"supported_features": 0,
"translation_key": null,
"unique_id": "pc_0x84fd27fffe2ce1d3_light_zigbee2mqtt_energy",
"unit_of_measurement": null
},
Thanks for the information. Looks like you shared information from .storage/core.entity_registry
, needs to be .storage/core.config_entries
. That contains all the data for the GUI configuration options.
But there is an easier way to get that btw, you can also click the three dots and "Download diagnostics".
Thanks for the information. Looks like you shared information from
.storage/core.entity_registry
, needs to be.storage/core.config_entries
. That contains all the data for the GUI configuration options. But there is an easier way to get that btw, you can also click the three dots and "Download diagnostics".
You are correct, here comes the data:
{
"entry_id": "bd9ee80f8dce1e30798d6624545d8db4",
"version": 2,
"domain": "powercalc",
"title": "conservatory_1",
"data": {
"entity_id": "light.conservatory_1",
"manufacturer": "ikea",
"model": "LED2005R5",
"unique_id": "pc_0x84fd27fffe2ce1d3_light_zigbee2mqtt",
"sensor_type": "virtual_power",
"name": "conservatory_1",
"_power_entity": "sensor.conservatory_1_power",
"_energy_entity": "sensor.conservatory_1_energy"
},
"options": {},
"pref_disable_new_entities": false,
"pref_disable_polling": false,
"source": "integration_discovery",
"unique_id": "pc_0x84fd27fffe2ce1d3_light_zigbee2mqtt",
"disabled_by": null
}
Diagnostics file: config_entry-powercalc-bd9ee80f8dce1e30798d6624545d8db4.json.txt
That looks exactly as expected. These are also correct. right?
"_power_entity": "sensor.conservatory_1_power",
"_energy_entity": "sensor.conservatory_1_energy"
Then I might need to add some extra debug logging.
I also changed the debug line Found include entities
to only list the entity_id's and not full objects. Less data and makes it a lot easier to read.
That looks exactly as expected. These are also correct. right?
"_power_entity": "sensor.conservatory_1_power", "_energy_entity": "sensor.conservatory_1_energy"
Yeah that's correct
Can you overwrite config/custom_components/powercalc/group_include/include.py
with the following version https://github.com/bramstroker/homeassistant-powercalc/blob/debug-include/custom_components/powercalc/group_include/include.py?
Added multiple extra logs here. That would hopefully show what goes wrong.
Restart after that and check logs again.
I only see:
Including entities from area: parkering_och_uppfart
Including entities from area: uterum
Including entities from area: garage
These are all the first groups from the nested structure, so that's a pattern there. Need to have a further look into that if I can reproduce. Might be an regression bug in v1.8.
Could you try adding the GUI entry for a sensor for one of these groups and see if the group works correctly again? For example garage
I'm pretty sure the above happens because when no entities could be resolved for an area than it will be considers as an error and stop processing the other entities in the group. Will have a look if we can continue processing the other entities/subgroups in that case.
Didn't we have that problem before as well? I stopped when no lights was resolved in the first group I small bulb lighted up somewhere in my head
including the debug file, added garage_alert from auto discovery home-assistant_powercalc_2023-07-16T15-23-01.115Z.log
Didn't we have that problem before as well? I stopped when no lights was resolved in the first group I small bulb lighted up somewhere in my head
I don't know. Anyways I was able to reproduce with a test and will have a look into fixing that. And that will also prevent any regressions in the future.
including the debug file, added garage_alert from auto discovery home-assistant_powercalc_2023-07-16T15-23-01.115Z.log
That confirmed my suspision:
2023-07-16 17:21:03.396 DEBUG (MainThread) [custom_components.powercalc.group_include.include] Including entities from area: garage
2023-07-16 17:21:03.397 DEBUG (MainThread) [custom_components.powercalc.group_include.include] Found possible include entities: ['light.garage_alert']
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] light.garage_alert: Try to find power sensor
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] light.garage_alert: Walk config entries
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] light.garage_alert: Check config entry bedroom_left
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] light.garage_alert: Check config entry bedroom_right
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] light.garage_alert: Check config entry conservatory_1
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] light.garage_alert: Check config entry garage_alert
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] light.garage_alert: Found config entry garage_alert
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.sensors.group] Creating grouped power sensor: garage power (entity_id=sensor.garage_power)
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.sensors.group] Creating grouped energy sensor: garage energy (entity_id=sensor.garage_energy)
2023-07-16 17:21:03.398 DEBUG (MainThread) [custom_components.powercalc.group_include.include] Including entities from area: teknikrum
Now it sets up garage correctly and also continous to teknikrum.
Continue setting up group on error has been fixed with #1757 Is merged to master.
Confirmed working, now all groups showing again :)
Awesome! Thanks for providing the info and helping debugging this one.
System Health details
System Information
Home Assistant Community Store
GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.32.1 Stage | running Available Repositories | 1275 Downloaded Repositories | 54Home Assistant Cloud
logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | okHome Assistant Supervisor
host_os | Debian GNU/Linux 11 (bullseye) -- | -- update_channel | stable supervisor_version | supervisor-2023.07.1 agent_version | 1.2.1 docker_version | 20.10.21 disk_total | 78.2 GB disk_used | 55.8 GB healthy | true supported | true supervisor_api | ok version_api | ok installed_addons | Studio Code Server (5.8.1), MariaDB (2.6.1), InfluxDB (4.7.0), Mosquitto broker (6.2.1), phpMyAdmin (0.8.7), ESPHome (2023.6.5), Frigate NVR Proxy (1.3), Node-RED (14.3.0), Zigbee2MQTT (1.32.1-1), Network UPS Tools (0.12.0)Husqvarna Automower
can_reach_server | ok -- | --Dashboards
dashboards | 2 -- | -- resources | 31 views | 20 mode | storageRecorder
oldest_recorder_run | July 14, 2023 at 06:32 -- | -- current_recorder_run | July 16, 2023 at 09:49 estimated_db_size | 2121.41 MiB database_engine | mysql database_version | 10.6.12Spotify
api_endpoint_reachable | ok -- | --Checklist
Describe the issue
After the update to 1.8.0 and changes to configuration related to that (removed platform and moved configuration to powercalc->sensors), no entities defined in nested groups are shown anymore Only single entities and single groups are working
Full configuration: new style: https://github.com/gribber/ha/blob/main/integrations/powercalc.yaml old disabled: https://github.com/gribber/ha/blob/main/sensors/powercalc.yaml.disabled
Reproduction steps
Debug logs
Diagnostics dump or YAML config
No response