ebaauw / homebridge-nb

Homebridge plugin for Nuki Bridge
Apache License 2.0
51 stars 3 forks source link

Latch is displayed without entry in config.json #103

Closed Nastras closed 1 year ago

Nastras commented 1 year ago

Hey ho Erik i got myself a second nukibridge to use your plugin 😉. So far everything works as it should 💪.

One thing I noticed with my security bar. This one has no latch. I have in the config.json also no latch activated. In Homekit, a latch is still displayed on the device. Do you have an idea why the latch is displayed?

IMG_4438 IMG_0038 IMG_0039

ebaauw commented 1 year ago

That's a characteristic, Unlatch on the Lock Mechanism service for the smart lock, not a separate Lock Mechanism service for the latch function. The latch setting in config.json controls the creation of the separate service; the characteristic is exposed unconditionally.

Originally, I planned to use the /unlock endpoint, which behaves differently, based on the door fitting configuration: unlatch for knob vs unlock for lever. However, that didn't work out too well (see closed issues), so now I'm using the lockAction endpoint, explicitly specifying unlock or unlatch.

Nastras commented 1 year ago

Thank you for the explanation. I understood that it has nothing to do with the latch in config.json.

What I unfortunately have not yet properly understood why do I need this switch for a lock without latch. Or does it only have an indicating function?

I switched on the switch unlatch earlier and the security bolt has made very strange noises because he has tried to drive over his end stop.

Nastras commented 1 year ago

I just looked into the journalctl of both instances and noticed this message 🙁.

I have different ports 8080 and 9090 for both instances. I have had this behavior before today. But then I was still configuring so I thought after a reboot the problem should be solved. Now it is there again.

IMG_4443 IMG_4444

Nastras commented 1 year ago

I just noticed that this error message filled my daemon.log and sys.log until there was no more memory left on the pi and nothing worked.

IMG_4445

Nastras commented 1 year ago

It gets wilder and wilder. Now I have deleted the log files and made a reboot of the Pi. Now there is space on the Pi again.

After I looked into the journalctl of homebridge-nb-2 it asked me to press the button of the bridge again. This I have done.

Shortly after that he wants me to press the button again 🫣.

IMG_4446

Nastras commented 1 year ago

Now neither instance is running anymore even after a restart. It looks to me like the two Nuki bridges are interfering with each other in both instances.

IMG_4447

Nastras commented 1 year ago

But it shouldn't be because both instances have a different port of the respective nuki bridge added.

IMG_4451 IMG_4450

ebaauw commented 1 year ago

Shortly after that he wants me to press the button again

No. You pressed the button on one bridge (10689F0F), but Homebridge NB is still waiting for the press on the other bridge (6E7C5E21).

It looks to me like the two Nuki bridges are interfering with each other in both instances.

You only need one instance of Homebridge NB, exposing both Nuki bridges. If you run two instances of Homebridge NB, both will discover and (try to) connect to both bridges. The bridges aren't very powerful and have a hard time handling that load, resulting in the 503 service unavailable (and probably the bridge returning an invalid response, causing the TypeError).

But it shouldn't be because both instances have a different port of the respective nuki bridge added.

No, see the description for port in the Homebridge UI form:

Port to use for webserver receiving Nuki bridge notifications. Default: random.

ebaauw commented 1 year ago

It doesn't look good that Homebridge NB retries the /auth immediately after 503 (and the TypeError). That will definitely swamp the Nuki bridge. There should be a delay, as when not having pressed the button.

EDIT: there's no delay; the bridge waits ~30s for the button to be pressed after receiving /auth, and only then returns the "button not pressed status". After this, Homebridge NB immediately sends a new /auth request.

Nastras commented 1 year ago

You only need one instance of Homebridge NB, exposing both Nuki bridges. If you run two instances of Homebridge NB, both will discover and (try to) connect to both bridges.

That is a good hint and explains why everything is going crazy. But I assumed after our conversation on homebridge-nb channel on Discord that with a second nuki bridge I can turn on the latch function on my door lock and turn it off on the security bolt.

There is no possibility innthe plugin to configure single locks with this function. Otherwise I would not have needed the second nuki bridge if I have everything in one instance.

IMG_4452

ebaauw commented 1 year ago

