mKeRix / room-assistant

Presence tracking and more for automation on the room-level
https://www.room-assistant.io
MIT License
1.28k stars 122 forks source link

Track iPhones via BLE #309

Closed mKeRix closed 3 years ago

mKeRix commented 4 years ago

Is your feature request related to a problem? Please describe. BLE tracking is quicker and a bit more reliable than BT Classic tracking. It would be awesome if we could also get this working for iPhones.

Describe the solution you'd like The idea for this was spawned in a reddit comment thread. It turns out you can make iPhones and Macs (not Watches!) act as a peripheral and advertise a custom service via BLE. For this we need to write our own app. That service can then provide a static ID, which we can tie to the periodically changed random ID. Based on this you can then actually track the iPhone based on its BLE advertisements. Each time we see a new ID advertise our custom service we connect to the service and find the "room-assistant" ID that belongs to the cloaked BLE MAC.

Describe alternatives you've considered

5a3ee commented 4 years ago

How feasible would this be? Am I understanding correctly that an app would be required? Haven’t done any Swift coding in a while have done just about enough to potentially make it work if room-assistant will definitely work with it.

mKeRix commented 4 years ago

As far as I understand it right now we would need an app that uses the Core Bluetooth APIs in peripheral mode. The app should register a BLE service that can also be called in the background (needs some special setting). The service should be advertised under a known name, so that we can discover it from room-assistant. After connecting to it it should provide a static ID (possibly protected by a password for privacy reasons). The static ID should probably be configurable in the app UI.

I have no clue if it would be allowed into the App Store like this though.

mKeRix commented 4 years ago

Crownstone goes a bit more into detail on how to achieve this here. In contrast to what was discussed on reddit this does not require connections to the device.

I spent some time writing a sample test app in Swift, which can now advertise stuff in the background. I now need to test my sample app to see if I can reproduce the findings from the link above.

mKeRix commented 4 years ago

Another update for the interested people: I managed to get this working! There still are some open tasks and the whole functionality isn't perfect yet, but it can correctly identify my test iPhones BLE advertisements without pairing even when it's in standby. I ended up limiting it to just the initial idea, as the additional information from Crownstone wouldn't add much benefit for the room-assistant functionality.

Next steps: clean up some things, make the app a bit prettier and then figure out how to make it available via TestFlight.

adamrutt commented 4 years ago

That’s awesome!

Get Outlook for iOShttps://aka.ms/o0ukef


