Unable to commission a TP Link Tapo P125M over Matter with a Home Assistant Container instance and python-matter-server

I have a a TP Link Tapo P125M that supports the new matter standard, and I’m trying to connect it (With it also being connected to Apple and Google Home) to my Dockerized instance of Home Assistant using the following docker-compose code and the git repo for python-matter-server:

networks:
  homeassistant:
    name: homeassistant
  a-lan:
    driver: macvlan
    driver_opts:
      parent: enp2s0
    ipam:
      config:
        - subnet: 192.168.1.0/24
          gateway: 192.168.1.1

services:
  homeassistant:
    mac_address: D2-54-BD-D1-83-C0
    container_name: homeassistant
    hostname: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - /docker/home-assistant/data/:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    ports:
      - '8123:8123'
      - '5060:5060'
    privileged: true
    devices:
      - '/dev/ttyUSB0'
    networks:
      a-lan:
        ipv4_address: 192.168.1.2  
      homeassistant:

  matter-server:
    hostname: matter-server
    mac_address: D2-C8-9C-B1-50-2A
    build:
      context: /docker/python-matter-server/
      dockerfile: Dockerfile.dev
    image: matter-server:latest
    container_name: matter-server
    restart: unless-stopped
    # Required for mDNS to work correctly
    security_opt:
      # Needed for Bluetooth via dbus
      - apparmor:unconfined
    volumes:
      - /docker/matter-server/data:/data/
      - /run/dbus:/run/dbus:ro
    ports:
      - 5580:5580
    networks:
      homeassistant:
      a-lan:
        ipv4_address: 192.168.1.4

Whenever I try to add the plug from my Android phone’s settings and selecting the Home Assistant app, the matter server’s logs print out something complaining about mDNS:

