Git Product home page Git Product logo

hass_bletracker's Introduction

Home Assistant Custom Bluteooth Tracker

Introduction

The following repo is a simple python3 script that works as a bluetooth tracker on home assistant. This was made since I wasn't able to find a reliable platform that was able to get me location tracking and let my home assistant know when i was home or away without any false triggers. This script is optimezed to know exactly when you are home and away, and can be tuned to avoid any false away notifcations.

What the script does is it initializes a thread that keeps track of your bluetooth device. If there are any false scans that don't discover the device, it will wait for a period of attempts before marking your device as away. You can simply modify the variables in the config files to suit your needs, but the current values should already be good enough.

The script should work with any bluetooth device.

In addition to tracking whether the device is available when a bluetooth scan is made from a raspberry pi, this script can also can connect to some bluetooth trackers. Currently I use the itag device which is a cheap bluetooth tracker that can be bought online for next to nothing. An image of the device is attached below.

alt text

This itag device is a cheap tracker that you do not need to charge for a few months, and in addition to help with location tracking it comes with a toggle button. The extra feature is the ability to customize what this button does, with any action on your home assistant.

Currently the script only tracks one particular device, however if the ability to track more devices are needed, feel free to create an ISSUE and I can build it out when I find some time

What You Need

  1. You will require a raspberry pi with bluetooth. I currently use the same pi running home assistant in a python virtual environment.

  2. You will also need to run this as root or modify permissions to be able to use the bluetooth as any user on the pi

I am Running HASSIO

If you are running hassio, I currently havent figured out how to make this an add-on due to some permission issues with the bluetooth driver in hassio. A current method of still being able to implement this would be installing this on a raspberry pi w , and when you reach step 9, simply change the config of your hassio and point it to your raspberry pi w's ip address

Installation:

  1. sudo apt install bluetooth libbluetooth-dev pkg-config libboost-python-dev libboost-thread-dev libglib2.0-dev python-dev

  2. git clone https://github.com/araa47/hass_bletracker.git

  3. pip3 install flask bluepy requests

  4. Identify the mac address of the device you want to track, you can run hcitool scan

  5. Now you can modify the config.py file and set the mac address of your device in that file. You can also modify threshold and scan_sleep_time, but this can be tuned later on if you have issues with the current values. If you are using a normal bluetooth device skip to step 7.

  6. If you are using an itag device you may want to enable itag to True, and also set the require home assistant url, password, and entity_id if you want to toggle your smart devices using the button on the itag.

  7. Run the program by typing in sudo python3 app.py

  8. This should start an api on port 5000 of your device. You can simply send requests to the following url to check whether the program is working pi_ip:5000/api/search/mac_addr , where pi_ip is the ip of your raspberry pi and mac_addr is the mac address of the device in the config file you are tracking.

  9. Now that the tracker is active, simple add the lines in the configuration.yaml file attached in this repo.

  10. Your device should show up on home assistant, enjoy!

Notes

If you are using the itag device and enabled pairing, when you walk out of range from the pi with the itag tacker, it will start beeping. This is pretty annoying right now, but seems to be a firmware feature on the itag so I havent been enable to disable this. If you are annoyed by this noise, you could aways open up the device and disconnect the buzzer.

Future Updates

Currently this script only supports tracking a single device, but it shouldn't be too difficult to add multiple device support. Will be adding this in once I get some more time.

hass_bletracker's People

Contributors

araa47 avatar

Watchers

Abby avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.