NorthernMan54 / node-red-contrib-homebridge-automation

Homebridge and Node-RED Integration
Apache License 2.0
107 stars 18 forks source link

Homebridge device discovery only finding external accessories #103

Closed jjknudsen closed 1 year ago

jjknudsen commented 1 year ago

This plugin had been working perfectly for quite some time. I've been using the Homebridge Ring plugin and recently made a configuration change to the plugin. I'm not 100% sure this change is what broke things, but I'm pretty confident.

One of the plugin configuration options is to treat all Cameras as external accessories to improve performance. The plugin notes:

If enabled, all Ring Cameras we be treated as external accessories, which generally leads to better performance. This means they each need to be individually added to HomeKit. 

After making this change and pairing each camera individually to Homekit, the device list in Node-RED only shows these external camera accessories. All other Homebridge accessories no longer show up. I have restarted Node-RED, Homebridge, the entire device. I've tried re-creating the hb-conf node as well. Nothing I do seems to make a difference.

I have not yet reverted the plugin change just because of the time it takes me to re-create my Homekit automations, but I may try this soon.

When I run the below command, changing the port for each child bridge, it does return an accessory list for each bridge.

curl -X PUT http://127.0.0.1:40267/accessories --header "Content-Type:Application/json" --header "authorization: 123-45-678"

