home-assistant-matter-hub: [Bug]: Failed to start bridge due to error: TypeError: Cannot read properties of undefined (reading 'attributes')

Version

3.0.0-alpha.63

Matter Controller

Google Home

Steps to reproduce

Things were working just fine in .62, but after updating to .63 the everything became unavailable in Google Home. I checked on the HAMH and sure enough this error was back and only about 5 devices were present. Has the exact same message as #404 and #447 (I’m not allowed to re-open or I would have), and also accompanied by the errors in #457 (but those aren’t shown in the web UI, so presumably I also have that issue but this one is breaking things first.

There are a ton of errors about “Failed to create device” in the log that I don’t remember from when I reported 404 the first time, but nothing specific about why the device can’t be created.

If I had to guess I’d say maybe something about state being undefined and maybe that was because of the nulls? But as I said it’s been working for quite some time and I haven’t added any new devices since around .60 or .61 or so when everything was working.

State and attributes

It’s basically all of my devices, but e.g. “hallway_light” State: off Attributes:

supported_color_modes:
  - brightness
color_mode: null
brightness: null
off_with_transition: false
off_brightness: 64
friendly_name: Hallway Lamp
supported_features: 40

Relevant log output

[ 2025-01-20T21:55:32.347Z ] [ ERROR ] [ BridgeDeviceManager                                ]: Failed to create device light.shelf_light_a_level_light_color_on_off. Entity information: {
  entity_id: 'light.shelf_light_a_level_light_color_on_off',
  registry: [Object],
  deviceRegistry: [Object],
  state: undefined
}
[ 2025-01-20T21:55:32.347Z ] [ ERROR ] [ BridgeDeviceManager                                ]: Failed to create device light.shelf_light_b_level_light_color_on_off. Entity information: {
  entity_id: 'light.shelf_light_b_level_light_color_on_off',
  registry: [Object],
  deviceRegistry: [Object],
  state: undefined
}
[ 2025-01-20T21:55:32.347Z ] [ ERROR ] [ BridgeDeviceManager                                ]: Failed to create device light.hallway_light. Entity information: {
  entity_id: 'light.hallway_light',
  registry: [Object],
  deviceRegistry: [Object],
  state: undefined
}

.... many more of those

[ 2025-01-20T21:55:32.406Z ] [ ERROR ] [ Bridge / 25ce3dabd62f467388914a1a2d515165          ]: Failed to start bridge due to error: TypeError: Cannot read properties of undefined (reading 'attributes')
    at LightDevice (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:1560:55)
    at createDevice (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3021:10)
    at BridgeDeviceManager.upsertDevice (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3292:22)
    at file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3279:21
    at Array.map (<anonymous>)
    at BridgeDeviceManager.upsertDevices (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3277:16)
    at async BridgeDeviceManager.loadDevices (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3251:25)
    at async BridgeServerNode.start (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3403:7)
    at async _BridgeService.initialize (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3464:7)


[ 2025-01-20T21:55:32.448Z ] [ ERROR ] [ Matter / Transaction                               ]: Rolling back initialize<25ce3dabd62f467388914a1a2d515165.aggregator.switch_playroom_lights>#30 due to error: Behaviors have errors
[ 2025-01-20T21:55:32.448Z ] [ ERROR ] [ Matter / Transaction                               ]: Rolling back initialize<25ce3dabd62f467388914a1a2d515165.aggregator.switch_guest_room_lights>#35 due to error: Behaviors have errors
[ 2025-01-20T21:55:32.449Z ] [ ERROR ] [ Matter / Transaction                               ]: Rolling back initialize<25ce3dabd62f467388914a1a2d515165.aggregator.switch_workbench_speakers>#3a due to error: Behaviors have errors
[ 2025-01-20T21:55:32.449Z ] [ ERROR ] [ Matter / Transaction                               ]: Rolling back initialize<25ce3dabd62f467388914a1a2d515165.aggregator.script_going_out>#3f due to error: Behaviors have errors
[ 2025-01-20T21:55:32.449Z ] [ ERROR ] [ Matter / Transaction                               ]: Rolling back initialize<25ce3dabd62f467388914a1a2d515165.aggregator.script_bedtime_snack_time>#44 due to error: Behaviors have errors
[ 2025-01-20T21:55:32.449Z ] [ ERROR ] [ Matter / Transaction                               ]: Rolling back initialize<25ce3dabd62f467388914a1a2d515165.aggregator.switch_backyard_landscape>#4e due to error: Behaviors have errors