From: Heiko Rothe notifications@github.com Sent: Monday, October 26, 2020 1:19:50 AM To: mKeRix/room-assistant room-assistant@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [mKeRix/room-assistant] Track iPhones via BLE (#309)

Another update for the interested people: I managed to get this working! There still are some open tasks and the whole functionality isn't perfect yet, but it can correctly identify my test iPhones BLE advertisements without pairing even when it's in standby. I ended up limiting it to just the initial idea, as the additional information from Crownstone wouldn't add much benefit for the room-assistant functionality.

Next steps: clean up some things, make the app a bit prettier and then figure out how to make it available via TestFlight.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FmKeRix%2Froom-assistant%2Fissues%2F309%23issuecomment-716155897&data=04%7C01%7C%7C73456204ec31463e5a7408d878f108e2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637392323908311275%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=tvopQuW4vBSJLA0YIGP3IFrcyXZJrjABMMZj68Awa6Y%3D&reserved=0, or unsubscribehttps://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAEVSDTSWGZ43UINOPYYST53SMQXYNANCNFSM4SYVHGDA&data=04%7C01%7C%7C73456204ec31463e5a7408d878f108e2%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637392323908311275%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=Kl4ig%2Fy2nJxJaNyj0sitP%2BOYnQYGtU8bx81qAIFzGMc%3D&reserved=0.

mKeRix commented 4 years ago

I've submitted the app version I had to TestFlight for review, but since the UI part is very simple and it is more or less just a tool for setting background Bluetooth settings I fear that it may be rejected on the grounds of not providing a "minimum functionality". I still wanted to see if it's enough for TestFlight in this first version.

If this fails I'll have to think of some features I could add to the app (maybe viewing current RSSI levels for easier tuning?). Implementing those will then take some more time, as I'm not really versed in Swift or iOS development.

srmooney commented 4 years ago

What about adding as part of the Home Assistant Companion App?

mKeRix commented 4 years ago

We could ask, but I don't think they would want it in there. The Home Assistant app currently asks for no Bluetooth permissions, this requires "Bluetooth always" permissions. I feel like it would be hard to argue to include this code and request additional permissions for a project which is not under their control.

At least this could be a fun exercise for getting into Swift and all that stuff, even if it takes some time.

mKeRix commented 4 years ago

Good news! The app has been approved for beta testing via TestFlight by Apple. I will distribute a new beta release of room-assistant and the app link soon.

rjbudke commented 4 years ago

I would love to help beta test.

github-actions[bot] commented 4 years ago

:tada: This issue has been resolved in version 2.13.0-beta.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

mKeRix commented 4 years ago

You can try this now! You will need to install the beta version of room-assistant and the app on any device you want to track. The app is available through TestFlight here: https://testflight.apple.com/join/OpCkeHf8

Would love to hear any feedback you might have.

fidonet commented 4 years ago

Hi

Have this installed and whilst other BLE devices are showing up in the logs, there’s no sign of either of my iOS devices ... not the iPad Pro or my iPhone 11

I granted Bluetooth permissions to the TestFlight app / RA app in TestFlight but I’m not convinced its actually doing any advertising currently

Thoughts?

– Jon Morby

On 11 Nov 2020, at 20:40, Heiko Rothe notifications@github.com wrote:

 You can try this now! You will need to install the beta version of room-assistant and the app on any device you want to track. The app is available through TestFlight here: https://testflight.apple.com/join/OpCkeHf8

Would love to hear any feedback you might have.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

maa-x commented 4 years ago

I only have a single device to test with, but am noticing the same behaviour. Grep on output for the first three chars of the ID displayed in the app doesn't return anything.

Also a feature suggestion, it'd be nice to be able to copy the ID from the app! Thank you tons for the hard work and excited to see this happening!

mKeRix commented 4 years ago

Are you on the latest room-assistant beta version as well (v2.13.0-beta.1)? You should see some logs saying "attempting app discovery for tag xyz", hopefully followed by a message that companion app was discovered with the IDs that you are shown in the app. Sometimes it also helps to turn Bluetooth off and then on again in the settings (not the control center!).

You can also try and see if the service is being advertise correctly by installing the nRF Connect app on an extra device (e.g. your iPad), then scanning and connecting to the device that you want to track (e.g. iPhone). After connecting you can swipe over to the left on the device details page, which should show an attribute table. Does this table contain the room-assistant service (UUID starting with 5403C8A7) and characteristic (UUID starting with 21C45F33)? If you click the little down arrow on that characteristic, does it show some value?

maa-x commented 4 years ago

Running 2.13.0-beta.1, however I am not seeing any logs stating that it is attempting app discovery for tag xyz. Do I need to add the UUID to the whitelist even if I have not seen it in the logs with an empty whitelist?

How would room-assistant know that the UUID I gave it is for the companion app?

maa-x commented 4 years ago

Have added the UUID to the whitelist, configuration looks like this now:

global:
  integrations:
    - homeAssistant
    - bluetoothLowEnergy
homeAssistant:
  mqttUrl: 'mqtt://192.168.1.xxx:1883'
  mqttOptions:
    username: mqtt-user
    password: pass
bluetoothLowEnergy:
  hciDeviceId: 0
  whitelist:
   - id-in-companion-app-with-dashes

But I still do not see companion app logs.

mKeRix commented 4 years ago

The ID for the companion app looks different than MAC addresses, it shouldn't make much of a difference though. I suspect that an assumption that I have made to limit the amount of devices it tries to discover from isn't applicable for the real world and only worked for my test device.

You can help me try this out with some manual editing of the code. If you are on a Pi Zero, you can edit /opt/nodejs/lib/node_modules/room-assistant/dist/integrations/bluetooth-low-energy/bluetooth-low-energy.service.js. In line 251 you should see a check for the manufacturerData length. Could you decrease to e.g. 6 (or even take it out completely) and see if that makes the companion app show up? So from tag.peripheral.advertisement.manufacturerData.length > 10 to e.g. tag.peripheral.advertisement.manufacturerData.length > 6.

I will also see if I can test with some more devices.

EDIT: After editing the file you need to restart room-assistant of course.

maa-x commented 4 years ago

Set it to 1 and it was attempting connections with everything more or less. Set it to 6 and it does attempt a couple unsuccesful connections but most importantly it discovers the companion app.

Testing a little bit further now, I don't see the MQTT topic I need to add to home assistant to add that device to home-assistant. I also forgot how to debug that element.

This is all I see in the logs (verbose off):

11/12/2020, 11:31:45 - info - BluetoothLowEnergyService: Attempting app discovery for tag 7214500ef242
11/12/2020, 11:31:46 - info - BluetoothLowEnergyService: Discovered companion app with ID UID-VERY-LONG-AND-MANY-DASHES for tag 7214500ef242
11/12/2020, 11:31:46 - info - BluetoothLowEnergyService: Discovered new BLE peripheral UID-VERY-LONG-AND-MANY-DASHES with ID UUID-VERY-LONG-AND-MANY-DASHES and RSSI -82
mKeRix commented 4 years ago

Alright, seems like we need to fine-tune that number in the next versions. I will put out a new beta with the value decreased later today so that this at least works without manually editing stuff.

The entity should appear automatically in HA as long as the ID is in the whitelist, at least if you have auto discovery enabled in HA. The state topic for the sensor should be in room-assistant/sensor/ble-UID-VERY-LONG-AND-MANY-DASHES/state.

fidonet commented 4 years ago

Morning

After reading that counter to 1 I can also confirm that the companion app is detected and so far it seems to be working as anticipated!

Thanks for adding this functionality, truly amazing!

– Jon Morby

On 12 Nov 2020, at 11:50, Heiko Rothe notifications@github.com wrote:

 Alright, seems like we need to fine-tune that number in the next versions. I will put out a new beta with the value decreased later today so that this at least works without manually editing stuff.

The entity should appear automatically in HA as long as the ID is in the whitelist, at least if you have auto discovery enabled in HA. The state topic for the sensor should be in room-assistant/sensor/ble-UID-VERY-LONG-AND-MANY-DASHES/state.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

maa-x commented 4 years ago

I believe I have everything setup correctly as it stands, however I am not seeing the entity appear in the integration - despite other sensors (cluster leader and cluster size) being created successfully.

In my logs, I see this:

11/12/2020, 2:54:41 PM - info - BluetoothLowEnergyService: Discovered companion app with ID UID-VERY-LONG-AND-MANY-DASHES for tag lowercaseidnodashes
11/12/2020, 2:54:41 PM - info - BluetoothLowEnergyService: Discovered new BLE peripheral UID-VERY-LONG-AND-MANY-DASHES with ID UID-VERY-LONG-AND-MANY-DASHES and RSSI -55

Indicating that the companion app was discovered by room-assistant.

I have since deleted the MQTT integration and restarted the entire process twice, but to no avail. Both Rasperry Pies have been restarted too.

The config file for both is this

global:
  integrations:
    - homeAssistant
    - bluetoothLowEnergy
homeAssistant:
  mqttUrl: 'mqtt://192.168.1.232:1883'
  mqttOptions:
    username: mqtt-user
    password: mqtt-pass
bluetoothLowEnergy:
  hciDeviceId: 0
  whitelist:
   - uuid-very-long-many-dashes-but-lowercase

Listening for events with topic room-assistant/sensor/ble-UID-VERY-LONG-AND-MANY-DASHES/state shows no events in Mosquitto / Home assistant.

maa-x commented 4 years ago

The issue lies in the fact that unlike the other BLE entities, these have to be upper case in the config, as such:

global:
  integrations:
    - homeAssistant
    - bluetoothLowEnergy
homeAssistant:
  mqttUrl: 'mqtt://192.168.1.232:1883'
  mqttOptions:
    username: mqtt-user
    password: mqtt-pass
bluetoothLowEnergy:
  hciDeviceId: 0
  whitelist:
   - UID-VERY-LONG-AND-MANY-DASHES
maa-x commented 4 years ago

Predictably, we're now hitting Apple's restriction regarding BLE tracking.

If the iPhone is locked, no more advertisements are made. I imagine there is no workaround for this as I'd expect we would have otherwise seen functional "Track and trace" type apps not using the Apple SDK for it. Unless we can initiate a sort pairing request that would allow locked tracking, this is probably the best we'll get.

Other than that, I am seeing significantly more robust tracking in a small flat. Previously on Bluetooth Classic, I would constantly be jumping from room to room, which is not the case now, as the BLE integration tracks the phone much better.

maa-x commented 4 years ago

This issue from a different but very similar project (track and trace basically), indicates that it might be possible by flipping the relationship once the app goes into the background: instead of asking the iPhone to advertise, room-assistant should instead broadcast beacons whose handling can be delegated to iOS. The companion app would subsequently have to emit the mosquito packet itself (if I'm understanding correctly).

EDIT: I'm only guessing, but would it be possible to request to be woken-up by Apple if the device is moving?

EDIT2 (apologies I'm basically thinking out loud): Now that we have a companion app, I am wondering if it is not possible to flip the relationship and have the app report its location, rather than the Raspberry Pi? eg, we would make each instance of room-assistant a beacon and have the iPhone send a mosquitto packet to home-assistant telling it which room (beacon) it is closest to. From the thread linked above, this seems doable even with the app in the background.

EDIT3: The app also goes into the background randomly, even with the phone unlocked.

mKeRix commented 4 years ago

@MaxIsMyName The lowercase/uppercase confusion is a good point, there is no reason why case should play any role in these lists. Making it case insensitive would presumably be any easy change that could improve user experience. Something for my list. :)

Apart from that: your findings are interesting, as they do not match mine. I've had this running for multiple days now, using the phone like I normally would. I only opened the app when I set it up, after that I haven't touched it at all. The tracking still worked even while the phone was locked for me, I just saw some brief outages (ca. 20min) every now and then which I haven't had time to analyze yet.

The app is specifically built to make use of the background modes, which allows apps to keep their BLE services available in the background, even after the app itself has already been removed from memory. That is also why it requests the "Bluetooth Always" permission.

Flipping would be a possibility, but it would turn a lot of things upside down as it switches the tracking context completely. As far as I can remember iOS will only alert the app that it entered or left a beacon region, but not continuously wake the app with new RSSI values. This is also the feature that is available in the Home Assistant app itself. Plus, using the location permissions (which would be needed for this) supposedly put the app under much more scrutiny in the review process. I also read that abusing such little tricks as waking the app via some permissions to do something unrelated will not pass the review process.

mKeRix commented 4 years ago

I just put out a new version that reduces the number we talked about above to 6, which should hopefully work out fine for most of you.

maa-x commented 4 years ago

To give an idea of how the tracking has been working for me, here are two images of the tracking. Red is not_home. The other two rooms are tracked pretty well.

9AC89464-6970-4622-87B8-89283DC1871D EB9B4832-6364-456E-900C-6192BB217986

mKeRix commented 4 years ago

I think there's still some potential to improve, both in detection quality and stability. At least I have some ideas to try. Atm I'm a bit pre-occupied with other things, but I'll get back to this!

robbiet480 commented 4 years ago

We could ask, but I don't think they would want it in there. The Home Assistant app currently asks for no Bluetooth permissions, this requires "Bluetooth always" permissions. I feel like it would be hard to argue to include this code and request additional permissions for a project which is not under their control.

At least this could be a fun exercise for getting into Swift and all that stuff, even if it takes some time.

I don’t have a problem with this, as long as we made it an opt in functionality. @zacwest what do you think? Seems straightforward enough.

zacwest commented 4 years ago

As long as it's framed as "this is useful if you have something receiving it" it should be okay as an opt-in feature.

I would mostly be worried about app approval with something like this which can passively monitor users without an obvious user-facing product-level feature. Most apps I have seen which do this are either bluetooth accessory (e.g. the Bose app), games, or peer to peer payment like Cash.

maa-x commented 4 years ago

If it helps, the nRF Connect app (App Store), does pretty much the same thing as has been on the App Store since 2016.

eximo84 commented 4 years ago

Out of interest should this allow esphome ble to also track and iOS device?

mKeRix commented 4 years ago

I would mostly be worried about app approval with something like this which can passively monitor users without an obvious user-facing product-level feature. Most apps I have seen which do this are either bluetooth accessory (e.g. the Bose app), games, or peer to peer payment like Cash.

@zacwest That was also my fear. I think it's a good sign that it made it through TestFlight review, but of course that isn't really any indication that it would pass normal review. I do think that there are some ways to enhance privacy without sacrificing ease of use though. The service could for example only be advertised when the phone is at considered at home, be that by checking the current WiFi or by working with geofences.

@eximo84 Yep, it should in theory. Of course ESPHome or esp32-mqtt-room would need to be updated to make use of this additional functionality similar to how room-assistant does it.

eximo84 commented 4 years ago

@mKeRix Yep, it should in theory. Of course ESPHome or esp32-mqtt-room would need to be updated to make use of this additional functionality similar to how room-assistant does it.

Great, I assume the code the app outputs is a 128but UUID? Esphome supports this but it wont discover the device. Ill reach out to ESP devs and see if they can investigate. Thanks for your reply.

mKeRix commented 4 years ago

@eximo84 The app registers a BLE GATT service and characteristic under constant UUIDs (can be found in the code, once this is more stable I was planning on documenting it for other devs). Reading from that characteristic will give a UTF-8 encoded string containing another ID that is specific to the app installation. The characteristic can be read without pairing. Essentially what needs to be implemented is: filter out Apple devices by looking at the manufacturer data in the advertisements, try to connect to them and check if the known UUIDs exist - and if they do read the value and put it to a cache matching the currently advertised MAC to the ID.

arsaboo commented 4 years ago

Just to make sure, can we use the bluetoothLowEnergy along with bluetoothClassic for the same device? I am trying to track my iPhone and I just added the bluetoothLowEnergy, but that tracker does not show up.

maa-x commented 4 years ago

@arsaboo You'll need two bluetooth devices (not phones but dongles on the Pi for example) as mentioned in the documentation. You can specify the hciDevice in the config.

mKeRix commented 4 years ago

Actually both bluetoothLowEnergy and bluetoothClassic can run on the same adapter in newer versions of room-assistant, so no extra dongle required anymore (it does improve performance though). Are you running the beta and the companion app @arsaboo?

arsaboo commented 4 years ago

Yes, I got the companion app version - 0.1.0 (2) from TestFlight (link posted on Reddit). Here's my config.yml:

global:
  instanceName: master
  integrations:
    - homeAssistant
    - bluetoothClassic
    - bluetoothLowEnergy
homeAssistant:
  mqttUrl: 'mqtt://192.168.2.212:1883'
  mqttOptions:
    username: blah
    password: blahblah
bluetoothClassic:
  addresses:
    - '64:70:33:XX:XX:XX'
    - 'B8:53:AC:XX:XX:XX'
bluetoothLowEnergy:
  hciDeviceId: 0
  whitelist:
   - B3707D2B-B0CA-XYZ-XYZ-XYXXZZZXCCX

I only see the bluetoothclassic trackers.

arsaboo commented 4 years ago

I am on "sw_version": "2.12.0",. I am guessing that may be the problem. I did run sudo npm i --global --unsafe-perm room-assistant, but I am guessing it does not install the beta version.

arsaboo commented 4 years ago

Ok, so I updated to "sw_version": "2.13.0-beta.2", but still the same. I do see some BLE devices discovered in the logs:

 BluetoothLowEnergyService: Discovered new BLE peripheral TS6300 seri with ID 74bfc0e74aed and RSSI -59
Nov 19 11:20:33 study room-assistant[16215]: 11/19/2020, 11:20:33 - info - BluetoothLowEnergyService: Attempting app discovery for tag 691e8ce075ea
Nov 19 11:20:34 study room-assistant[16215]: 11/19/2020, 11:20:34 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 691e8ce075ea with ID 691e8ce075ea and RSSI -69
Nov 19 11:20:34 study room-assistant[16215]: 11/19/2020, 11:20:34 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 1e18950e095d with ID 1e18950e095d and RSSI -58
Nov 19 11:20:34 study room-assistant[16215]: 11/19/2020, 11:20:34 - info - BluetoothLowEnergyService: Attempting app discovery for tag 7ae63d8e59b1
Nov 19 11:20:34 study room-assistant[16215]: 11/19/2020, 11:20:34 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 7ae63d8e59b1 with ID 7ae63d8e59b1 and RSSI -64
Nov 19 11:20:35 study room-assistant[16215]: 11/19/2020, 11:20:35 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 538f14543791 with ID 538f14543791 and RSSI -80
Nov 19 11:20:35 study room-assistant[16215]: 11/19/2020, 11:20:35 - info - BluetoothLowEnergyService: Discovered new BLE peripheral cc6ea4e9ea91 with ID cc6ea4e9ea91 and RSSI -84
Nov 19 11:20:35 study room-assistant[16215]: 11/19/2020, 11:20:35 - info - BluetoothLowEnergyService: Attempting app discovery for tag 79ddcbcb12fa
Nov 19 11:20:36 study room-assistant[16215]: 11/19/2020, 11:20:36 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 6a8d7e2226ee with ID 6a8d7e2226ee and RSSI -77
Nov 19 11:20:36 study room-assistant[16215]: 11/19/2020, 11:20:36 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 79ddcbcb12fa with ID 79ddcbcb12fa and RSSI -58
Nov 19 11:20:36 study room-assistant[16215]: 11/19/2020, 11:20:36 - info - BluetoothLowEnergyService: Discovered new BLE peripheral SHIELD with ID 421bead275df and RSSI -78
Nov 19 11:20:37 study room-assistant[16215]: 11/19/2020, 11:20:37 - info - HomeAssistantService: Device tracker requires manual setup in Home Assistant with topic: room-assistant/device_tracker/bluetooth-classic-64-70-33-xx-xx-xx-tracker/state
Nov 19 11:20:39 study room-assistant[16215]: 11/19/2020, 11:20:39 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 273aaea3894f with ID 273aaea3894f and RSSI -74
Nov 19 11:20:40 study room-assistant[16215]: 11/19/2020, 11:20:40 - info - BluetoothLowEnergyService: Attempting app discovery for tag d0034b33ae24
Nov 19 11:20:42 study room-assistant[16215]: 11/19/2020, 11:20:42 - error - BluetoothClassicService: Failed to retrieve RSSI for 64:70:33:0E:2D:C3: Trying to lock adapter 0 even though it is already locked
Nov 19 11:20:43 study room-assistant[16215]: 11/19/2020, 11:20:43 - info - HomeAssistantService: Device tracker requires manual setup in Home Assistant with topic: room-assistant/device_tracker/bluetooth-classic-b8-53-ac-xx-xx-xx-tracker/state
Nov 19 11:20:46 study room-assistant[16215]: 11/19/2020, 11:20:46 - info - BluetoothLowEnergyService: Attempting app discovery for tag 6241db520224
Nov 19 11:20:50 study room-assistant[16215]: 11/19/2020, 11:20:50 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 6241db520224 with ID 6241db520224 and RSSI -81
Nov 19 11:20:52 study room-assistant[16215]: 11/19/2020, 11:20:52 - info - BluetoothLowEnergyService: Discovered new BLE peripheral d0034b33ae24 with ID d0034b33ae24 and RSSI -75
Nov 19 11:20:52 study room-assistant[16215]: 11/19/2020, 11:20:52 - info - BluetoothLowEnergyService: Attempting app discovery for tag 45dd8e541466
Nov 19 11:20:54 study room-assistant[16215]: 11/19/2020, 11:20:54 - error - BluetoothClassicService: Failed to retrieve RSSI for B8:53:AC:41:96:C1: Trying to lock adapter 0 even though it is already locked
Nov 19 11:20:59 study room-assistant[16215]: 11/19/2020, 11:20:59 - info - BluetoothLowEnergyService: Discovered new BLE peripheral e7e736d537e3 with ID e7e736d537e3 and RSSI -87
Nov 19 11:21:05 study room-assistant[16215]: 11/19/2020, 11:21:05 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 45dd8e541466 with ID 45dd8e541466 and RSSI -78
Nov 19 11:21:16 study room-assistant[16215]: 11/19/2020, 11:21:16 - info - BluetoothLowEnergyService: Discovered new BLE peripheral 757ed9a63070 with ID 757ed9a63070 and RSSI -78
mKeRix commented 4 years ago

The logs look ok to me at first glance. I assume you don't see any message like "discovered companion app" on any of your instances? Do you run the bluetoothLowEnergy integration on all of your instances? Can you open the room-assistant app again and then restart the closest room-assistant instance to see if that changes anything?

If you have another iOS device like an iPad available you could also check if the phone broadcasts the right data with that, let me know if you'd be interested in the necessary steps for that.

jack-yen-by commented 4 years ago

I have the similar issue. The log did show "discovered companion app"; however, I'm unable to see the entity appear in home assistant. Is there anything else I should be looking for? I am using the latest beta for both room assistant and companion app.

mKeRix commented 4 years ago

@jack-yen-by If you see that log message that is a great sign! Can you confirm that the ID is in the whitelist exactly as it is stated by the log message/app? All uppercase, with dashes.

Also, are you running the bluetoothLowEnergy integration on all instances? Do you see any of the other room-assistant entities in Home Assistant?

domoritz commented 4 years ago

Relatedly, it would be awesome if you could copy the device id from the companion app.

jack-yen-by commented 4 years ago

@mKeRix, found the issue. I used whiteList instead of whitelist. Now it is working. It's jumping between pi4s but pi0s are not picking it up even though i'm right next to pi0. Any idea why that might be the case? I have 3 pi4s and 5 pi0s around the house.

Based on the log below, it doesn't seem like pi0 is even trying to discover the BLE devices.

--edit--

restarted a few times and instead of the ansible, i went into the pi0 and manually update something and manual restarted, I was able to get it to work on pi0. Everything seems to work great so far.

I do noticed that I have to restart the bluetooth every so often when i leave the house and come back every now and then for it to work properly again. I wonder if the companion app just dies out in the background or something?

arsaboo commented 4 years ago

Ok....after restarting everything a couple of times, I see a new ble tracker. It has a state not_home. I am running BLE on two Pis now.

mKeRix commented 4 years ago

@jack-yen-by I think there is an issue with how room-assistant grabs and shares the companion app data, which may lead to what you described. I have observed the same in my test setup after a while of running. I have some ideas on what I could change and will try them out soon-ish.

yetdog commented 4 years ago

First of all - thank you so much for all your hard work on this! I've been running R-I for a number of months now across 6 PiZeroW's with varying degrees of success. Mainly - "it kind of works but I can't fully rely on it so it's just a toy right now" - with classic BT. Very encouraged to see the BLE stuff working. Ok on to my experience:

Like I said I have 6 Pi0-W's around the house, and I'm leveraging Ansible to configure them all. Here's my relevant config:

vars:
    ansible_user: pi
    ansible_password: <pi password>
    room_assistant_version: 2.13.0-beta.2
    room_assistant_global_config:
      global:
        integrations:
          - bluetoothLowEnergy
          - homeAssistant
        cluster:
          quorum: 4
      homeAssistant:
        mqttUrl: <mqtt url>
        mqttOptions:
          username: <mqtt user>
          password: <mqtt pass>
      bluetoothLowEnergy:
        hciDeviceId: 0
        whitelist:
          - 201056D6-DFE9-446B-YYYY-xXXXXXXXXX

It seems that only two of the 6 Pi0W's has the companion app discoveries. The other 4 Pis give me entries like this:

BluetoothLowEnergyService: Discovered new BLE peripheral 4cccccc25f08 with ID 4cccccc25f08 and RSSI -90

But only two of the Pi's log these type:

info - BluetoothLowEnergyService: Discovered companion app with ID 201056D6-DFE9-446B-8A27-BAF2121F6882 for tag 75bef5928fda

Conversely, the room tracking only flaps between the two Pi's that discover the companion app, and none of the other 4.