Below is an excerpt of the Node-RED debug log. It seems this request is sent for the Camera accessories. But I also see it a number of times to what perhaps should be the Child bridge URLs but I'm not really sure what's going on.

  hapNodeJSClient HAP Discover failed Floodlight Pro (floodlight_pro) -> undefined error Error: Invalid URI "undefined/accessories"
    at Request.init (/home/username/.node-red/node_modules/request/request.js:273:31)
    at new Request (/home/username/.node-red/node_modules/request/request.js:127:8)
    at Function.request (/home/username/.node-red/node_modules/request/index.js:53:10)
    at Request._tryUntilFail (/home/username/.node-red/node_modules/requestretry/index.js:134:23)
    at Factory (/home/username/.node-red/node_modules/requestretry/index.js:188:7)
    at Browser._getAccessories (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:716:5)
    at Browser.<anonymous> (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:180:21)
    at Browser.emit (node:events:513:28)
    at Browser._addService (/home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:109:8)
    at /home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:86:14 {
  attempts: 1
} +1ms
  hapNodeJSClient HAP Discover failed Unknown Model (lpd_v4) -> undefined error Error: Invalid URI "undefined/accessories"
    at Request.init (/home/username/.node-red/node_modules/request/request.js:273:31)
    at new Request (/home/username/.node-red/node_modules/request/request.js:127:8)
    at Function.request (/home/username/.node-red/node_modules/request/index.js:53:10)
    at Request._tryUntilFail (/home/username/.node-red/node_modules/requestretry/index.js:134:23)
    at Factory (/home/username/.node-red/node_modules/requestretry/index.js:188:7)
    at Browser._getAccessories (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:716:5)
    at Browser.<anonymous> (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:180:21)
    at Browser.emit (node:events:513:28)
    at Browser._addService (/home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:109:8)
    at /home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:86:14 {
  attempts: 1
} +0ms
  hapNodeJSClient HAP Device discovered homebridge-bond 95F4 +2ms
  hapNodeJSClient HAP Device discovered TuyaPlatform D2B6 +1ms
  hapNodeJSClient HAP Device discovered Nest 71BD +1ms
  hapNodeJSClient HAP Device discovered homebridge-myq A60A +1ms
  hapNodeJSClient HAP Device discovered Office Occupancy Switch 602C +1ms
  hapNodeJSClient HAP Discover failed homebridge -> undefined error Error: Invalid URI "undefined/accessories"
    at Request.init (/home/username/.node-red/node_modules/request/request.js:273:31)
    at new Request (/home/username/.node-red/node_modules/request/request.js:127:8)
    at Function.request (/home/username/.node-red/node_modules/request/index.js:53:10)
    at Request._tryUntilFail (/home/username/.node-red/node_modules/requestretry/index.js:134:23)
    at Factory (/home/username/.node-red/node_modules/requestretry/index.js:188:7)
    at Browser._getAccessories (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:716:5)
    at Browser.<anonymous> (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:180:21)
    at Browser.emit (node:events:513:28)
    at Browser._addService (/home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:109:8)
    at /home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:86:14 {
  attempts: 1
} +1ms
  hapNodeJSClient HAP Discover failed homebridge -> undefined error Error: Invalid URI "undefined/accessories"
    at Request.init (/home/username/.node-red/node_modules/request/request.js:273:31)
    at new Request (/home/username/.node-red/node_modules/request/request.js:127:8)
    at Function.request (/home/username/.node-red/node_modules/request/index.js:53:10)
    at Request._tryUntilFail (/home/username/.node-red/node_modules/requestretry/index.js:134:23)
    at Factory (/home/username/.node-red/node_modules/requestretry/index.js:188:7)
    at Browser._getAccessories (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:716:5)
    at Browser.<anonymous> (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:180:21)
    at Browser.emit (node:events:513:28)
    at Browser._addService (/home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:109:8)
    at /home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:86:14 {
  attempts: 1
} +1ms
  hapNodeJSClient HAP Discover failed homebridge -> undefined error Error: Invalid URI "undefined/accessories"
    at Request.init (/home/username/.node-red/node_modules/request/request.js:273:31)
    at new Request (/home/username/.node-red/node_modules/request/request.js:127:8)
    at Function.request (/home/username/.node-red/node_modules/request/index.js:53:10)
    at Request._tryUntilFail (/home/username/.node-red/node_modules/requestretry/index.js:134:23)
    at Factory (/home/username/.node-red/node_modules/requestretry/index.js:188:7)
    at Browser._getAccessories (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:716:5)
    at Browser.<anonymous> (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:180:21)
    at Browser.emit (node:events:513:28)
    at Browser._addService (/home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:109:8)
    at /home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:86:14 {
  attempts: 1
} +1ms
  hapNodeJSClient HAP Discover failed homebridge -> undefined error Error: Invalid URI "undefined/accessories"
    at Request.init (/home/username/.node-red/node_modules/request/request.js:273:31)
    at new Request (/home/username/.node-red/node_modules/request/request.js:127:8)
    at Function.request (/home/username/.node-red/node_modules/request/index.js:53:10)
    at Request._tryUntilFail (/home/username/.node-red/node_modules/requestretry/index.js:134:23)
    at Factory (/home/username/.node-red/node_modules/requestretry/index.js:188:7)
    at Browser._getAccessories (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:716:5)
    at Browser.<anonymous> (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:180:21)
    at Browser.emit (node:events:513:28)
    at Browser._addService (/home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:109:8)
    at /home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:86:14 {
  attempts: 1
} +1ms
  hapNodeJSClient HAP Discover failed homebridge -> undefined error Error: Invalid URI "undefined/accessories"
    at Request.init (/home/username/.node-red/node_modules/request/request.js:273:31)
    at new Request (/home/username/.node-red/node_modules/request/request.js:127:8)
    at Function.request (/home/username/.node-red/node_modules/request/index.js:53:10)
    at Request._tryUntilFail (/home/username/.node-red/node_modules/requestretry/index.js:134:23)
    at Factory (/home/username/.node-red/node_modules/requestretry/index.js:188:7)
    at Browser._getAccessories (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:716:5)
    at Browser.<anonymous> (/home/username/.node-red/node_modules/hap-node-client/HAPNodeJSClient.js:180:21)
    at Browser.emit (node:events:513:28)
    at Browser._addService (/home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:109:8)
    at /home/username/.node-red/node_modules/bonjour-hap/lib/Browser.js:86:14 {
  attempts: 1
} +0ms
jjknudsen commented 1 year ago

I started digging into the code and found that that the bonjour-hap library which is used to discover Homekit devices is discouraged and has been replaced by Ciao. I happened to notice Ciao was an option for the mDNS advertiser in the Homebridge settings. I switched the Homebridge mDNS advertiser from Avahi to Ciao and for whatever reason the errors in Node-RED went away and the device list was repopulated with all Homekit accessories.

I have no idea why this fixed, the problem but it fixed it nonethess so I'll mark this closed.