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

Duplicated entities when using home-assistant-matter-hub #2709

Open
digiolin opened this issue Dec 2, 2024 · 11 comments
Open

Duplicated entities when using home-assistant-matter-hub #2709

digiolin opened this issue Dec 2, 2024 · 11 comments

Comments

@digiolin
Copy link

digiolin commented Dec 2, 2024

IMPORTANT: Please search the issues, including closed issues, and the FAQ before opening a new issue. The template is mandatory; failure to use it will result in issue closure.

Describe the bug

I started to use this AddOn that creates a Matter Hub and devices can be controlled locally via Alexa, without using Skills etc:
https://github.com/t0bst4r/home-assistant-matter-hub/

Your application has logic already to handle devices added via the official Alexa Integration when using Include devices connected via Echo.

I cretead this issue also in here so it can be worked together to find a good solution:
t0bst4r/home-assistant-matter-hub#245

Here an example of a debug logs from a switch device:

{
    "applianceId": "AAA_SonarCloudService_<void>",
    "endpointTypeId": "",
    "driverIdentity": {
        "namespace": "AAA",
        "identifier": "SonarCloudService"
    },
    "manufacturerName": "TestVendor",
    "friendlyDescription": "TestVendor smart device",
    "modelName": "",
    "deviceType": "",
    "version": "0",
    "friendlyName": "Camara",
    "friendlyNameModifiedAt": 1733084691197,
    "capabilitiesModifiedAt": 1733084691197,
    "ipAddress": "",
    "port": "",
    "entityId": "<void>",
    "applianceNetworkState": {
        "reachability": "REACHABLE",
        "lastSeenAt": 1733130114179,
        "createdAt": 1733084691197,
        "lastSeenDiscoverySessionId": {
            "value": "<void>"
        }
    },
    "tags": {
        "tagNameToValueSetMap": {}
    },
    "additionalApplianceDetails": {
        "additionalApplianceDetails": {}
    },
    "firmwareVersion": "0",
    "actions": [],
    "capabilities": [
        {
            "capabilityType": "AVSInterfaceCapability",
            "type": "AlexaInterface",
            "version": "3",
            "properties": {
                "supported": [
                    {
                        "name": "powerState"
                    }
                ],
                "proactivelyReported": true,
                "retrievable": true,
                "readOnly": false
            },
            "interfaceName": "Alexa.PowerController"
        },
        {
            "capabilityType": "AVSInterfaceCapability",
            "type": "AlexaInterface",
            "version": "3",
            "properties": {
                "supported": [
                    {
                        "name": "connectivity"
                    }
                ],
                "proactivelyReported": true,
                "retrievable": true,
                "readOnly": false
            },
            "interfaceName": "Alexa.EndpointHealth"
        }
    ],
    "applianceTypes": [
        "SMARTPLUG"
    ],
    "isEnabled": true,
    "aliases": [],
    "connectedVia": "Echo Comedor",
    "alexaDeviceIdentifierList": [],
    "applianceKey": "<void>",
    "identifiers": {},
    "applianceDriverIdentity": {
        "namespace": "AAA",
        "identifier": "SonarCloudService"
    },
    "ipaddress": "",
    "applianceLambdaControlled": true,
    "mergedApplianceIds": [
        "AAA_SonarCloudService_<void>"
    ]
}

Maybe an option to exclude a likst of manufacturers or any other specific key will be useful.

  1. Setup new matther hub using https://github.com/t0bst4r/home-assistant-matter-hub/
  2. Enable Include devices connected via Echo
  3. Duplicated instances will show up all over the place

Expected behavior

Screenshots

System details

  • Home Assistant version: latest
  • alexa_media version (from const.py or HA startup log): latest
  • alexapy version (from pip show alexapy in homeasssistant container or HA startup log): latest
  • Is Amazon 2FA/2SV enabled <!---We will not debug login issues if unanswered---> (y/n): y
  • Amazon Domain: es

