BluetoothLE Tile - Detect on raspberry Pi?

So I’m still trying to find the perfect solution for presence detection and it occurred to me that myself and my wife have Tile bluetoothLE trackers on our keys, so it would seems to be a pretty bullet proof way to detect presence, that would also work well for guests if I added one to the guest set of keys.

The problem is I’m not sure if the thing is actually detectable by HomeAssistant? Anyone know what protocol it uses and how I would find out what it’s ID is?

I have tried turning on the BLE scanning in HomeAssistant, but I get a load of things show up as I have various devices in my house that use BLE and no way of telling which is which?

Anyone done anything similar before?

Thanks

Gareth

As luck would have it, @bruhautomation just did a great video on BLE and Happy Bubbles.

Yes! This method should work for any beacons not just Tiles. Works for my two Tile keyrings.

I was getting ready to write this up properly but hopefully it makes sense for now :slight_smile:

I took this python script, and I run it on a CHIP computer: https://getchip.com/pages/chip

Pi3 is good too, anything with Python and Bluetooth really:

Uncomment this line, and change the log to somewhere HA can access.

#logOutFilename='/var/log/test_beacon.log'

Also make these changes:

FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'

becomes

FORMAT = '%(asctime)s - %(message)s'

Saves messy logs.

Log entries are like this:

2017-01-20 16:20:53,748 - Tag f1:c8:e1:b4:7c:9f is back after 7 sec. (Max 48). RSSI -88.
2017-01-20 16:20:55,049 - Tag f1:c8:e1:b4:7c:9f is back after 1 sec. (Max 48). RSSI -92.
2017-01-20 16:20:57,429 - Tag d1:f2:6a:3c:6a:9a is back after 3 sec. (Max 48). RSSI -80.
2017-01-20 16:20:58,739 - Tag d1:f2:6a:3c:6a:9a is back after 1 sec. (Max 48). RSSI -84.

The RSSI can be used as a (very) approximate range finder, but I’m not using that here.

In my binary_sensors.yaml I have the following (via ssh):

  - platform: command_line
    command: if ssh chip@[CHIP IP] "timeout -s SIGINT 5s tail -f /var/log/test_beacon.log" | grep 'f1:c8:e1:b4:7c:9f' > /dev/null; then echo 1; else echo 0; fi
    name: Bit_Rivers_Keys_tile
    payload_on: 1
    payload_off: 0
    sensor_class: occupancy

And repeat for however many beacons you want to track.

Adjust the 5s part, aka 5 seconds, to however long you think you need to prevent false absences.

In a sensors.yaml, if you want to flesh out the payload:

  - platform: template
    sensors:
      bit_rivers_keys_status:
        value_template: '{% if is_state("binary_sensor.bit_rivers_Keys_tile", "on") %}Home{% else %}Away{% endif %}'

If you’re running HAdashboard

<li data-row="2" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="bit_rivers_keys_tile" data-view="Habinary" data-title="Bit_Rivers' Keys" data-iconon="check-square" data-icon-off="ban"></div>
</li>

Here’s some aliases I made for the chip to help me test it, and as the starting point of other sensors:

alias ble=‘cat test_beacon.log | grep Detected | sort -u’
alias blec=‘cat test_beacon.log | grep Detected | cut -c38-55’
alias devices=‘echo && echo -n "Number of Unique Devices Detected: " && blec | sort -u | uniq -u | wc -l && echo’
alias listen=‘echo; tail -f test_beacon.log’

Of course, as an easy ‘away’ test just put the tile in a metal box / wrap in tin-foil :wink:

Hope I haven’t forgotten anything,

1 Like

Ok, so I kinda have this working using the room-assistant MQTT node module, but it is failing to find my tile.

It seems like the tile only advertises it’s presence in a way the pi can see when I turn the bluetooth off on my phone. If I do that I see a device with a name of “tile” show up, and I can use it to track my status fine.

But, as soon as I turn the bluetooth on on my phone the tile seems to stop advertising its status and the Pi no longer sees it.

Now, I assume the phone can still see it as it must be communicating somehow.

Anyone got any ideas, seems a shame to have to use an un-paired tile to make this work as it somewhat defeats the point of the tile . . .

Cheers

Gareth