2023-05-30 13:13:42 matter-server matter_server.server.vendor_info[1] INFO Loading vendor info from storage.
2023-05-30 13:13:42 matter-server matter_server.server.vendor_info[1] INFO Loaded 73 vendors from storage.
2023-05-30 13:13:42 matter-server matter_server.server.vendor_info[1] INFO Fetching the latest vendor info from DCL.
2023-05-30 13:13:43 matter-server matter_server.server.vendor_info[1] INFO Fetched 73 vendors from DCL.
2023-05-30 13:13:43 matter-server matter_server.server.vendor_info[1] INFO Saving vendor info to storage.
2023-05-30 13:14:23 matter-server matter_server.server.helpers.paa_certificates[1] INFO Fetching the latest PAA root certificates from DCL.
2023-05-30 13:14:23 matter-server matter_server.server.helpers.paa_certificates[1] INFO Fetched 0 PAA root certificates from DCL.
2023-05-30 13:14:23 matter-server matter_server.server.helpers.paa_certificates[1] INFO Fetching the latest PAA root certificates from Git.
2023-05-30 13:14:23 matter-server matter_server.server.helpers.paa_certificates[1] INFO Fetched 0 PAA root certificates from Git.
/usr/local/lib/python3.11/asyncio/events.py:73: RuntimeWarning: coroutine 'StorageController.async_save' was never awaited
  self._args = None
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2023-05-30 13:14:23 matter-server chip.CTL[1] INFO Setting attestation nonce to random value
2023-05-30 13:14:23 matter-server chip.CTL[1] INFO Setting CSR nonce to random value
2023-05-30 13:14:23 matter-server chip.CTL[1] INFO Starting commissioning discovery over BLE
2023-05-30 13:14:23 matter-server chip.CTL[1] INFO Starting commissioning discovery over DNS-SD
2023-05-30 13:14:23 matter-server chip.DL[1] ERROR FAIL: NULL apEndpoint->mpAdapter in bluezObjectsSetup
2023-05-30 13:14:23 matter-server chip.CTL[1] ERROR Commissioning discovery over BLE failed: src/platform/Linux/BLEManagerImpl.cpp:682: CHIP Error 0x00000003: Incorrect state
2023-05-30 13:14:23 matter-server chip.-[1] ERROR src/platform/Linux/BLEManagerImpl.cpp:682: CHIP Error 0x00000003: Incorrect state at src/controller/SetUpCodePairer.cpp:299
2023-05-30 13:14:23 matter-server chip.BLE[1] ERROR No adapter available for new connection establishment
2023-05-30 13:14:53 matter-server chip.CTL[1] ERROR Discovery timed out
2023-05-30 13:14:53 matter-server chip.ZCL[1] ERROR Secure Pairing Failed
2023-05-30 13:14:53 matter-server matter_server.server.client_handler[1] ERROR [140564957005648] Error handling message: CommandMessage(message_id='c6daefa599864b21b425d39012476fd3', command='commission_with_code', args={'code': '32171844344'})
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/matter_server/server/client_handler.py", line 188, in _run_handler
    result = await result
             ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/matter_server/server/device_controller.py", line 154, in commission_with_code
    raise NodeCommissionFailed(
matter_server.common.errors.NodeCommissionFailed: Commission with code failed for node 13
2023-05-30 13:14:54 matter-server chip.DIS[1] ERROR Timeout waiting for mDNS resolution.

My network is currently segmented into a main network (That Home Assistant is on), and an IoT network (Where all my other smart home devices, including the Matter plug) through a Pfsense firewall with Avahi and mDNS reflection enabled, as well as firewall rules for allowing communication with the home assistant instance and the matter server over ipv4 and ipv6, and denying communication with anything else on the main network. And so far, I’ve tried deleting the file starting with chip_, but that didn’t work.

Months ago it was working flawlessly, then after one of the addon upgrades I ran into something like this: Unable to connect the TP-Link Tapo P125M outlet using the Matter integration · Issue #90011 · home-assistant/core · GitHub. And it hasn’t worked since :man_shrugging:

One of the tips I’ve seen is to do a full factory reset before trying to re-pair (holding the power button for 5s resets wifi, keep holding for 10s for a full reset). Every now and then I take it back out of the closet and see if anything’s changed but no dice yet. I didn’t get this far but it has some reported troubles with multi-admin as well: TP-Link Tapo P125M review: Matter smart plug reveals cracks in the new smart home standard - The Verge

I know matter’s in early stages but this is off to a rockier start then I expected.

I just received my “Model Tapo P125M(US) Ver: 1.6” (from label on box) today and tried to add it using the Home Assistant Android app using the Matter integration (the device was detected). It brought up the tp-link image, but failed to add the device. I gave it a retry or two and no success.

I then installed the TP-Link Tapo app on Android from Google Play, logged in, and was able to add the device. I also checked and there was a firmware update, so I applied it.

I then returned to Home Assistant, tried to add it again, and this time success (the tp-link icon had a bunch of color shapes circling the image of the switch while it set up, the colors were missing in the failed attempts).

The switch works as expected on a dashboard.

Home Assistant reports the following for the P125M:
Device info
Mini Smart Wi-Fi Plug
by TP-Link
Firmware: 1.0.0 Build 220930 Rel.143947
Hardware: 1.0

Home Assistant 2023.8.3
Supervisor 2023.08.1
Operating System 10.4
Frontend 20230802.1 - latest

Installed on Raspberry Pi 4 with 4GB memory

Back for another go, you gave me such hope! :joy: Used the tapo app to install the latest firmware and tried again, still nothing. I noticed you have the newer 1.6 hardware (although HA still identifies it as 1.0?) Mine has 1.0 on the box so maybe newer ones work better.

I’m using iOS, if I do another full reset it does provision wifi and I see it listed under Matter Accessories. Oh well, at least the tapo integration works with it now.

I’ve gone through a wild number of attempts to get these working correctly. I got a three pack and they work well enough in the Tapo app, but getting them added to either Home Assistant or HomeKit is difficult. It works around 20% of the time, with a full factory reset at the start of each attempt. Then, I think all is good, it’s connected in Home Assistant and I expose that to HomeKit Bridge. Then I unplug it and plug it back in and it completely stops responding in Home Assistant. Shows as connected correctly, but it just doesn’t do anything when I toggle it.

Omg I finally got it. I have HA available externally through the cloudflared addon and only used the external URL in the iOS companion app. Today I tried setting the internal URL, reset everything and was able to pair the P125M again.

Tips on debugging are light so here are some things that helped me narrow it down:

  • The device’s ssid will be set to what your phone is connected to. If you have a 2.4Ghz or iot-only ssid, connect to that first
  • dns-sd -B _matterc._udp shows devices in commissioning mode. Found in this doc from google
  • Look into IGMP snooping options in your network gear. This wasn’t an issue for me (it’s enabled on a tplink managed switch), but could be an issue with Unifi
  • Tasmota v13 supports matter on ESP32. You can use this to rule out networking or device specific issues. I set Sleep 0 through the tasmota console otherwise wifi was slow/unstable
  • Try pairing from the Apple Home app as well, when this worked I knew it was something HA specific
1 Like

Are you able to see the power consumption data too by using Matter?

I also paired the Tapo P125M, but I only see the switch and not see the power consumption.
Can someone help me??

Matter does not yet support power consumption

Has anyone tried any of the new Tapo bulbs?
Had guessed some of the things stafunk hit on (tasmota v13 supporting matter is new though!).

I also hit on in the Tapo Matter documentation that ipv6 appears to be a requirement.
My ISP in Australia is one of the few laggards both in Australia and globally to not support ipv6.