building on this, I installed a BLE peripheral simulator on my android phone.
It pretends to be a device having a battery and announces via BLE.
After activating it, I very much was able to see my phone, confirming your theory.
For easier reading it is possible to output the device name:
Just to resurrect this thread, I have recently switched all my smart plugs to the Shelly plugs, which enabled me to try this out. The good news is that using the new Private BLE you can use it to track iPhones or Apple watches, however I am struggling with how it is working and how it updates, as it is not very useful atm. I created an automation to read the attributes of the source of the Private BLE device when it changes, and then using mqtt_room map that to the correct room in the house. So the problem is it updates very slowly, even though it looks like the script on the shelly devices is running every 300ms. I wanted to understand a bit what is happening from an architecture pov, the shelly’s are all sending updates every 300ms (with 25 devices this is very chatty!) using rpc over http to the shelly integration (I assume), this is then being analysed somewhere in HA (where?) and passed to the Private BLE device as a distance measurement with an update of the mac address of the source. It takes sometimes 20 minutes to register a room change, the data is correct, I would just like to make this update happen a lot quicker.
Can you share? I dont see anything in the attributes or anywhere suggesting which shelly provided what info. Just ambiguous signal reading for only the watch is what i can find IRK from.
You get the IRK for the phone or watch by following the instructions in the Private BLE here . It’s a bit fiddly, especially when getting the IRK out of the XML stream, but it works. Once you have the Private BLE device showing up in Settings->Devices&Services->Private BLE, go into the device, click on the device in the Diagnostic panel, in the panel that opens up, you can pull down the Attributes tab, and the second source entry at the bottom will be the MAC address of the Shelly device that detected it.
If you get that working here is my automation, that fires every time there is a state change on the Private BLE device, it looks to see if the source has changed, if so, match the mac address to the real room, and post that to the mqtt_device. I have been trying to work out in the code what triggers the update of the source attribute of the Private BLE, when the Shelly integration is getting multiple updates per second, and where the logic is deciding which is the nearest Shelly device.
I think so, I have a bunch of Shelly UK plugs, added via the Shelly integration, then used the configure option in the Shelly integration for these devices and selected the Active Bluetooth scanning, which as far as I can make out adds and enables the bluetooth scanning script on the Shelly device. I then added my Apple watch as a Private BLE device and the info shown before started to populate. My HA instance is running on a Pi 4, not sure as such this makes the Shelly devices “proxying” the bluetooth. As far as I can make out the Shellys are sending the results of their bluetooth scans from the script using rpc over http via wifi direct to the HA instance running the Shelly integration, but I could have got this completely wrong.
Much thanks I still dont know why my Mac only shows my Apple Watch and can’t get the IRK from my phone.
My issue is the Private BLE integration for me only has state changes of home/away and so it doesnt change unless I leave. I have multiple Shelly 2PM +s and was hoping to use w/ more granular presense detection but from what I can tell this attribute doesnt change unless the home/away state does which is far less useful to know which proxy detected I came first.
So just to confirm, you have pressed the configure on the device in the Shelly integration page, and chosen active scanning. Then gone on to the web page of the Shelly device, chosen scripts, and made sure the script is running. Also, turn on the debug in the panel below the script on the shelly device and you should see the output of the scan running, it should be very verbose. I can only think that the script isn’t running, and that would stop the attribute info I am seeing on HA instance being displayed.
I believe I am only doing passive scanning atm. I don’t have any BT devices I want ported into HA so was currently only trying to leverage for presence detection.
The shelly script is running…etc I see the attribute but it just doesnt change unless the home/away state changes. If I walk thru the house the attribute doesnt change say if i was right next to a different shelly from what I can tell.
You maybe where I am then, it takes about 20 minutes before I get the attribute to change to reflect which room I am in. I have been trying to trace in the code what conditions define when it changes in the attribute but it is slow going,
I havent had the need/opportunity to mess with much exposed via the ‘attributes’ til lately but this. But from the logbook I never see additional updates unless the wholesale state changes from home/away. so intra house moves dont show up as such as an additional ‘home’ entry so not sure if Id validate such as you say 20 mins later if the attribute is in fact changing. But currently no way its usable as room detection. Didnt realize it supported flashing esphome but I’m too lazy to pull them out to UART flash them and dont really want to esphome flash them anyhow and rather keep native shelly code on em. Frustrating cause in the shelly script log you can see the exposed data is there.
For anyone looking for room/area-based BLE detection, the Bermuda integration (disclosure: I wrote it and have all the biases) works with Shelly Plus devices (and esphome proxies) and gives fast responses to area changes and home/away status.
I don’t have any Shelly’s myself (yet) but others are using it successfully. The Shelly’s do seem to have some limitations on how much broadcast traffic they’re willing to send (looks like they cache 3 seconds worth as of v1.0) but if you’ve multiple devices in an area that would probably even out OK.
It updates every second, as long as the proxies have sent new data.
It has support for Private BLE Device and iBeacons, so you can get iOS and Android devices working in it, too.
I’m interested in giving better support to those who are trying to use Shelly devices so any input on how to optimise the advert forwarding is welcome - although a lot of it seems to be well-covered in this thread already, so I might point people here for specific help.
@agittins thanks for the nudge (and for writing Bermuda), I had looked at Bermuda a while ago but I think at the time it didn’t support Private BLE, however, I have installed Bermuda now and it works perfectly, approx 1-2 seconds latency typically from arriving in a room to it displaying in HA! So for anyone else, using Apple Watch, Shelly Plus devices, Private BLE and the Bermuda integration you can get rock solid and responsive room presence.