Fitbit Powered Home Automation
My new employer, Odecee, runs innovation events every quarter where employees are given a hectic 48 hours to work on an idea. This time around I worked on a project leveraging Apache Storm, which was great fun, but the thing that really caught my attention was the white-paper research being done by the iBeacon team. In particular, the fact that the Bluetooth LTE software they were using on their iPhones was able to detect my Fitbit Flex, through the office floor. A little creepy that my location could be tracked by anyone with an iPhone in the vicinity, but it got me thinking, could I use this data leakage for good?
Home automation was the first thing that came to mind. Electricity prices in Australia are outrageously expensive, and I was looking at a way of controlling my appliance usage using a WeMO Switch. Traditionally you interact with these switches using either the WeMO Switch + Motion product to detect movement, by manually controlling the devices with your phone, or more recently using IFTTT’s location services. All these approaches are cumbersome. I want my house to know when I’m home, and this is where the Fitbit comes in. I wear my Fitbit almost all the time, so it’s a perfect way of detecting my presence.
So the plan was to use a Raspberry PI with a Bluetooth 4.0 USB Dongle to scan for my Fitbit. I would then connect the Raspberry Pi to IFTTT (somehow), which has a handy WeMO channel for controlling the plug.
I wrote a tiny Python script which scans for the presence of my Fitbit using the Bluez hcitool utility. When my Fitbit’s MAC address is detected, it records a timestamp against the reading. Then, every 10 seconds it checks the device and timestamp map. If a device hasn’t been detected for the last 30 minutes, it sends an email to IFTTT telling it to turn the WeMO switch off. If a device has been detected, and the script previously recorded an off state, then it sends an email to IFTTT to turn the WeMO on.
Why email? Well although IFTTT allows you to connect all manner of web-sites together, there is no straightforward way of adding your own data in, particularly via some kind of API. To get around this, email seemed to me like the easiest option. So my two IFTTT plans wait for emails, and when an email is received with a #deviceOn/#deviceOff tag, the WeMo will be toggled on and off.
There you have it, the basis for a Fitbit powered home-automation system. It seems to be working relatively well at the moment, and I haven’t seen any noticeable drop in my Fitbit battery. Hopefully there’s a drop in my power bill.