NorthernMan54 / node-red-contrib-homebridge-automation

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

Support for AVAHI as mDNS Advertiser #120

Open ThePhiMuc opened 3 weeks ago

ThePhiMuc commented 3 weeks ago

Current Situation

I was moving my NodeRed installation to a new Raspi. The new one is running Homebridge, too. On the new one, Homebridge devices could not be found by your plugin, the dropdown was empty.

After digging around a while I found that the Homebridge installation at the old Raspi was set to "Bonjour HAP" as mDNS Advertiser, the one et the new Raspi was set to AVAHI (which seems to be the standard at new installations now).

Everything was working fine again, as soon I set "Bonjour HAP" as advertiser at the new Homebridge installation. So for me it seems that your plugin is successfully communicating with Homebridge if Bonjour HAP is used, but not if Homebridge is set to AVAHI.

I don't know what the benefits of the different advertisers are - but it would be great, if your plugin would suport AVAHI, too.

CU, Philipp

Proposed Change

Add the possibility to use AVAHI as mDNS Advertiser

Additional Context

No response

NorthernMan54 commented 3 weeks ago

Without digging deeper, I think you are seeing this issue - https://github.com/homebridge/bonjour/issues/12

HDeKnop commented 3 weeks ago

This is very disappointing.

I have just been struggling with the exact same issue today - except that I cannot go back to Bonjour. Am stuck on Avahi for network stability elsewhere.

Hope this can work with Avahi as well in future.

NorthernMan54 commented 3 weeks ago

Does the homebridge UI / accessories tab work for you? It uses a slight different package for discovery.

HDeKnop commented 3 weeks ago

The accessories tab works better 95% of the time. Only get misalignment when I’m testing / rebooting / trying to get Node_Red to work. But “eventually” that always does come back to fully OK. Note I have 2 instances each on their own RPi.

NorthernMan54 commented 2 weeks ago

I was thinking about migrating Homebridge-automation to the same package to manage discovery, but as you shared that doesn't resolve it.

Am thinking the only solution is to fix the issue I shared above

HDeKnop commented 2 weeks ago

Further behaviour: just now I opened up node-red for a quick check.

  1. Everything has been running by itself - have not touched anything since last night.
  2. Initially all my devices were there - from both instances.
  3. Edited a couple of small changes in Node-red flows. 10 minutes later I try to include a new HB-event node ... and the drop-down selector is completely empty.
  4. HB Accessories tab is still populated fully.
ThePhiMuc commented 2 weeks ago

I didn't dig deep here but yesterday there have been two homebridge instances running in my network (the one on the old Pi, one at the new one - no child-bridges are used). That's not a large amount and they have not been on the same machine. But (which might cause trouble) they have been using the same homekit pin (I imported a Homebridge backup to the new machine). After I migrated everything to the new machine I stopped the old homebrindge installation and rebootet the new Pi. I've switched back to AVAHI a few moments ago and now the plugin is working fine, even AVAHI is selected. This lets me assume that you're right and it might be that network-package-problem which can not occour here anymore 'cause there's only one Homebridge instance now...

What I'm wondering about: I definitely stopped the homebridge service on the old Pi but the plugin wasn't able to find the nwe instance using AVAHI yesterday. My first thought was "they are using the same Pin, maybe the plugin doesn't know where to get the devices from". So I stopped the old instance which didn't help (even after restarting Nodered). Afterwards I changed to Bonjour and opened this feature-request. But maybe that has been a caching problem or something like that.

So from my point of view I'm fine - but I think using more than one instance is a common usecase and it might be a good idea to find a fix for that ;)

So HDeKnop might be more helpful here for further investigation ;-)

HDeKnop commented 1 week ago

Have been playing around with different permutations to try and somehow find a consistent behaviour that would indicate for you where the issue is. (details on that below)

So far all I can say is:

  1. The accessories tab DOES seem to always be up to date correctly. Unclear what was causing misses in the past. Have not observed accessories tab ever having issues now.
  2. Your plugin - when it works for me - consistently gives me issues with devices on different homebridge instances. Even if they are found in the drop-down list, they will not initialise correctly in the flow; typically with a 'PIN ERROR' somewhere in the debug messages. This is an issue I got 90% of the time. (though not 100% - which I do not understand)
  3. Regarding nr 2 I can resolve by changing the PIN on all homebridge instances to align to the one your plugin is using. ==> this gave me about 12 hours of absolute bliss where I believed everything resolved yesterday ==> re nr 1 now all homebridge instances show all accessories (incl. from other instances) on their accessories tabs - presumably since they're all using the same pin. ==> weirdly this has not negatively impacted connection to Home App (presumably showing my ignorance more than anything)

Like I said: yesterday I thought everything was resolved. This afternoon I open up Node-Red and only connection errors on all devices. Drop-down menu empty. Just as I write this sentence I checked and see that it is working again ... connections established and drop-down populated with all 62 devices.

As context on how I'm setup:

I have 3 separate RPis each with its own homebridge instance. 1x homebridge OS, 1x homebridge on Bookworm with desktop, 1x homebridge on Bookworm on RPI 5 Each instance runs a different set of plugins. (overkill - this is running my house even as I'm expanding with new plugins etc ... so need to limit impact of failures). I've been alternately trying node-red on (any one) of these Pi's or my Macbook. Always same behaviour. (and as we speak its still working ...)

Really would love to get this stable enough that I can move my automations out of Homekit and into your plugin ;-)

I don't know enough to find what is causing this - but am happy to be a testcase or follow your instructions if you can tell me what to look for.

NorthernMan54 commented 5 days ago

FYI - Will be looking at this in the short term, and will migrate to the same homebridge instance discovery as the UI. Then can tackle the issue with the common module between the two.