Home monitoring and (fledgling) automation framework built on the RabbitMQ message broker.
I'm slowly making my house "smart". Currently active are:
- temperature and humidity sensors throughout the house
- a power monitor attached to the electric meter • an antique voltmeter reflecting real-time power consumption
- a remotely-operated sprinkler controller for my lawn
- an occasionally-working device in my fuel oil tank to measure volume
- a furnace activity monitor and timer-based override
All of this data needs to go somewhere, and often several somewheres. Long-term data collection, event response, real-time analysis and graphing, and behavior modification (both for me and the house) are some of the goals I have for this system. It's been a work in progress over several years, frequently interrupted as I context-switch between this and other electronics, car, home, work and personal projects.
A few months ago I heard about RabbitMQ, started learning a bit more about message brokers, and realized that pub/sub was the ideal model for this system: multiple sources of information being presented to multiple consumers at once. I'd known for a while that I was reinventing the wheel by implementing my own — not terribly efficient — hub-and-spoke system for getting information from a sensor to a consumer, but it finally dawned on me that if I wanted to grow the system I needed a better backbone.
Receives XBee frames and publishes them to the
raw_xbee_frames exchange. Also consumes messages from the
xbee_tx queue to be transmitted as frames to remote XBee devices.
Sensor data handlers
The following scripts consume device-specific frames from the
raw_xbee_frames exchange and publish usable to the
sensor_data exchange. They are essentially device drivers.
furnace_consumer.py script also exposes some methods via RPC to control an override timer so that we can get enough hot water for a shower. It's a long story…
Consumes power monitor data published by
power_consumer.py on the
sensor_data exchange and transmits frames (via the
xbee_tx queue) to an XBee/microcontroller device housed in an antique voltmeter (aka the "volt-o-meter") in the living room that reflects real-time power consumption.
Invoked hourly to retrieve weather forecasts and current conditions, published to the
weather exchange. Not really used at this time, but I'm hoping to be able stay ahead of the heating and cooling needs of the house by reacting to the weather.
Sensor data logger
db_logging_receiver.pystores data published on the
sensor_dataexhange to an sqlite3 database
upload_data.pyperiodically uploads the data to a more powerful server for graphing and longer-term trend analysis
XML-RPC bridge to the messaging-based RPC mechanism used by
sprinkler_driver.py. Python's XML-RPC library is so very handy, but I didn't like keeping track of multiple XML-RPC servers (one for each endpoint).
Interfaces with the remotely-operated sprinkler controller I built. Sprinkler is (de-)activated via cron.
This is an AMQP-to-WebSocket gateway written in Node.js. The WebSocket part is actually an implementation detail under the covers of the very cool (and poorly documented) Socket.IO. There's some boilerplate code at the top of the file that shows how to hook the browser up so that you can subscribe to topics on an exchange and invoke RPC methods.
Several libraries are required:
- socket.io version 0.8.7
- amqp version 0.1.1
- node-uuid version 1.2.0
- node-static version 0.5.9
- log4js version 0.4.0
Just install these in the current directory with npm
$ npm install firstname.lastname@example.org $ npm install email@example.com $ npm install firstname.lastname@example.org $ npm install email@example.com $ npm install firstname.lastname@example.org
$ node amqp_socketio_bridge.js
Furnace Timer UI
Simple HTML and jQuery iPhone web app. Start the
amqp_socketio_bridge.js and point your browser to http://localhost:8000/furnace_timer/.