Been chatting about this in another thread and someone suggested I put it in here as well.
I've been playing with the Hive API for a while to turn lights on, adjust the heating, etc. One of the things that Hive is missing is proper geofencing. i.e. If the house is empty it turns the heating down automatically. I've been messing around with this and have a fairly stable system in place where my Pi looks for the Bluetooth MAC addresses of our mobile phones. The problem is where people don't have a phone or, like me, have Bluetooth switched off when at home - on my phone, it KILLS the wifi speed.
So, I bought one of these Tile things and stuck it on my keyring. At first, I thought I had it working. But I think these devices are only visible for a short period every few seconds as it would variously flag me as in and out when I was always in. So far, this is my code - or the code I got from the Bluepy site plus some bits of my own:
Code: Select all
from bluepy.btle import Scanner, DefaultDelegate import bluetooth import time import datetime class ScanDelegate(DefaultDelegate): def __init__(self): DefaultDelegate.__init__(self) def handleDiscovery(self, dev, isNewDev): if isNewDev: ts = time.time() timestamp = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') score = 0 if "cc:1c:41:40:ec:11" in dev.addr: #if "c1:ed:da:df:55:46" in dev.addr: print "Andy in", timestamp score = score + 1 else: print "Andy out", timestamp scanner = Scanner().withDelegate(ScanDelegate()) devices = scanner.scan(15.0)
Code: Select all
Andy out 2018-12-01 13:41:10 Andy out 2018-12-01 13:41:14 Andy in 2018-12-01 13:41:20
After this, it writes the result to a MySQL table. Another script then reads the score and sets the heating temperature accordingly.
Anyway, I thought I'd put this in here to see if anyone had any better ideas for occupancy detection with multiple occupants. IFTTT is no good in this respect as it doesn't know who's still in if one person goes out, and it wouldn't work with other BLE devices.