dgreif / homebridge-hatch-baby-rest

A homebridge plugin for Hatch Baby Rest night light
MIT License
74 stars 19 forks source link

Can connect but cannot control #41

Closed zcopter closed 3 years ago

zcopter commented 3 years ago

Hi, I'd like to see if I can get a bit of assistance. I have 2 original Hatch Rest lights and have gone through the setup procedure. I have added 1 of the units into the config with the mac I have set it up with 50% audio default light color and stream as the "audio track". When I go to turn the accessory on I can see it status that the device is recognized then it connects and after approx. 1-3 seconds it disconnects but nothing is happening with the Hatch....

Here is the log after restart and trying to power on the Hatch. (MAC shows in log but I have removed it here)

[1/9/2021, 9:44:06 AM] [HB Supervisor] Starting Homebridge with extra flags: -I [1/9/2021, 9:44:06 AM] [HB Supervisor] Started Homebridge v1.1.7 with PID: 3532 [1/9/2021, 9:44:06 AM] Loaded config.json with 1 accessories and 1 platforms. [1/9/2021, 9:44:06 AM] --- [1/9/2021, 9:44:06 AM] Loaded plugin: homebridge-config-ui-x@4.36.0 [1/9/2021, 9:44:06 AM] Registering platform 'homebridge-config-ui-x.config' [1/9/2021, 9:44:06 AM] --- [1/9/2021, 9:44:07 AM] Loaded plugin: homebridge-hatch-baby-rest@2.1.0 [1/9/2021, 9:44:07 AM] Registering accessory 'homebridge-hatch-baby-rest.HatchBabyRest' [1/9/2021, 9:44:07 AM] Registering platform 'homebridge-hatch-baby-rest.HatchBabyRest' [1/9/2021, 9:44:07 AM] --- [1/9/2021, 9:44:07 AM] Loading 1 platforms... [1/9/2021, 9:44:07 AM] [Config] Initializing config platform... [1/9/2021, 9:44:07 AM] [Config] Running in Service Mode [1/9/2021, 9:44:07 AM] Loading 1 accessories... [1/9/2021, 9:44:07 AM] [Bishop's Room] Initializing HatchBabyRest accessory... [1/9/2021, 9:44:07 AM] [Bishop's Room] Waiting for bluetooth to power on [1/9/2021, 9:44:07 AM] Homebridge is running on port 51143. [1/9/2021, 9:44:07 AM] [Bishop's Room] Scanning for device [1/9/2021, 9:44:09 AM] [Bishop's Room] Found device Bishop’s Room with address : [1/9/2021, 9:48:00 AM] [Bishop's Room] Turning on [1/9/2021, 9:48:00 AM] [Bishop's Room] Connecting to Bishop’s Room... [1/9/2021, 9:48:02 AM] [Bishop's Room] Connected to Bishop’s Room [1/9/2021, 9:48:07 AM] [Bishop's Room] Disconnected from Bishop’s Room

zcopter commented 3 years ago

From the config:

