Breina / PowerTagGateway

HomeAssistant integration for EcoStruxure gateways; SmartLink, PowerTag Link and Panel Servers.
MIT License
15 stars 8 forks source link

Duplicate device ID because of truncated Panel Server component serial number #27

Open Wopples opened 1 month ago

Wopples commented 1 month ago

Describe the bug Our PAS800L panel server has serial numbers with a length of 21 characters. When a device is created the integration turuncates the serial number to 20 characters. Devices that have a serial number with only the last character difference have a conflict. I've been looking for a way to shorten the serial number in the panel server, but have not found. Is it possible to increase the length of the device ID or to truncate the serial number at the front if it's to long? Schneider HA Schneider Panel

Versions

Logs extract: 2024-10-28 09:09:03.701 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010wireless communication valid already exists - ignoring binary_sensor.hal_1_1_wireless_communication_valid 2024-10-28 09:09:03.701 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010radio communication valid already exists - ignoring binary_sensor.hal_1_1_radio_communication_valid 2024-10-28 09:09:03.701 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010alarm info already exists - ignoring binary_sensor.hal_1_1_alarm_info 2024-10-28 09:09:03.706 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010wireless communication valid already exists - ignoring binary_sensor.hal_1_1_wireless_communication_valid 2024-10-28 09:09:03.706 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010radio communication valid already exists - ignoring binary_sensor.hal_1_1_radio_communication_valid 2024-10-28 09:09:03.706 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010alarm info already exists - ignoring binary_sensor.hal_1_1_alarm_info 2024-10-28 09:09:03.707 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004wireless communication valid already exists - ignoring binary_sensor.ontkoppelbord_zp_wireless_communication_valid 2024-10-28 09:09:03.708 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004radio communication valid already exists - ignoring binary_sensor.ontkoppelbord_zp_radio_communication_valid 2024-10-28 09:09:03.708 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004alarm info already exists - ignoring binary_sensor.ontkoppelbord_zp_alarm_info 2024-10-28 09:09:03.725 WARNING (MainThread) [homeassistant.helpers.frame] Detected code that calls async_forward_entry_setup for integration powertag_gateway with title: EcoStruxure Panel Server and entry_id: 01JAYV9GJ313NNXT9KT79W8SYF, during setup without awaiting async_forward_entry_setup, which can cause the setup lock to be released before the setup is done. This will stop working in Home Assistant 2025.1. Please report this issue.

Breina commented 1 month ago

Seems to be an oversight on Schneider's end, so I put a message on their forum.

https://community.se.com/t5/Gateways-and-Energy-Servers/PowerTag-serial-numbers-can-be-longer-than-the-modbus-registers/m-p/489073#M4378

I can work around this though, but if I would do it in the codebase, everyone's entities would get duplicated, so I will propose a manual fix that's just for you:

  1. Navigate to custom_components/powertag_gateway/entity_base.py
  2. On line 126, find self._attr_unique_id = f"{TAG_DOMAIN}{serial}{entity_name}
  3. Add {modbus_index} so that this line becomes self._attr_unique_id = f"{TAG_DOMAIN}{serial}{entity_name}{modbus_index}"
  4. Save and restart

Please let me know if that helps!

Wopples commented 1 month ago

I modified the entity_base.py, restarted HA, deleted the entry, restarted HA, reintegrated the entry. The result is the same with the exception that before I had 633 entities and now I have 810. Some are still mapped to the wrong device and not all devices are shown. I checked if the change to entity_base.py was still there after the reintegration and that was the case. I don't have the impression that new devices were created as my frontend views continue to show their data. So the existing entities are unchanged (except for the units that are set back from kW to W). frontend

Enclosed the core log file: home-assistant_2024-10-29T06-51-15.814Z blinded.txt

Wopples commented 3 weeks ago

Hi Breina, Sorry to insist on this subject, but I'm stuck with my project. Help from Schneider will be difficult. Even if they change their serial number format, it would mean that we physicaly will have to change the devices. You indicate that you see a work around but that you don't want to jeperdize the entities of exisiting users. This is ofcoarse of the utmost importance. Is it possible to include a "switch" in the software to activate the workaround? Thanks in advance, Mik

Breina commented 2 weeks ago

Yeah that's a bit annoying how HA does this. You got to remove the integration (remove any lingering entities if there are any), restart and then re-add the integration.

I've added a config flag that applies this new unique_id on fresh setups, as per your suggestion. If you update the integration in HACS first, you no longer have to manually apply the fix.

Wopples commented 2 weeks ago

Hi Breina, I removed Power Tag, deleted all entities and helpers that had a link with the integration and reinstalled 0.5.3 via HACS and reïntegrated (with all necessary restarts). I started with the automatic DPWS discovery. That returned an error. I then chose the manual option, but did not find the "flag". The interface was still the same as before. After setup I still have 10 entities instead of 13. The only difference is that the 3 power tags that were not imported last time because of the truncated serail number are present now instead of the original ones I had before. I checked the core log, but could not see any errors during the setup. Do I have to change something manualy somewhere?

Breina commented 2 weeks ago

