Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tile Trackers on Raspberry Pi -- Investigating #163

Open
brianjking opened this issue Dec 5, 2018 · 7 comments
Open

Tile Trackers on Raspberry Pi -- Investigating #163

brianjking opened this issue Dec 5, 2018 · 7 comments

Comments

@brianjking
Copy link
Owner

https://community.home-assistant.io/t/bluetooth-presence-detection-without-raspberry-pi-3/35558/4?u=brianjking

@brianjking
Copy link
Owner Author

brianjking commented Dec 5, 2018

From @Bit-River here....

sudo apt-get install python3-pip libglib2.0-dev python-flask

sudo pip3 install bluepy
from flask import Flask
from bluepy.btle import Scanner, DefaultDelegate

class ScanDelegate(DefaultDelegate):
    def __init__(self):
        DefaultDelegate.__init__(self)

    def handleDiscovery(self, dev, isNewDev, isNewData):
        return()

scanner = Scanner().withDelegate(ScanDelegate())

app = Flask(__name__)

@app.route('/api/search/<string:mac_addr>', methods=['GET'])
def device_scan(mac_addr):
    scanner = Scanner().withDelegate(ScanDelegate())
    devices = scanner.scan(3.0)
    for dev in devices:
        if dev.addr == mac_addr:
            return("true")
    return("false")

@app.errorhandler(404)
def not_found(error):
    return("Not Found ", error)

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=False)
## Presense / Tiles Sensor via Pi Zero Hassbian

  - platform: rest
    name: Car Keys
    resource: http://192.168.18.143:5000/api/search/a4:e8:27:f4:3e:2a
sudo hcitool lescan
  • NOTE: MAC address must be in lowercase
  • NOTE 2: When Tiles are paired with the Tile Android app they do not broadcast a MAC address.

Have questions for @Bit-River outlined here

@Bit-River --

Hey - Thank you so much for this writeup! I think this MIGHT be what I'm looking to use my Tile Trackers for and hope you can help me out with some guidance..

I'm essentially looking to use Tile Bluetooth Trackers to identify if anyone is home or not home without running the Tile app on our phones with Bluetooth running 24/7. I tried to accomplish this using a Kindle Fire tablet which I installed the Play Store/Google Play Services/etc on and installed the Tile app. Upon logging in on the Kindle Fire and granting access to Bluetooth and location services the Tile app continually told me it wasn't able to receive location access no matter what I did.

Before I order a new Pi 3 Model B+ or maybe a Pi Zero W I wanted to check with you to ensure I'm understanding this properly... Unfortunately, I have a spare Pi 2 Model B and a Pi Zero here, but no bluetooth dongles available right now.

  • I currently have a Raspberry Pi 3 Model B running Home Assistant using the Hassbian installation method. You can find my full configuration repo here.

  • Using your Python script I should be able to keep Bluetooth turned OFF on my phone and use the binary_sensor to determine if a Tile is home or not home, is this correct?

  • Can I install this on my existing Pi 3 Model B which is running Hassbian already?

If I can install this I believe I need to run sudo apt-get install libglib2.0-dev python-flask and then activate my venv by running source /srv/homeassistant/bin/activate.

Once my venv is activated I can run pip install bluepy, correct?

Where would I actually place the Python script? Would this go inside of /home/homeassistant/.homeassistant?

Thank you so much! I really appreciate any guidance you can provide. You can also reach me on Discord at bk#5430 if that's easier for you.

Thank you! Cheers...

@brianjking
Copy link
Owner Author

brianjking commented Dec 5, 2018

D5:A8:5B:68:B3:92 Tile (Brian bag Tile)
D7:57:D9:9D:8C:B4 Tile (Spare Keys Tile)
D3:A5:72:80:83:6A Tile (Brian Keys Tile)
C8:31:53:38:C9:F1 Tile (Kinna's Tile)

https://community.home-assistant.io/t/bluetooth-presence-detection-without-raspberry-pi-3/35558/22?u=brianjking

How to figure out which Tile is which?

brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
@brianjking
Copy link
Owner Author

sudo setcap 'cap_net_raw,cap_net_admin+eip' /srv/homeassistant/lib/python3.5/site-packages/bluepy/bluepy-helper

brianjking added a commit that referenced this issue Dec 11, 2018
@brianjking
Copy link
Owner Author

sudo stdbuf -oL hcitool lescan | grep Tile

brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
brianjking added a commit that referenced this issue Dec 11, 2018
@brianjking
Copy link
Owner Author

homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.briankeystile. State max length is 255 characters.

@brianjking
Copy link
Owner Author

image

@hitokiri8x
Copy link

I have read briefly, for me you don't have to do all that with python and flask, just use the bluetooth le tracker and you are ok, as long as you don't pair the tiles to the app ( based on your info ).

configuration.yaml

device_tracker:
  - platform: bluetooth_le_tracker

known_devices.yaml

devicename:
  name: Band Bob
  mac: BLE_AA:BB:11:22:33:CC
  icon: mdi:watch
  track: yes
  hide_if_away: false

I'm using with my rpi2 + asus bt-400 (12€) and my mi band3.
I haven't set yet any logic behind, just start to track down by band.
Also I have set to track presence with wifi connection to the router https://github.com/mueslo/openwrt_hass_devicetracker

Also I suggest you to check for https://appdaemon.readthedocs.io/en/latest/ , python scripts in hass are very limited...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants