The BTLE Multi-User presence app will allow you to get information from BT devices into Hubitat in order to set presence for users. This will work with Tile Mate devices, and any other device that transmits BT presence every few seconds (configurable for what your threshold is). Wherever you run the python script from is your "location" and you can assign different "users" to be looked for within the script, thus it's multi-user. This idea was borrowed from here.
The added benefit of using this is that you don't need to invest in expensive presence devices, assuming you have a Linux device with bluetooth LE capabilities and it's in a location where it can see the BTLE devices you wish to track.
There is a thread on this topic in the hubitat forums.
To get started you'll need:
- A Linux device with BTLE capabilities - cheapest is Pi Zero W, but a beefier Pi works too. I would not recommend virtualizing this with Docker as you need access to the bluetooth stack.
- Patience - you'll have to figure out what bluetooth device is actually the one you care about - this is a little trial and error and you can use RSSI information to determine how close/far away things are.
- Hubitat Hub
- Virtual BTLE Presence Device
- My Hubitat app assigned to your Virtual Presence Device(s) above
- Before you invest time in getting hubitat setup for this, make sure you can successfully see your beacon and have the right software installed. I'm not going to go into details here, but they are losely based on this.
- I do know that Raspberry Pi wireless devices support this out of the box. You also have to run this as root
- Login to your Pi
sudo apt-get update sudo apt-get install -y libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev libical-dev libreadline-dev python-bluez python-requests
- Make sure you can see your BT interface
$ hciconfig hci0: Type: Primary Bus: UART BD Address: DC:A6:32:0B:0A:A7 ACL MTU: 1021:8 SCO MTU: 64:1 UP RUNNING RX bytes:869075428 acl:0 sco:0 events:24957693 errors:0 TX bytes:275256 acl:1 sco:0 commands:30480 errors:0
- Make sure your test script runs. If not, you may need additional modules. Again, check the above install instructions in #1 in case it is helpful.
$ sudo python ./test_beacon.py
- If you see a bunch of MAC addresses scrolling by, this all the bluetooth devices your system can see. Good luck finding out which one is the BT device you care about. I know the Tile Mate devices broadcast once every 15-20 seconds, so look for an entry with "back after 16 secs" and those will be your Tile Mate devices. Grab the mac addresses you care about. Note: You can also adjust time_threshold at the top of test_beacon.py to only see things that beacon at time interverals LONGER than time_threshold. This is currently set to 10, so it should see Tile Mate devices as they beacon at >10 seconds.
- Update your mac addresses in TAG_DATA array in check_beacon_presence.py. Here is my example. I named my tiles "Brian" and "Amy" (ties to part of the device name in Hubitat). I have a timeout of 30 seconds for them (if not seen for 30 secs, they get flagged as AWAY), and the area І'm running my script from is "Home" (ties to the device location in Hubitat), and SWITCH_MODE means it only reports changes to Hubitat. We don't have the URL yet, so move on to the next step to do that. If you leave it in REPEAT_MODE, the RSSI of the device will be set as the signal strength in the virtual device.
TAG_DATA = [ ["Brian","fe:31:0b:b0:c6:12",30,0,"Home",SWITCH_MODE], ["Amy","c8:ae:c6:e0:dc:12",30,0,"Home",SWITCH_MODE], ]
- Go to Drivers Code and create a new device using this Virtual BTLE Presence Device.
- Go to Devices and create a new virtual device '''name it whatever the location name will be called in your script with a - and a USER after it'''. Mine are called "Home-Brian" and "Home-Amy". Network Device ID can be '''HOME_VIRTUAL_PRESENCE_1''' for the first. Device Type will be the type you configured in step 1. For this example, mine is named "Home-Brian" and my location name above is "Home". You can create multiple virtual devices and give them different names after the "-" then you can reference them after the location below in #5 and use that new webhook in #8. There should be no space before and after the "-" in the device name!
- Go to Apps Code and create a new App from code BTLE-Presence-app.groovy. Save it. Click Oauth.
- Install the User App and select all the virtual presense devices you created that you want to control.
- Copy the Endpoint URL (I use the internal URL), and use that in the URL_HUBITAT entry for the python script above. It should look something like this: http://192.168.1.30/apps/api/414/location/?user=PARAM_NAME&location=PARAM_IDX&cmd=PARAM_CMD&access_token=3523535-1356-235623465-xxxxx-xxxxx
- Now paste this URL into your browser and make sure you get the following
response:
["Yep, this is the right URL, just put it into check_beacon_presence.py URL_HUBITAT. Make sure your location name (next to last element of each array in TAG_DATA) in the script matches the device 'location-name'"]
- Install the url in the python script, then run it as root. Also you'll want to set it up to run as root (see Autorun as Service section here.
sudo python ./check_beacon_presence.py
- You should now have a virtual presence sensor that you can tie to Hubitat actions. You can create as many virtual presense sensors as you have tags.
$ sudo python ./check_beacon_presence.py Brian - HOME - http://192.168.1.30/apps/api/414/location/?user=Brian&location=Home&cmd=HOME&access_token=806621fc-6d62-42e8-a07c-xxxxxxxxxxxxxx Amy - AWAY - http://192.168.1.30/apps/api/414/location/?user=Amy&location=Home&cmd=AWAY&access_token=806621fc-6d62-42e8-a07c-xxxxxxxxxxxxxx Amy - HOME - http://192.168.1.30/apps/api/414/location/?user=Amy&location=Home&cmd=HOME&access_token=806621fc-6d62-42e8-a07c-xxxxxxxxxxxxxx
- Edit check_beacon_presence.service to point to where you have this packge existing on your system.
- Copy it; enable it, start it.
$ chmod 755 check_beacon_presence.py $ sudo cp check_beacon_presence.service /lib/systemd/system/ $ sudo chmod 644 /lib/systemd/system/check_beacon_presence.service $ sudo systemctl daemon-reload $ sudo systemctl enable check_beacon_presence.service $ sudo systemctl start check_beacon_presence.service
- Check to see if it's running
$ sudo systemctl status check_beacon_presence.service -l
There is a thread on this topic in the Hubitat forums. Please check here for help.
Bug me on Twitter at @brianwilson or email me here.