Sorry if I was unclear. My remark "Damn. That is a catch-22." Was in response to your correct observation that you would get all locks twice in HomeKit, as you cannot specify which devices to expose.

Nastras commented 1 year ago

Not a thing. I seem to have misunderstood it, too. So I assumed that if I have two nuki bridges and operate my two nuki locks separately in different instances that I can then configure latch separately.

Now I have the problem that nothing of my intention works because the instances interfere with each other 😅😅😅

ebaauw commented 1 year ago

The instances don't interfere with each other; the Nuki bridge simply has a hard time handling the requests from two Homebridge NB instances. I already saw this while creating Homebridge NB, running a dev/test instance next to a production instance. And v1.4.x will have made things worse, with encrypted tokens. And immediately retrying /auth after an error is disastrous.

Nastras commented 1 year ago

The instances don't interfere with each other; the Nuki bridge simply has a hard time handling the requests from two Homebridge NB instances.

That's how I meant it too, expressed it a bit stupidly 😅.

Do you still have an idea how I can solve my problem so that I can configure my security bolt without latch and my door lock with latch?

Is there maybe the possibility to tell the instance via config.json that it is only looking for a certain bridge?

Otherwise the purchase of the second Nuki Bridge was completely wasted 🫣

Nastras commented 1 year ago

I have only one instance of homebridge-nb running since last night. In this only one nukibridge is integrated. But both nukibridge were in power. I already ran a sudo systemctl install homebridge-nb this morning to get your updated files from yesterday. So that the search for a bridge is only every 30 sec. After I just arrived home I found out that my Pi is out of memory again and system.log and daemon.log are 1GB again. If I see it correctly, this problem exists consistently as soon as two nukibridge are in the network. No matter if this is used for the plugin or not.

Can you please let me know what the chance is for a solution or should I return the new nukibridge 😞?

Thanks a lot!

ebaauw commented 1 year ago

I already ran a sudo systemctl install homebridge-nb this morning to get your updated files from yesterday.

I don't think that's a valid command, or did you mean npm install homebridge-nb. That installs the latest published version from the NPM repository, not the (work-in-progress) latest commit from GitHub.

v1.4.2 fixes the missing delay. That version also supports whitelisting which bridges, smart locks, and openers to expose, see #66. That should enable you to whitelist one bridge and connected devices in one Homebridge NB instance, and the other bridge and connected devices in the other instance.

In theory, you could have a two Homebridge NB instances, each whitelisting the same Nuki bridge and a different smart lock (with different latch setting), but that single bridge might still be overwhelmed by the combined requests from the two Homebridge NB instances.

After I just arrived home I found out that my Pi is out of memory again and system.log and daemon.log are 1GB again

Monitoring filesystem space and recycling logfiles is beyond the scope of Homebridge NB. In a standard Homebridge installation, the Homebridge UI uses a dedicated logfile instead of syslog, which it recycles every so many lines.

Nastras commented 1 year ago

Hey that's great news ❤️ I just wanted to install the update but I get the answer that the version can not be found. If I install with latest it stays on 1.4.1 and if I specify the version 1.4.2 comes the message:

IMG_4453

I don't think that's a valid command, or did you mean npm install homebridge-nb. That installs the latest published version from the NPM repository, not the (work-in-progress) latest commit from GitHub.

I have made a mistake . Yes i mean npm install homebridge-nb 😅

ebaauw commented 1 year ago

Damn, I need to press enter after npm publish! Should work now.

Nastras commented 1 year ago

Hi Erik, sorry for the late feedback. Family has been keeping me very busy 😁.

I have now updated the plugin and set it up successfully. I still have two instances with one nukibridge for each lock.

The plugin is running very well so far and nothing to complain about. I am once again impressed with your skills and how well you have implemented it ❤️.

I would like to take this opportunity to thank you for your quick help again.

If I notice something out of the ordinary I will contact you again 😉

Thank you!

Nastras commented 1 year ago

Oh I have one more question would it be possible to run both nukibridges in one instance? You had mentioned that I can no longer find it.

If so how would I have to adjust the config for this?

ebaauw commented 1 year ago

Yes, you would simply whitelist both bridges (or leave the devices empty). But you would still only have one latch setting in that setup. You need two Homebridge instances for different latch settings.

Nastras commented 1 year ago

Oh yes the thing with the latch settings I forgot completely. Then I stay with two instances 😁