Debug Logs (alexa_media & alexapy)
Please provide logs.

Additional context

@t0bst4r
Copy link

t0bst4r commented Dec 2, 2024

I don’t think we can do anything about it in the hub. I will check why the manufacturer is "TestVendor" instead of "t0bst4r", but that‘s all I can do here…

On the other hand, I don’t think there is a clean automated way for alexa-media-player to decide which devices to exclude or include.
To solve this, there needs to be a way to tell alexa-media-player which ones to exclude.

@danielbrunt57
Copy link
Collaborator

I had a similar issue with my TP-Link devices (2 smart light bulbs) as I have the TP-Link skill in Alexa as well as the TP-Link Integration in HA and AMP was re-adding Nightstand Lamp 1 and Nightstand Lamp 2.

Since I only had 2, I excluded them:
image

I've just had a look at the Matter Hub add-on and installed it but haven't configured a bridge yet.

I'm wondering what info if any uniquely identifies these Matter Hub devices connected via Echo?
Here?

    "applianceId": "AAA_SonarCloudService_<void>",
    "endpointTypeId": "",
    "driverIdentity": {
        "namespace": "AAA",
        "identifier": "SonarCloudService"
    },

or...

    "applianceDriverIdentity": {
        "namespace": "AAA",
        "identifier": "SonarCloudService"
    },

My two TP-Link lights appear in AMP debug logs as:

"light":[
   {
      "id":"a8e7ea9b-bddf-450e-a102-9416ca634834",
      "appliance_id":"AAA_SonarCloudService_fd0ff205-efa9-4be1-8581-eac04293d011:f0c6f807e5d6b2ba0395e2580b8623d6",
      "name":"Nightstand Lamp 1",
      "is_hue_v1":false,
      "brightness":true,
      "color":true,
      "color_temperature":true
   },
   {
      "id":"a58e580c-4d4a-4b27-82cf-0f175fa80a38",
      "appliance_id":"AAA_SonarCloudService_fd0ff205-efa9-4be1-8581-eac04293d011:2a24c46615e5ebb145d96becc457233b",
      "name":"Nightstand Lamp 2",
      "is_hue_v1":false,
      "brightness":true,
      "color":true,
      "color_temperature":true
   }
]

I'll add a bridge for just those two lights and have a look at resulting debug logs...

@danielbrunt57
Copy link
Collaborator

Home Assistant Smart Home Skill (via alexa: smart_home:)
(these are not "Discover devices connected via Echo")
Nightstand Lamp 2:

