This first post is going to be a long one, describing the basics of how my system is set up – I apologize but without this information, anything further I post will not make any sense.
For about the last 9 months I have been tinkering away in the background designing some home automation devices. There are various reasons for wanting to do this but in short – because I can.
Ethernet enabled arduinos are very easy to use, versatile, keep things simple and are relatively cheap – The perfect solution for DIY home automation. Sure, there are things like X10, Clipsal cBus etc but these are generally expensive and/or not very universal.
The main important difference between my intended setup and Jon’s was that I have an existing house that I am not doing a major remodel on so re-cabling my whole house was not going to be an option. This meant all the mains switching would be done locally at the switch point and not back at a central point. There are a couple of advantages of this but the main one is that I don’t have to rely solely on the automation system and components used to build the it just to turn on a light.
The arduinos send and receive messages to/from a server so that (for example) when a button was pressed at a module, it would send a signal back to the server (to update a web page for example) or I could use the server to send a ‘button push’ command enabling the actual automation side of things. However, if the automation systems fail such as the server being offline or a network switch dies – How can we ensure we still have some (perhaps somewhat reduced) functionality? I still need to be able to turn lights on and off but I’m ok with it if they don’t turn themselves off while the system is offline.
With this in mind, the outputs of each Arduino, directly control the outputs of the system. For example, if a button for a light is pushed, it turns on/off a directly connected relay and added to that, if it can, it reports to the server it’s status.
My house is wired with cat5e to every place I intend to utilize the ability to automate a process such as light switches, doors, sensors etc back to a communications rack. The arduinos will be placed in these locations and powered with ‘poor mans’ PoE.
The communications rack houses a special low power PC that only consumes about 30W of power – This box is my Internet router, VoIP phone system, web server (not this one) and MQTT server.
MQTT?? What’s that? I hear you say – Well, really that is the heart of what makes all this possible. MQTT stands for Message Queue Telemetry Transport and is a special message protocol that was intended to be used on slow or intermittant TCP based networks for sending information such as sensor data over the internet.
While it was possible to develop some PHP pages on apache and have the arduino’s generate ‘GET’ requests to make things happen or some other sort of TCP socket connection, it’s really like using a car to squash a pea. Sure, it can do it but why go to all the effort when all you want to do is send a few bytes of data. MQTT works based on a Publisher and subscriber type system. Think of internet newsgroups – You have a server, with a heap of topics you can subscribe to, or publish to. MQTT is similar but much simpler.
There are a few MQTT servers (called ‘Brokers’) available, the one I use is Mosquitto. Not for any specific reason other than it was simple to install on my CentOS box but it’s also available for windows for those not so linux minded.
The system is very simple. A device or computer can publish information to a ‘Topic’ and anyone who is subscribed to that topic will receive that data. A device or computer can simultaneously be subscribed to a topic and publish to it. Topics sort of look like a folder structure such as ‘home/kitchen/lights’
Lets take a practical example:
If i have an arduino that is subscribed to ‘home/kitchen/lights’ and it waits for a simple ‘0’ or ‘1’ to turn the lights on or off, then any other device on the network can publish a value of ‘1’ to ‘home/kitchen/lights’ to turn the lights on. Fortunately there are many MQTT compatible clients out there for use in java, php and just plain binary programs to do this. So, you can have a PHP based web page that is able to publish this data – You now have the ability to control your kitchen lights at the click of a button on a web page. Not only that, the web page can reflect the status of lights in real time with the assistance of Ajax or similar technology.
Generally speaking, each module will have the ability to:
Control up to 4 relays via tactile switches with LED status indicators
Have controllable back lighting for the switches (for night time)
Have up to 4 inputs for movement sensors
Be equipped with a temperature sensor
However, there will be some custom modules for the likes of RFID readers (door access control) and a special one to do some switches and monitor household electricity use (read my electricity meter) and another one will have an RF transmitter for controling some RF enable power point devices. All of these are already developed, just not implemented yet with the exception of the electricity meter reader which I will go in to more detail on soon.