I’ve noticed that with my set-up too, if the tile is near a stong phone bluetooth signal / competing with the detecting device - it gets lost.

It was one of the reasons I went with the Chip, small enough to put near the key box rather than where I usually leave my phone.

I’ve had to work around it rather than solve it.

The reason this happens is it’s because a part of the BLE protocol. The tile is in what’s called a ‘peripheral’ mode and your phone is in ‘central’ mode. Centrals can have multiple simultaneous connections to peripherals, but peripherals only usually have one.

A peripheral like your Tile will ‘advertise’ its services, basically sending a broadcast for anyone to hear, when it’s not connected to anything. But as soon as it connects to something, like your phone, it will then stop advertising. Because it’s connected. So that explains why you see it when you turn Bluetooth off your phone. If you don’t plan to use Tile with your phone and only want it for detection, you could forget it from the Bluetooth settings of the phone to not pair with it anymore, and then you could keep seeing the advertisements.

1 Like

@Bit-River are you saying that you got this working using a chip and a file, or a more generic BLE beacon?

Thanks for the explanation, such a shame their is no way to make this work without making the tile functionality null.

So stupid question, how does the phone know how to connect to the Tile once it has connected? I assume it still has to have some kind of address it can talk to?

I’ve recently done this with a cheap bluetooth dongle and some NUT tags, straight out the box and didn’t register them to any devices so they send out discovery all the time without issue. I modified the test_beacon.py code to broadcast over MQTT and I use the MQTT device_tracker component to bring it all together. Works well.

Not really got around to cleaning up the code enough to release, I should probably do that.

3 Likes

The phone knows how to connect with a Tile because each BT device also has a unique “MAC” address (like wifi or ethernet interfaces). During the pairing process that happens inside its app, the app makes the phone remember that device’s MAC and the app automatically connects to it when it detects its advertisements.

i am using ping component and it works perfectly.

Do you mind share your modified script? I recently received 2 tiles and want to use that for device_tracking, also using MQTT.
Thanks!

Installed Happy Bubbles Presence on RPi3. Configured it to talk to my MQTT server with authentication. Using a usb bluetooth module as hci0, builtin bluetooth is disabled. hcitool lesbian shows my beacons but the presence web interface does not show any of my beacons. Do I need to install Gatt or some other requirements?

The presence server doesn’t do the BLE detection itself. It receives MQTT messages with BLE information from the Happy Bubbles BLE detectors. They are the ones that do the actual detection of BLE beacons.

Thanks, I ended up using the RPI3 with room-assistant and this with a better antenna. RPI3 is also my garage’s snapcast/volumio device but with that antenna my garage detects the usb beacons in the cars from a pretty decent distance down the alley.

I came here hoping to find a solution to getting Tiles working with Hass too.

Here’s something interesting that I have noticed at work where we have quite a few Tiles in the building. Our Bluetooth enabled laptops and computers are seeing a whole bunch of Tiles that are advertising their presence.

It seems unlikely that so many Tiles would be out of range of their paired devices.

Is that the only possible explanation for it or could it be something else?

Hi guys.

Quick question :

I have happy bubbles installed on RPI 3. Can i use tile as a beacon if i were to get one? Or even Nut? Or other ‘device tracking’ beacon that appeared on kickstarter for that matter?

Or do they have their own ‘protocol’ or whatever that dont allow it for use with other devices?

Thanks in advance.

Tile will work, but apparently not when it’s paired with a (mobile) device. In that state it does not broadcast beacon signals?

Sounds cool… Would be very interested too.

Hi all – FYI, I’m currently working on a Tile integration, but it uses the unpublished REST API (not Bluetooth). My use case focuses on “did I leave my wallet somewhere?”, rather than “am I home?”

That said, if the Tile reports back to the Tile servers frequently enough, this could be useful in presence detection. I’ll keep you posted; if anyone is interested in trying a beta, let me know.

1 Like

Hi all – following up. I’ve submitted a PR for Tile integration: https://github.com/home-assistant/home-assistant/pull/10478

Running it in my own HASS instance and it works well so far:

04 PM

In terms of speed, I find that when I arrive home, my tile updates about a minute or so later on average. Again, might not be the very best at presence detection, but depending on what you’re doing, that could be a reasonable use case.

1 Like