"SKILL_eyJza2lsbElkIjoiYW16bjEuYXNrLnNraWxsLmRkMWIyMjU5LTE4MTgtNDQ3OS1iOGVmLWJmOWE3ZDkxZTgyOCIsInN0YWdlIjoiZGV2ZWxvcG1lbnQifQ==_light#nightstand_lamp_2":{
   "applianceId":"SKILL_eyJza2lsbElkIjoiYW16bjEuYXNrLnNraWxsLmRkMWIyMjU5LTE4MTgtNDQ3OS1iOGVmLWJmOWE3ZDkxZTgyOCIsInN0YWdlIjoiZGV2ZWxvcG1lbnQifQ==_light#nightstand_lamp_2",
   "endpointTypeId":"",
   "driverIdentity":{
      "namespace":"SKILL",
      "identifier":"eyJza2lsbElkIjoiYW16bjEuYXNrLnNraWxsLmRkMWIyMjU5LTE4MTgtNDQ3OS1iOGVmLWJmOWE3ZDkxZTgyOCIsInN0YWdlIjoiZGV2ZWxvcG1lbnQifQ=="
   },
   "manufacturerName":"Home Assistant",
   "friendlyDescription":"light.nightstand_lamp_2 via Home Assistant",
   "modelName":"",
   "deviceType":"CLOUD_DISCOVERED_DEVICE",
   "version":"0",
   "friendlyName":"Nightstand Lamp 2",
   "friendlyNameModifiedAt":1715989459116,
   "capabilitiesModifiedAt":1715989459116,
   "ipAddress":"",
   "port":"",
   "entityId":"3edebc66-7e84-4142-8ec7-191529e6c014",
   "applianceNetworkState":{
      "reachability":"REACHABLE",
      "lastSeenAt":1733138322052,
      "createdAt":1715989459116,
      "lastSeenDiscoverySessionId":{
         "value":"7d22d25c-a36a-4b14-81d8-8f7e4e421579"
      }
   },

TP-Link Skill
Nightstand Lamp 2:

"AAA_SonarCloudService_fd0ff205-efa9-4be1-8581-eac04293d011:2a24c46615e5ebb145d96becc457233b":{
   "applianceId":"AAA_SonarCloudService_fd0ff205-efa9-4be1-8581-eac04293d011:2a24c46615e5ebb145d96becc457233b",
   "endpointTypeId":"",
   "driverIdentity":{
      "namespace":"AAA",
      "identifier":"SonarCloudService"
   },
   "manufacturerName":"TP-LINK",
   "friendlyDescription":"TP-LINK smart device",
   "modelName":"",
   "deviceType":"",
   "version":"0",
   "friendlyName":"Nightstand Lamp 2",
   "friendlyNameModifiedAt":1715380591165,
   "capabilitiesModifiedAt":1733138084512,
   "ipAddress":"",
   "port":"",
   "entityId":"a58e580c-4d4a-4b27-82cf-0f175fa80a38",
   "applianceNetworkState":{
      "reachability":"REACHABLE",
      "lastSeenAt":1733138322052,
      "createdAt":1715380591165,
      "lastSeenDiscoverySessionId":{
         "value":"7d22d25c-a36a-4b14-81d8-8f7e4e421579"
      }
   },

Matter Hub
Nightstand Lamp 1:

"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#3":{
   "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#3",
   "endpointTypeId":"",
   "driverIdentity":{
      "namespace":"AAA",
      "identifier":"SonarCloudService"
   },
   "manufacturerName":"TestVendor",
   "friendlyDescription":"TestVendor smart device",
   "modelName":"",
   "deviceType":"",
   "version":"0",
   "friendlyName":"Nightstand Lamp 1",
   "friendlyNameModifiedAt":1733138228207,
   "capabilitiesModifiedAt":1733138228207,
   "ipAddress":"",
   "port":"",
   "entityId":"84f6f292-959d-4e72-8bbc-6e50f51964fa",
   "applianceNetworkState":{
      "reachability":"REACHABLE",
      "lastSeenAt":1733138322052,
      "createdAt":1733138228207,
      "lastSeenDiscoverySessionId":{
         "value":"89543536-9013-42c2-b6a8-efdc57608bf1"
      }
   },

Nightstand Lamp 2:

"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#4":{
   "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#4",
   "endpointTypeId":"",
   "driverIdentity":{
      "namespace":"AAA",
      "identifier":"SonarCloudService"
   },
   "manufacturerName":"TestVendor",
   "friendlyDescription":"TestVendor smart device",
   "modelName":"",
   "deviceType":"",
   "version":"0",
   "friendlyName":"Nightstand Lamp 2",
   "friendlyNameModifiedAt":1733138228209,
   "capabilitiesModifiedAt":1733138228209,
   "ipAddress":"",
   "port":"",
   "entityId":"c7899879-e9b8-4309-8553-118bbd9e8351",
   "applianceNetworkState":{
      "reachability":"REACHABLE",
      "lastSeenAt":1733138322052,
      "createdAt":1733138228209,
      "lastSeenDiscoverySessionId":{
         "value":"89543536-9013-42c2-b6a8-efdc57608bf1"
      }
   },

I managed to spot this is the logs also:

"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299":{
   "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299",
   "endpointTypeId":"",
   "driverIdentity":{
      "namespace":"AAA",
      "identifier":"SonarCloudService"
   },
   "manufacturerName":"t0bst4r",
   "friendlyDescription":"t0bst4r smart device",
   "modelName":"",
   "deviceType":"",
   "version":"0",
   "friendlyName":"Test Bridge",
   "friendlyNameModifiedAt":1733138228209,
   "capabilitiesModifiedAt":1733138228209,
   "ipAddress":"",
   "port":"",
   "entityId":"b3fd978e-92b8-4053-aae6-403f5fbc7fd0",
   "applianceNetworkState":{
      "reachability":"REACHABLE",
      "lastSeenAt":1733138322052,
      "createdAt":1733138228209,
      "lastSeenDiscoverySessionId":{
         "value":"89543536-9013-42c2-b6a8-efdc57608bf1"
      }
   },
   "tags":{
      "tagNameToValueSetMap":{
         
      }
   },
   "additionalApplianceDetails":{
      "additionalApplianceDetails":{
         
      }
   },
   "firmwareVersion":"0",
   "actions":[
      
   ],
   "capabilities":[
      {
         "type":"AlexaInterface",
         "version":"1.0",
         "properties":{
            "supported":[
               
            ],
            "proactivelyReported":false,
            "retrievable":false,
            "nonControllable":false
         },
         "capabilityType":"AlexaEndpointCapabilityInstance",
         "interfaceName":"Alexa.Commissionable"
      },
      {
         "type":"AlexaInterface",
         "version":"1.0",
         "properties":{
            "supported":[
               
            ],
            "proactivelyReported":false,
            "retrievable":false,
            "nonControllable":false
         },
         "capabilityType":"AlexaEndpointCapabilityInstance",
         "interfaceName":"Alexa.Matter.NodeOperationalCredentials.FabricManagement"
      },
      {
         "capabilityType":"AVSInterfaceCapability",
         "type":"AlexaInterface",
         "version":"3",
         "properties":{
            "supported":[
               {
                  "name":"connectivity"
               }
            ],
            "proactivelyReported":true,
            "retrievable":true,
            "readOnly":false
         },
         "interfaceName":"Alexa.EndpointHealth"
      }
   ],
   "applianceTypes":[
      "HUB"
   ],
   "isEnabled":true,
   "aliases":[
      
   ],
   "connectedVia":"Kitchen Echo Dot",
   "alexaDeviceIdentifierList":[
      
   ],
   "applianceKey":"b3fd978e-92b8-4053-aae6-403f5fbc7fd0",
   "identifiers":{
      "networkInterfaceIdentifiers":[
         {
            "identifierType":"MatterNetworkInterfaceIdentifier",
            "type":"MATTER",
            "matterVendorId":"65521",
            "matterProductId":"32768",
            "matterDiscriminator":"0"
         }
      ]
   },
   "applianceDriverIdentity":{
      "namespace":"AAA",
      "identifier":"SonarCloudService"
   },
   "ipaddress":"",
   "applianceLambdaControlled":true,
   "mergedApplianceIds":[
      "AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299"
   ]
}

All of the above is in the single, multi-page log entry from the get_network_details:

2024-12-02 03:18:42.212 DEBUG (MainThread) [alexapy.alexaapi] d****l@b******a: static GET: https://alexa.amazon.ca/api/phoenix returned 200:OK:application/json
2024-12-02 03:18:42.212 DEBUG (MainThread) [alexapy.alexaapi] api_calls: 4
2024-12-02 03:18:42.258 DEBUG (MainThread) [alexapy.alexaapi] d****l@b******a: get_network_details response:

It will take some analyzing/debugging to track down where the logic is that handles devices added via the official Alexa Integration when using Include devices connected via Echo...

@digiolin
Copy link
Author

digiolin commented Dec 2, 2024

Thanks @danielbrunt57, good analysis. Let me try to find a way of improving the exclude and include in AMP, it should be something regex compatible or at least a yaml on which we can specify any key and value to include/exclude.

As soon as @t0bst4r changes the manufacturer in its code: t0bst4r/home-assistant-matter-hub#245 (comment)

We can just filter out by manufacturer and that's it, I think that it will be better to give to users the freedom and choose by their own what to include/exclude other than harcoding it 🤔

@digiolin
Copy link
Author

digiolin commented Dec 2, 2024

@danielbrunt57 I thought that I added the link of the code wher this logic is implemented.

https://github.com/alandtse/alexa_media_player/blob/master/custom_components/alexa_media/alexa_entity.py

@danielbrunt57
Copy link
Collaborator

To solve this, there needs to be a way to tell alexa_media which ones to exclude.

There is but it is a comma separated list of friendly names to be excluded, which is not feasible if you are using Matter Hub to provide Alexa with all desired devices!

image

@danielbrunt57
Copy link
Collaborator

@danielbrunt57 I thought that I added the link of the code wher this logic is implemented.

https://github.com/alandtse/alexa_media_player/blob/master/custom_components/alexa_media/alexa_entity.py

Thanks but I had already looked there straight away and found it.
It simply excludes if connectedVia is blank and connectedVia is only blank for the Alexa Smart Home skill.

    if appliance.get("connectedVia"):
        # connectedVia is a flag that determines which Echo devices holds the connection. Its blank for
        # skill derived devices and includes an Echo name for zigbee and local devices.
        return True

The comment needs to be corrected as it is inaccurate and very misleading!

@danielbrunt57
Copy link
Collaborator

My first thought is:
The user needs to somehow specify the name of the bridge to exclude.
That friendlyName is here:

"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299":{
   "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299",
   "endpointTypeId":"",
   "driverIdentity":{
      "namespace":"AAA",
      "identifier":"SonarCloudService"
   },
   "manufacturerName":"t0bst4r",
   "friendlyDescription":"t0bst4r smart device",
   "modelName":"",
   "deviceType":"",
   "version":"0",
   "friendlyName":"Test Bridge",

From there, if we can get the applianceId for the bridge, then perhaps we can exclude devices with that applianceId prefix?
Bridge: "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299"
Nightstand Lamp 2: "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#4"

@danielbrunt57
Copy link
Collaborator

or at least a yaml on which we can specify any key and value to include/exclude.

FYI, AMP YAML Configuration has/is being deprecated and 5.0.0 now issues a warning to that effect.
Alan failed to provide me with version numbers for the warning so my PR says v4.14.0 will eliminate it but he jumped from 4.13.8 to 5.0.0 on the latest merge/release! I'm not sure now which next version will totally ignore it but it definitely will be gone soon.

@digiolin
Copy link
Author

digiolin commented Dec 2, 2024

My first thought is: The user needs to somehow specify the name of the bridge to exclude. That friendlyName is here:

"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299":{
   "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299",
   "endpointTypeId":"",
   "driverIdentity":{
      "namespace":"AAA",
      "identifier":"SonarCloudService"
   },
   "manufacturerName":"t0bst4r",
   "friendlyDescription":"t0bst4r smart device",
   "modelName":"",
   "deviceType":"",
   "version":"0",
   "friendlyName":"Test Bridge",

From there, if we can get the applianceId for the bridge, then perhaps we can exclude devices with that applianceId prefix? Bridge: "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299" Nightstand Lamp 2: "applianceId":"AAA_SonarCloudService_6efb805b-4d08-39ad-b0bd-282250ea5299#4"

That makes complete senses, I see all devices named like with <applianceId of matter-hub>#<int>

As a user we can control the name of the hub that it shows as friendlyName, this can lead us to find a way to filter out by hub, but this needs a new logic that is still not in place right?

@danielbrunt57
Copy link
Collaborator

As a user we can control the name of the hub that it shows as friendlyName, this can lead us to find a way to filter out by hub, but this needs a new logic that is still not in place right?

Correct! In addition to that, the user will need a way to somehow input that "skill" friendly name exclusion into AMP UI config.
Currently, exclude_devices is the friendly name but only the friendly name of the device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants