Connective tissue and spitballing

Connective tissue and spitballing

I’ve got a “working” (albeit rickety) Arduino + PIR Motion sensor thing going on. Aw yeah! It’s an Arduino Uno, so no wifi yet, but I might cheat and use an Arduino 101 to do the next step, that is having it communicate to a RESTful web service that will do stuff based on what the sensor picks up. Eventually I’ll dump all this onto an Arduino Pro Mini with an esp8266 so there’s not a ton unnecessary hardware. Also still need to reliably detect ambient light levels with a photoresistor or something but that shouldn’t be too hard.

I’ve been monkeying around with the Phillip’s Hue API and it’s been pretty straight forward. Really there isn’t a lot to it – get a user token, get the list of lights and groups, and then send the appropriate PUTs and POSTS to change them. So my plan here would be to make a simple Python library to simplify using the Hue API – I know there exist a couple of them, but I’d like to play a bit more with this and use it as an opportunity to improve my idiomatic Python.

There’s also the RESTful API I’ve been making to run on my Pi that would be called by the sensor. In this case I’ll have the sensor pack POST something to my Pi’s service that would likely be the UUID,  a boolean for “motion detected?” vs. “no motion detected for a given length of time,” and then a value for how bright the room already is. Any other sensors I add later could also be added to the post.

The Pi service would then figure out what to do. If sensor BATHROOM sends that motion was detected and light level is low, the service would take that and then look at the rules for BATHROOM and determine what to do. All the thinking is on the Pi. The only “thinking” the sensor’s microcontroller would do is keep track of how long it’s been since it picked up any movement.

Maybe when the sensor comes online it can ping the Pi with its UUID, the Pi will respond with any config info the sensor needs – “Hey, the timeout is 3 minutes” just in case the user updates the Pi rules with changes or whatever.

On the Pi, I’ll have the service, but also a simple admin/configuration site running that will allow me to configure rules for all my sensors. Probably will use Angular.js for that since I’ve been wanting to get more skill with it. That thing would have a few things it’d do when a user logs in. Polls various “smart hubs” to get a list of devices on them. Poll the various devices I’ve made and registered previously to ascertain their status. Show the user the sensors that are online. User clicks a sensor, opens up and shows them what the rules are and what lights or other devices and behaviors are set up for that sensor.

Leave a Reply

Your email address will not be published. Required fields are marked *