Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Wopples opened this issue Oct 28, 2024 · 17 comments
Labels
bug Something isn't working

Comments

@Wopples
Copy link

Wopples commented Oct 28, 2024

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

  • HomeAssistant: 2024.10.3
  • Integration: v0.5.0

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.

@Wopples Wopples added the bug Something isn't working label Oct 28, 2024
@Breina
Copy link
Owner

Breina commented Oct 28, 2024

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
Copy link
Author

Wopples commented Oct 29, 2024

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
Copy link
Author

Wopples commented Nov 4, 2024

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
Copy link
Owner

Breina commented Nov 9, 2024

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
Copy link
Author

Wopples commented Nov 12, 2024

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
Copy link
Owner

Breina commented Nov 12, 2024

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
Copy link

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
Copy link
Author

Wopples commented Nov 13, 2024

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
Copy link
Author

Wopples commented Nov 15, 2024

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
Copy link
Author

Wopples commented Nov 26, 2024

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
Copy link
Author

Wopples commented Nov 27, 2024

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

@Wopples
Copy link
Author

Wopples commented Dec 1, 2024

Breina,

New development: I reinstalled version 0.5.3. All entities I need are present. They are not grouped under the right device (I still only have 10 instead of 13), but they are present and I can use them. I can live with this.

Sorry to have put you on the false track. I should have observed this before.

@Breina
Copy link
Owner

Breina commented Dec 7, 2024

That's alright no worries. I didn't really know how to proceed with this, so I didn't update you on progress. I'll leave this open for when I get some inspiration and find your missing 3 entities.

@Wopples
Copy link
Author

Wopples commented Dec 20, 2024

Hey Breina,
I realy appreciate what you are doing! Don't worry about the lost entries for now. I can manage as all entities are there.
A real inconvenience is that everytime I restart HA all entities are duplicated. Everytime I have to delete the entry and add again to let HA use the original entities again.
I'm on 0.5.3.

@Breina
Copy link
Owner

Breina commented Jan 24, 2025

Is it possible that you've been deleting the wrong devices? I can't reproduce them duplicating.

@Wopples
Copy link
Author

Wopples commented Jan 31, 2025

Hey Breina,

Sorry for my late reply.
I don't delete devices, I delete the complete installation, restart and reinstall Powertag to get back to my old devices and entities.
That worked until 0.5.3.
I boldly updated everything today as I was a lot of new updates behind.
HA 2024.10.4->2025.1.4
OS 10.2->14.2
Powertag from 0.5.3->1.5.8
It again mapped the entities to _1 entities, loosing the originals.
I again removed the integration, restarted and reinstallad PowerTag, but now I only see 2 devices and 81 entities, where I had 10 devices and 603 entities before.
I fond this in the log:
This error originated from a custom integration.

Logger: root
Source: custom_components/powertag_gateway/config_flow.py:170
integration: PowerTag Link Gateway (documentation, issues)
First occurred: 15:58:48 (1 occurrences)
Last logged: 15:58:48

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 2668, in _abort_if_unique_id_configured
    raise data_entry_flow.AbortFlow(error)
homeassistant.data_entry_flow.AbortFlow: Flow aborted: already_configured

I removed powertag completely and reinstalled 0.5.3 and now the gateway fails to setup:

`Logger: homeassistant.config_entries
Source: config_entries.py:640
First occurred: 16:26:23 (1 occurrences)
Last logged: 16:26:23

Error setting up entry EcoStruxure Panel Server for powertag_gateway
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/loader.py", line 1272, in _load_platform
cache[full_name] = self._import_platform(platform_name)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/loader.py", line 1304, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/util/loop.py", line 200, in protected_loop_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.13/importlib/init.py", line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "", line 1026, in exec_module
File "", line 488, in _call_with_frames_removed
File "/config/custom_components/powertag_gateway/binary_sensor.py", line 11, in
from .device_features import FeatureClass
File "/config/custom_components/powertag_gateway/device_features.py", line 7, in
class FeatureClass(Enum):
...<15 lines>...
CO2 = auto()
File "/config/custom_components/powertag_gateway/device_features.py", line 22, in FeatureClass
TEMP1 = auto()
^^^^^
File "/usr/local/lib/python3.13/enum.py", line 440, in setitem
v.value = self._generate_next_value(
~~~~~~~~~~~~~~~~~~~~~~~~~^
key, 1, len(self._member_names), self._last_values[:],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.13/enum.py", line 1259, in generate_next_value
raise TypeError('unable to sort non-numeric values') from None
TypeError: unable to sort non-numeric values

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 640, in __async_setup_with_context
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/powertag_gateway/init.py", line 57, in async_setup_entry
await hass.config_entries.async_forward_entry_setup(entry, platform)
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2349, in async_forward_entry_setup
result = await self._async_forward_entry_setup(entry, domain, True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2380, in _async_forward_entry_setup
await integration.async_get_platform(domain)
File "/usr/src/homeassistant/homeassistant/loader.py", line 1108, in async_get_platform
platforms = await self.async_get_platforms((platform_name,))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/loader.py", line 1185, in async_get_platforms
import_future.result()
~~~~~~~~~~~~~~~~~~~~^^
File "/usr/src/homeassistant/homeassistant/loader.py", line 1173, in async_get_platforms
platforms.update(self._load_platforms(platform_names))
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/loader.py", line 1098, in _load_platforms
platform_name: self._load_platform(platform_name)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/loader.py", line 1292, in _load_platform
raise ImportError(
f"Exception importing {self.pkg_path}.{platform_name}"
) from err
ImportError: Exception importing custom_components.powertag_gateway.binary_sensor`

I will now try to revert to my backup in the hope to restore everything to what it was before.

@Wopples
Copy link
Author

Wopples commented Feb 18, 2025

Hi Breina,

Would it be an option to use the Virtual server ID instead of the serial number? According to the Panel Server it is a unique number per device. It would limit the integration to a single Panel Server, but is it likely one would have multiple panel servers on a single Home Assistant instance?
If it would be a problem, then maybe it's possible to construct a unique number form the panel server serial number and the virtual server ID?

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants