Freitag, 26. Dezember 2014

Home automation done in one afternoon

So there they are. The winter holidays. And you finally I have all the time to make that stuff I wanted to do. But what to do first.
The challenge is to build the things as fast as possible. So we start with the home automation thing I had in my mind for a few month now. First up we need a cool name so it does stick out of the masses. Well it's name is going to be Herbert.
Next up we need a processing base station for WiFi integration.

Remote-controlled Socket
This nice Raspberry Pi will do the job pretty well I guess. I have a collection of 6 remote controlled wall-adapters for the power sockets and a remote-control to toggle 3 of them individually on and off. the all-off button also exists. Dismantling the remote I found a circuit-board with an ASIC, 12V battery, four tactile switches, 434MHz crystal, one LED and a 8bit-dip switch bank.
Basically just an ASIC
 A quick glance at the backside of the PCB shows that 7 of the 8 switches are connected to the ASIC. Looks like some sort of channel selection. Nice. The operation voltage for the remote is 12V so we can not directly hook the Pi up.
I need some sort of isolation between the two circuits. Something like a optocoupler or a relay. I just happen to have two dual-relay-modules laying around so why not use them. A really quick solder-job later the tactile switches had a wire attached as well a a wire to short one of the channel-selectors. Now all six sockets can be operated with one remote module. the all-off switch is not connected. So I can not switch them all off at once. For now. A look inside the socket adapters show that they also consist of an ASIC. This one isn't even labeled! A switch mode power-supply and an antenna.

The socket-module seems not to answer the command in a way to determine of the signal was received. I will have a look into this later. For now one-way communication will have to be sufficient.

Everything hooked together like this:
5V -> Relay supply
3.3V -> Relay driver
GPIO -> Relay switch signal
The relays short the tactile switches ans one of the channel-selectors. 

The next step is software. The Pi I use has Raspbian installed. This is a Linux based on the Debian distribution and comes with python and bindings to access the GPIO directly from the script. With Python you get a HTTP-server up and running in no time.

from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
import RPi.GPIO as GPIO
class myHandler(BaseHTTPRequestHandler):
    #Handler for the GET requests
    def do_GET(self):

        # Send the html message
        self.wfile.write("Hello World")
        GPIO.setup(4, GPIO.OUT, initial=1)
        GPIO.output(4, 1)

    #Create a web server and define the handler to manage the
    #incoming request
    server = HTTPServer('', 8000), myHandler)
    print 'Started httpserver on ', server.server_address
    #Wait forever for incoming http requests

except KeyboardInterrupt:
    print '^C received, shutting down the web server'

With little additions the first version of Herbert was built. Have look at the git if you want.