dgreif / homebridge-hatch-baby-rest

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

Scanning for device #4

Closed kidskin-kettle-WANDER-sassy closed 4 years ago

kidskin-kettle-WANDER-sassy commented 4 years ago

I have config.json setup and connects successfully:

  "accessories": [
    {
      "accessory": "HatchBabyRest",
      "name": "Charlie & Teddy",
      "macAddress": "12:34:56:78:90:11",
      "volume": 25,
      "audioTrack": 3,
      "color": { "r": 0, "g": 0, "b": 255, "a": 128 }
    }
  ]

but get:

[12/15/2019, 11:27:44 PM] Homebridge is running on port 51826.
[12/15/2019, 11:27:44 PM] [C] Scanning for device
[12/15/2019, 11:28:55 PM] [C] Turning on
[12/15/2019, 11:28:57 PM] [C] Turning on
[12/15/2019, 11:29:00 PM] [C] Turning on

appears to be running correctly on my MacBook Pro (Retina, Mid 2012) but the turn on/off doesn't do anything.

using iphone 11, latest iOS, with the original Hatch Baby Rest. I have two of them and would love to setup automation and control from homekit with your code.

Any thoughts?

dgreif commented 4 years ago

Sorry you are running into issues! This is most likely a permissions issue similar to #3 and #2. Your config looks correct, but your macbook may not be granting permission to the plugin. I will try set up the plugin on another macbook that I haven't already fixed permissions on and try to document the steps you need to take.

Are you seeing any of the following message?

1: Waiting for bluetooth to power on (Should be before you see Scanning for devices) 2: Connecting... 3: Connected

kidskin-kettle-WANDER-sassy commented 4 years ago

Don't apologize! You got me this far! I think I'm falling into #3 I see:

[12/17/2019, 7:50:51 PM] [C] Initializing HatchBabyRest accessory...
[12/17/2019, 7:50:51 PM] [C] Waiting for bluetooth to power on
Setup Payload:

So I'm NOT seeing the "Connecting..." and "Connected" part

dgreif commented 4 years ago

@incubus1062 I did a little debugging on a second macbook and it turns out there is a fun issue on OSX specifically. If you have never connected to a bluetooth device, the address shows up as unknown. Once you connect once, it will remember the address for that device for future reference. I added a fix in v1.1.8 that should handle this for you automatically. Since you have two lights, it's a 50/50 chance it will get them backward the first time it connects to them. All you need to do is wait until you see Connected to XXX for each, and then restart homebridge. After that first connection, it should always get them right in the future. Let me know how it goes!!

FYI there is still an issue where it doesn't always connect when you turn a light on/off, but clicking the button again will get it to connect. I'll be working on this when I have time, but at least you should be able to connect and have them work most of the time now 😅

kidskin-kettle-WANDER-sassy commented 4 years ago

You're the man! Thank you, it worked! I see the on/off thing you mentioned, but clicking the button forces the connection. And it works with the 2 Hatch Baby Rests!

I'm a n00b, so here's an example of the config.json I used to get it working on my end for the two if anyone is interested.

{
  "bridge": {
    "name": "Homebridge",
    "username": "D1:23:4F:G2:HF:55",
    "port": 51826,
    "pin": "123-12-123"
  },

  "accessories": [
    {
      "accessory": "HatchBabyRest",
      "name": "Night Light 1",
      "macAddress": "D1:C2:32:RT:B2:12",
      "volume": 25,
      "audioTrack": 3,
      "color": { "r": 0, "g": 0, "b": 255, "a": 128 }
    },

    {
      "accessory": "HatchBabyRest",
      "name": "Night Light 2",
      "macAddress": "D6:E1:F2:54:30:12",
      "volume": 90,
      "audioTrack": 6,
      "color": { "r": 255, "g": 0, "b": 255, "a": 50 }
    }
  ]

}

Thanks again for all your help and the update. Very much appreciate it!

dgreif commented 4 years ago

@incubus1062 glad it's working! The current setup wil connect when you click the button, and stay connected for ~5 seconds before it disconnects again. I originally just left the connection open, but the bluetooth on Raspberry Pis is very weird compared to running on a mac. I'll keep messing around with it and see if I can come up with a good solution for both environments, but running it on a mac is definitely a better experience right now. Let me know if you run into any other issues