Shit sorry, I did a typo. :(

Please try 0.5.4.

The flag is set for all new installations, If you don't see a warning Using older version of device's unique ID, may cause conflicts with duplicate serials. printed, it means that the fix is applied.

kelddamsbo commented 2 weeks ago

I have a PAS600, and this does not work with 0.5.4, I get no data from the PAS600. If I go back to 0,5,3, everything is okay again

Wopples commented 2 weeks ago

Sorry Breina,

Deleted, restarted, installed 1.5.4, restarted, added integration. Manual Panel Server. First went trough without error but also without creating entities. Did a "add entry" again manual Panel server and got "failed to connect".

Core Log: 2024-11-13 10:42:49.401 INFO (MainThread) [custom_components.powertag_gateway.schneider_modbus] Connecting Modbus TCP to xx.xx.x.xxx:502 2024-11-13 10:42:50.447 ERROR (MainThread) [root] Flow aborted: already_configured Traceback (most recent call last): File "/config/custom_components/powertag_gateway/config_flow.py", line 170, in async_step_configure return await self.async_step_connect() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/powertag_gateway/config_flow.py", line 240, in async_step_connect self._abort_if_unique_id_configured() File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2434, in _abort_if_unique_id_configured raise data_entry_flow.AbortFlow(error) homeassistant.data_entry_flow.AbortFlow: Flow aborted: already_configured`

Wopples commented 1 week ago

Hi Breina, 0.5.5 did not change anything for me, but I don't know if that was the intention of the release? I still have 3 entries missing.

Wopples commented 2 days ago

Hi Breina,

I plunged back into this and found that actually all Pannel parameters are present. The cabinets that have the same truncated serial number are grouped into 1 cabinet. As an example, cabinets called "Hal 1-1", "Hal 1-2" and "Hal 3" are all grouped into entity "Hal 3". It takes some rearanging from my part, but I can live with it. Hal 3

Wopples commented 1 day ago

Hi Breina,

Ignore my previous post: I had to restart HA and now all entities are duplicated and the existing ones became unavailable. sensors Log extract: 2024-11-27 16:59:07.382 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'powertag_gateway' calls async_forward_entry_setup for integration, powertag_gateway with title: EcoStruxure Panel Server and entry_id: 01JCQKNJBXF2HNMPZPB3SGHPS9, which is deprecated and will stop working in Home Assistant 2025.6, await async_forward_entry_setups instead at custom_components/powertag_gateway/__init__.py, line 57: await hass.config_entries.async_forward_entry_setup(entry, platform), please create a bug report at https://github.com/Breina/PowerTagGateway/issues 2024-11-27 16:59:13.887 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010wireless communication valid already exists - ignoring binary_sensor.hal_1_1_wireless_communication_valid_2 2024-11-27 16:59:13.887 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010radio communication valid already exists - ignoring binary_sensor.hal_1_1_radio_communication_valid_2 2024-11-27 16:59:13.888 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010alarm info already exists - ignoring binary_sensor.hal_1_1_alarm_info_2 2024-11-27 16:59:13.922 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010wireless communication valid already exists - ignoring binary_sensor.hal_1_1_wireless_communication_valid_2 2024-11-27 16:59:13.923 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010radio communication valid already exists - ignoring binary_sensor.hal_1_1_radio_communication_valid_2 2024-11-27 16:59:13.923 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010alarm info already exists - ignoring binary_sensor.hal_1_1_alarm_info_2 2024-11-27 16:59:13.929 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004wireless communication valid already exists - ignoring binary_sensor.ontkoppelbord_zp_wireless_communication_valid_2 2024-11-27 16:59:13.930 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004radio communication valid already exists - ignoring binary_sensor.ontkoppelbord_zp_radio_communication_valid_2 2024-11-27 16:59:13.930 ERROR (MainThread) [homeassistant.components.binary_sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004alarm info already exists - ignoring binary_sensor.ontkoppelbord_zp_alarm_info_2 2024-11-27 16:59:18.945 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset active energy delivered already exists - ignoring button.hal_1_1_reset_active_energy_delivered_2 2024-11-27 16:59:18.945 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset active energy received already exists - ignoring button.hal_1_1_reset_active_energy_received_2 2024-11-27 16:59:18.945 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset reactive energy delivered already exists - ignoring button.hal_1_1_reset_reactive_energy_delivered_2 2024-11-27 16:59:18.945 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset reactive energy received already exists - ignoring button.hal_1_1_reset_reactive_energy_received_2 2024-11-27 16:59:18.955 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset active energy delivered already exists - ignoring button.hal_1_1_reset_active_energy_delivered_2 2024-11-27 16:59:18.955 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset active energy received already exists - ignoring button.hal_1_1_reset_active_energy_received_2 2024-11-27 16:59:18.956 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset reactive energy delivered already exists - ignoring button.hal_1_1_reset_reactive_energy_delivered_2 2024-11-27 16:59:18.956 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reset reactive energy received already exists - ignoring button.hal_1_1_reset_reactive_energy_received_2 2024-11-27 16:59:18.959 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004reset active energy delivered already exists - ignoring button.ontkoppelbord_zp_reset_active_energy_delivered_2 2024-11-27 16:59:18.959 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004reset active energy received already exists - ignoring button.ontkoppelbord_zp_reset_active_energy_received_2 2024-11-27 16:59:18.960 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004reset reactive energy delivered already exists - ignoring button.ontkoppelbord_zp_reset_reactive_energy_delivered_2 2024-11-27 16:59:18.960 ERROR (MainThread) [homeassistant.components.button] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W10-7-GH-004reset reactive energy received already exists - ignoring button.ontkoppelbord_zp_reset_reactive_energy_received_2 2024-11-27 16:59:34.435 ERROR (MainThread) [homeassistant.components.sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010total active energy already exists - ignoring sensor.hal_1_1_total_active_energy_2 2024-11-27 16:59:34.435 ERROR (MainThread) [homeassistant.components.sensor] Platform powertag_gateway does not generate unique IDs. ID PowerTagRN-2023-W33-4-GH-010reactive power already exists - ignoring sensor.hal_1_1_reactive_power_2