Documentation & Issues

  • I have reviewed the documentation and the linked troubleshooting guide.
  • I have searched the issues for a similar problem.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 20 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Are there any other cases where a device would appear in HA without its attributes?

If the only known scenario is that HA is currently starting up, it seems like encountering this error should just trigger HAMH to exit/restart rather than start up with a failed/unusable bridge. Eventually the devices would be ready, and one of HAMH’s restarts would succeed.

Even being stuck in a restart-loop wouldn’t really be any worse than stuck with an unusable bridge (I guess if having multiple bridges is supported / common that could complicate things, but is that a desired feature?).

I’m also having this issue for some time including .69. I manage to solve it by ensuring HA is healthy before bridge starts. My adjusted composer looks like this:

services:

  homeassistant:
(...)
    healthcheck:
      test: "curl --fail http://localhost:8123/ || exit 1"

  matter-hub:
(...)
    depends_on:
      homeassistant:
        condition: service_healthy

Hope this helps!

Having the same issue in alpha.72! Logs

Outside of finding a solution where HAMH autopolls HA to check devices are initialised before starting, might also be helpful to have HAMH publish its own healthcheck/container health status so we can have external scripts monitor for this error and autorestart the container when it occurs.

FWIW @Sammy1Am’s healthcheck script worked for me and is what I’m currently using. I don’t like the idea of having a long access token sitting in a plaintext document in the HA container though, I feel like since HAMH already requires the access token, maybe it could be changed to perform this ping on startup since it seems to be a reliable means of checking devices are online.

I’ve just added a fix, where the application waits for Home Assistant to have a “RUNNING” state. Other states where it will wait are STARTING, STOPPING, FAILED, …

I hope that this will fix it. It will be part of the next release. I just close this issue, feel free to re-open this issue when the problem persists.

Okay, thanks for finding this. The problem is, that the state includes important information to construct the bridge and its devices. E.g. we use the state to decide if it’s a simple light, dimmable light or color light. This cannot be changed afterwards without a restart. So we’d need to find a way to wait for HA to fully start before HAMH fetches any state.

@vail34 @Sammy1Am Does it work for you, too?

Hello, thanks for the great work on this project ! I’ve noticed the same error when I restart both Home Assistant and the matter-hub at the same time (both in Docker). At first all devices have an ‘undefined’ state and this blocks the matter-hub startup. If I restart the matter-hub a short while after HA has started, everything is fine.

Here is the error :

[ 2025-01-27T09:11:45.118Z ] [ ERROR ] [ Bridge / 89769d7d86714be3bda86fa2f275e0b9          ]: Failed to start bridge due to error: TypeError: Cannot read properties of undefined (reading 'attributes')
    at LightDevice (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:1560:55)
    at createDevice (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3021:10)
    at BridgeDeviceManager.upsertDevice (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3292:22)
    at file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3279:21
    at Array.map (<anonymous>)
    at BridgeDeviceManager.upsertDevices (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3277:16)
    at async BridgeDeviceManager.loadDevices (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3251:25)
    at async BridgeServerNode.start (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3403:7)
    at async _BridgeService.initialize (file:///usr/local/lib/node_modules/home-assistant-matter-hub/dist/backend/cli.js:3464:7)

Maybe matter-hub should allow creation of entities with undefined state, and update them later on when their state changes ?