Open brianjking opened 5 years ago
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
MAC address
must be in lowercaseMAC 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...
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)
How to figure out which Tile is which?
sudo setcap 'cap_net_raw,cap_net_admin+eip' /srv/homeassistant/lib/python3.5/site-packages/bluepy/bluepy-helper
sudo stdbuf -oL hcitool lescan | grep Tile
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.briankeystile. State max length is 255 characters.
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...
https://community.home-assistant.io/t/bluetooth-presence-detection-without-raspberry-pi-3/35558/4?u=brianjking