A while ago I set my first steps to home automation, but never blogged it because it didn’t really belong on a blog about virtualization and cloud. Whoever, now that I wanted to expand my domotica solution, I thought it would be wise to make a documentation for the digital archive.
Domotica is another name for home automation, and nowadays you can do about everything when it comes to house automation, from graphing your energy consumption to remotely control your garden, TV, lights, curtains. So the first thing I did when starting with domotica, was making clear what I wanted to do with it. Eventually I had the following list:
- Control the lights
- Control the curtains
- Control the TV
- Show and answer the doorbell
- View the surveillance cams/webcams
- Do this all by phone, tablet, wall mount and speech.
As you can see, I didn’t want a domotica system for monitoring and controlling gas, water, electricity and temperature, I wanted something more like a Jarvis (Iron Man).
Which Hardware?
Now, when you search for a domotica system on the internet, there are a lot of “out-of-the-box” solutions that you can use, like: Vera, Homeseer, HomeWizard, KlikAanKlikUit, Zipato, etc. But as always I wanted a system that is fully customizable and has the freedom of developing and extending the system, so it will become my system. Long story short, I ended up with a Raspberry Pi 🙂
The first thing you have to do when choosing a domotica system, is decide which protocol you want to use. There are many protocols you can use for your domotica system. The most commonly used are: X10, Z-Wave, Zigbee and KNX. Most big companies like Somfy use Z-Wave as protocol and when browsing the internet forums, it looks like Z-Wave will become the big standard for home automation. Luckily the Raspberry Pi can be equipped with different modules so it can do all of the protocols you want. I chose to use the X10 protocol, because of the low cost and the fact that I already had some KlikAanKlikUit and Action switches.
So this is what I bought:
– A Raspberry Pi Model B set (Link)
– A 433Mhz Transmitter (Link)
What Software?
Now that I knew which hardware I was going to use, I had to make a decision for a software product. There are a lot of software products to choose from when it comes to home automation. A small selection is: Agocontrol, Domoticz, OSA, OpenHAB, Domotiga and Pluto.
I chose Domoticz, because of its maturity and support for many hardware and protocols.
Putting it all together
Let’s put everything together. First stop; install an Operating System on your Raspberry. I Chose Raspbian. You can find the installation instructions here (Raspberry Images). After that, you have to connect and configure the 433Mhz transmitter. You can use this instructions to get that all setup. And finally you have to install Domoticz, to make everything fancy and working (Tutorial).
Part 1: Controlling the lights
The first thing on the list was controlling the lights, so let’s start with that.
Because this contains many steps, I will summarize the actions you have to take in to steps.
- Create a virtual hardware component
- Create a virtual sensor on the virtual hardware component. (I added two because I have two lamps that I want to control.)
- Configure the virtual sensors (This is where you going to use the scripts created in the previous chapter.)
- Add the virtual sensors to your dashboard.
Now that the sensors are in place, we want to add some automation to them, because controlling your lights from your phone or tablet is nice, but automatic lights are much nicer 🙂
I decided that I wanted one light to switch on on a timed schedule, and one light must be switched on only if I am at home and between specific times, because the lights don’t have to be on when I’m in bed.
The first option is simple, because this is a standard feature of Domoticz. Select the sensor you want to be automatically switched on and off and click “timers”. Here you can set when the light has to go on and off. I chose for a dynamic on time and static off time. So now the light goes on when it’s 30 minutes before sunset and goes off at 23:00.
The second option is more complicated, but still not very hard to accomplish. The one thing I have always with me and can communicate with my home infrastructure, is my phone. So I searched for a solution that included my phone and came up with many ideas. I thought about the connection type, should it be Bluetooth, Wi-Fi, NFC or something else. Also, who has to be the initiator? Must it be the phone with an app or background program, or should it be initiated from the Raspberry Pi?
Because I want to have everything in one box and everything centrally managed, I wanted this to be initiated by the Raspberry Pi. I chose a network connection as connection type, because this wouldn’t require extra hardware and was easier to accomplish.
The steps to get this working are:
- Give my phone and my wife’s phone a static IP address (reservation) on the home network
- Create a LUA script that will poll both phones (Documentation)(My script is at the bottom of this post.)
- Create a virtual hardware component
- Create a virtual sensor on the virtual hardware component. (This generic switch will be empty, because it will be triggert by the lua script.)
- Create and configure a blockly event. (This will switch the light on or off depending on the status of the generic switch created above.)
- Set an off timer on the light virtual sensor.
This concludes part 1 of DIY Domotica: Controlling the lights.
Appendix: Lua Script
(Lua scripts are run every 10 seconds when named: script_time_*.lua)
commandArray = {} ping_phone_daniel=os.execute('ping -c1 10.10.100.210') ping_phone_abigail=os.execute('ping -c1 10.10.100.211') if (ping_phone_daniel) or (ping_phone_abigail) then -- Success, Switch ON if otherdevices['GSM Aanwezig'] == 'Off' then commandArray['GSM Aanwezig']='On' end else -- Fail, Switch Off if otherdevices['GSM Aanwezig'] == 'On' then commandArray['GSM Aanwezig']='Off' end end return commandArray
4 Comments