"accessories": [ { "name": "Bishop's Room", "macAddress": "", "volume": 50, "audioTrack": 2, "color": { "r": 254, "g": 254, "b": 254, "a": 128 }, "showAsSwitch": true, "accessory": "HatchBabyRest"

arvathrowaway commented 3 years ago

What are you running Homebridge on?

zcopter commented 3 years ago

Windows 10

arvathrowaway commented 3 years ago

Is your local machine close enough to the device to make a good BT connection?

zcopter commented 3 years ago

Yea I'm only 10 Ft away. I can access from my phone around 30.

arvathrowaway commented 3 years ago

Does the W10 machine have BT LE capability? Any debug logs you can post?

zcopter commented 3 years ago

Yea it's a brand new bt USB adapter. I have installed the libusb driver for it too. I'm not sure where I would find the debug logs?

From the HB log above it appears everything is functioning. I have tried removing the bt adapter and it throws an error then when I reconnect it the error goes away. So I assume it is working.

Is there supposed to be some sort of authentication or is really as simple as just Bluetooth and the MAC?

arvathrowaway commented 3 years ago

I experienced the same issue on an RPi. The issue was the last bit of the range on installing all the necessary libraries. It looked like it connected but never did anything. Is this the only accessory you have for the rest platform/plugin? It did the same thing to me when I tried to add more than one under the same MAC too

dgreif commented 3 years ago

It does look like it's connecting, but the command isn't making it to the device. It may be that once it connects, it's not about to read the services available from the light. Most users run homebridge on an rpi or Mac, so I haven't had to deal with many Windows issues. Looking at the docs for noble (BLE library used by this plugin), there is a link to this video: https://www.youtube.com/watch?v=mL9B8wuEdms&feature=youtu.be&t=1m46s . I suggest you try the steps there and see if that helps.

Regarding authentication, there is none on these lights. MAC address is all you need. If you want a more secure light, the rest plus uses WiFi and is way more secure. It's also a lot more reliable with this homebridge plugin.

zcopter commented 3 years ago

Hi I have been successful. I tried the install of noble. But, no luck... I think it had already been installed when I installed windows build tools. However I found out the Mac should be written out in lower case without colons. I had written it exactly as in the app. I can now turn on one of the lights. But if I add a 2nd one I can't connect to either. If I remove it I can still control the original as before or if I use the 2nd only I can also control it on its own. Is there anything special for 2 original hatches to be controlled?

I have also found out the range on this BT adapter is not great. Sometimes I can reach it at about 10ft and sometimes only about 3

dgreif commented 3 years ago

@zcopter glad you got it working, at least partially! I just double checked the code and it explicitly ignores upper vs lower case on the mac id, so that probably wasn't the issue. I've heard other reports of issues when connecting to multiple bluetooth rest lights so there very well could be a bug there. When I originally wrote the code, I was testing it with 2 lights, but I only have 1 on hand now.

As for range, that's unfortunate your adapter doesn't have good reach. I'm guessing that's what lead to a lot of your original issues

zcopter commented 3 years ago

Thanks. Regarding case do you think it could have been the colons? That's the other thing I changed. I'm still sitting where I was before while testing but it is odd sometimes it works from that distance and sometimes not... what is the distance for a pi (roughly) any idea?

Should it read status after a reboot? IE light on, restart homebridge, plugin shows light as off.

When trying to connect to both lights it starts up and initiates scanning for both at the same time then just sits like that. I wonder if I could add a pause until it reads the first then moves to the 2nd.

arvathrowaway commented 3 years ago

I thought you had said it was on a W10 machine?

I have it on a RPi Zero W and experience the same range issues as you sometimes. The issue was nearby devices (namely a Google Home mini and my phone). I unplugged the GHM and operated it from down the hall and the range issues disappeared and it operated without fail every time.

I also have two lights and it's not been an issue from what I can gather, and the same issues presented themselves if I had one set up in HB or two.

Moved both closer to the machine and haven't had any issues. Literally bought another RPi Zero W just for this integration and put them in between the two lights on either side of the same wall.

dgreif commented 3 years ago

It should work with :, - or no separator. A-B-C-D will be interpreted the same as a:b:c:d.

Distance-wise, my rpi 3B+ reaches around 25 feet, roughly. I had a light at ~40 feet and it was hit or miss with similar symptoms to what you are seeing.

The plugin does not read on startup. My assumption there was you will mainly be automating the light for things like ready-to-wake. Although it would be cool, I don't see a lot of value in ensuring that HomeKit always has the correct value for what the light is currently set to if it was set via some other means (eg via the Rest app)

zcopter commented 3 years ago

@arvathrowaway You're correct it is w10. Just thinking if I would be better off with a pi. So you are saying you don't have an issue with one HB connecting to 2 lights if they are with range?

@dgreif Ok thanks. Not sure then what fixed it. Reason I was asking if it checks status is if it is on and homebridge is rebooted I have to select power on before I can power off. Or if it starts from a timer on the app I have to perform the same procedure to turn it off.

dgreif commented 3 years ago

You should be able to turn it off with automations or scenes without it being on. Only if you go in and hit the manual toggle does it need to turn on first and then off.

zcopter commented 3 years ago

Ok thanks I'll try that tomorrow

zcopter commented 3 years ago

Log from testing with 1 hatch: [1/12/2021, 10:20:29 AM] Loaded plugin: homebridge-config-ui-x@4.36.0 [1/12/2021, 10:20:29 AM] Registering platform 'homebridge-config-ui-x.config' [1/12/2021, 10:20:29 AM] --- [1/12/2021, 10:20:30 AM] Loaded plugin: homebridge-hatch-baby-rest@2.1.0 [1/12/2021, 10:20:30 AM] Registering accessory 'homebridge-hatch-baby-rest.HatchBabyRest' [1/12/2021, 10:20:30 AM] Registering platform 'homebridge-hatch-baby-rest.HatchBabyRest' [1/12/2021, 10:20:30 AM] --- [1/12/2021, 10:20:30 AM] Loading 1 platforms... [1/12/2021, 10:20:30 AM] [Config] Initializing config platform... [1/12/2021, 10:20:30 AM] [Config] Running in Service Mode [1/12/2021, 10:20:30 AM] Loading 1 accessories... [1/12/2021, 10:20:30 AM] [Bishop's Room] Initializing HatchBabyRest accessory... [1/12/2021, 10:20:31 AM] [Bishop's Room] Waiting for bluetooth to power on [1/12/2021, 10:20:31 AM] Homebridge is running on port 51143. [1/12/2021, 10:20:31 AM] [Bishop's Room] Scanning for device [1/12/2021, 10:20:31 AM] [Bishop's Room] Found device Bishop’s Room with address

If I have 2 devices: [1/12/2021, 10:22:03 AM] [HB Supervisor] Starting Homebridge with extra flags: -I [1/12/2021, 10:22:03 AM] [HB Supervisor] Started Homebridge v1.1.7 with PID: 7656 [1/12/2021, 10:22:04 AM] Loaded config.json with 2 accessories and 1 platforms. [1/12/2021, 10:22:04 AM] --- [1/12/2021, 10:22:04 AM] Loaded plugin: homebridge-config-ui-x@4.36.0 [1/12/2021, 10:22:04 AM] Registering platform 'homebridge-config-ui-x.config' [1/12/2021, 10:22:04 AM] --- [1/12/2021, 10:22:04 AM] Loaded plugin: homebridge-hatch-baby-rest@2.1.0 [1/12/2021, 10:22:04 AM] Registering accessory 'homebridge-hatch-baby-rest.HatchBabyRest' [1/12/2021, 10:22:04 AM] Registering platform 'homebridge-hatch-baby-rest.HatchBabyRest' [1/12/2021, 10:22:04 AM] --- [1/12/2021, 10:22:04 AM] Loading 1 platforms... [1/12/2021, 10:22:04 AM] [Config] Initializing config platform... [1/12/2021, 10:22:05 AM] [Config] Running in Service Mode [1/12/2021, 10:22:05 AM] Loading 2 accessories... [1/12/2021, 10:22:05 AM] [Bishop's Room] Initializing HatchBabyRest accessory... [1/12/2021, 10:22:05 AM] [Bishop's Room] Waiting for bluetooth to power on [1/12/2021, 10:22:05 AM] [Amelia's Room] Initializing HatchBabyRest accessory... [1/12/2021, 10:22:05 AM] [Amelia's Room] Waiting for bluetooth to power on [1/12/2021, 10:22:05 AM] [Bishop's Room] Scanning for device [1/12/2021, 10:22:05 AM] [Amelia's Room] Scanning for device

then it just stops... I can connect to both individually from the same location but not if they are both in the config

dgreif commented 3 years ago

Currently the code doesn't do anything to coordinate bluetooth connections between multiple lights. If you try to control two at the same time, it will immediately try to connect to and control both of them. My guess is that some bluetooth controllers may not support connecting to multiple devices at the same time, which would cause issues with the current setup. It's something I can probably refactor in the code, but I don't have two bluetooth lights to test with at this point. I've been pretty limited on free time, so it will be a while before I get around to this. In the mean time, you could try setting up a second homebridge on a cheap raspberry pi to control one of the two lights. Or, you could upgrade one of the lights to a Rest+, which uses wifi and is way more reliable with homebridge. Sorry for the trouble!

arvathrowaway commented 3 years ago

I have two lights set up on the same config and it works fine, for what it’s worth.

zcopter commented 3 years ago

@dgreif Thanks for looking into it. I have went ahead and setup on a raspberry PI and most the time it is functioning quite well. I'v noticed the pi range isn't as great as the dongle. But, I can control both with the PI. I have done quite a bit of reading on the libusb drivers used for bluetooth via homebridge. My understanding is the dongle I am using should have the ability to communicate to multiple devices. I have tried the dongle with my PI and it works for both.

I suspect this is a case of either the way that the bluetooth dongle is being controlled, or something with the driver/windows. I have tried all three drivers libusb, winusb, and libusbk. Which from what I read one of those "should" work.

I guess as an "enhancement" it may be a workaround to have a wait/pause in between devices to allow controlling one at a time. Maybe as an option?

Anyways, Thank you for all of the support and assistance. If you have some tests I can assist with I am happy to do so.

Edited after testing the dongle with the pi.

dgreif commented 3 years ago

@zcopter I'm glad you got it working with your rpi. It sounds like this is more of a driver issue than a plugin issue so I think I'll close this one out.