Let there be light! …when there’s motion

Razberry on Raspberry Pi + Milight + Fibaro motion sensor + Domoticz

The usual way of operating the lights in your home today is that when you step into a room you turn the lights on by pressing a switch (usually a wall switch) and you turn them off when you leave the room by pressing the switch again. But wouldn’t it be awesome if all this happened automagically, without the need to go to the switch and press it? Well, it can be done if you have some lights which are capable of being automated. But even if you have such lights, how can you automate them exactly and how can it be decided when to turn them on or off? There are many approaches to this problem. The one that we’ll discuss here is using a motion sensor to detect presence in the room and to switch the lights based on the presence. Detecting presence is a complex topic in its own because even if you’re not moving, you can still be in the room (maybe sleeping or sitting inactive). Also it’s not easy distinguishing between human and animal presence and large moving objects (curtains blown by the wind, moving pendulums, etc.) can also be a problem. But in the first step we’re going to take the easy approach and assume that there are no complications. In this context we only need to worry about two things:

  1. Turning on the lights when movement is detected
  2. Turning off the lights if no movement is sensed for a while

 

Components

Razberry on Raspberry Pi + Domoticz + Fibaro motion sensor + Milight bulb

So let’s see what we need exactly in order to achieve the above goal: turning the lights on or off based on motion (or the lack of it) in the room.

  1. First of all we obviously need some kind of smart lights or smart light bulb sockets, which can be operated remotely by some signal.
  2. The second thing that we need is a motion sensor, which sends a signal when movement is detected and stops the signal when the motion disappears.
  3. Finally we need some kind of home automation server which is running all the time and is processing events, making sure that when the motion appears or disappears, the light is switched accordingly. Note that this component is not absolutely necessary in the case when the motion sensor can communicate with the lights directly. The usual case, however, is that they can’t interact directly and that a home automation server needs to mediate between them.

Let us examine each component in detail. For the sake of easier understanding we’ll start with the home automation server and continue with the smart lights and the motion sensor.

 

The home automation server software

Domoticz logo

The home automation server software that we will be using for this project is the free and absolutely marvelous Domoticz software. To discover how to set it up and configure it on a Raspberry Pi, read this article.

 

The home automation server hardware

Razberry on Raspberry PiThe home automation server that we’re going to discuss here will be a Z-Wave server. To learn about Z-Wave and find out how to put together a nice and cost effective Z-Wave server based on the Raspberry Pi, read this article.

 

The motion sensor

Fibaro motion sensor

The motion sensor used for this project will be the Fibaro motion sensor. One of the most important features that make it a good choice for automating the lights in a room is that it contains a built in light sensor too (along with the motion sensor, a temperature sensor and an acceleration sensor). Since we don’t want to mess with our lights (trying to turn them on or off) during day time, when there’s enough natural light in the target location, it’s important to be able to measure the level of light intensity. It is also convenient because it helps us avoid trying to turn the light on after it has already been turned on or off after it’s already switched off. Obviously, we could use a regular motion sensor and a separate light sensor instead, but filling the room with sensors might look ugly. The Fibaro motion sensor, on the other hand, is very discrete and quite beautiful in its own way. Another important capability of the Fibaro motion sensor which makes it a good choice for this project is being able to change the length of the time period for which it keeps reporting its state as “on” after motion is detected. This is also useful, by the way, if you wish to use it in a home alarm system because this time frame can be used to define the duration of the alarm. Last but not least it is a good fit for our purposes because it can automatically filter out minor movement (like animal movement).

To find out more about this device, read this article.

 

The smart lights

MiLight Bulb E27

We could use any kind of smart light bulbs in order to turn them on/off automatically, or even regular bulbs in remote-controlled sockets, but in this example we will be using the Milight/LimitlessLED/EasyBulb smart LED lights that we have examined in the past in this article. Learn about configuring the Milight LED bulbs in Domoticz in this article.

 

Turning the lights on automatically

To turn the lights on automatically when motion is detected in the room we are going to start using an advanced function of Domoticz: Events. You can access this function from the menu, by going to Setup -> More Options -> Events.

The idea behind this feature is that you can tell Domoticz how to react to certain changes in the system (events). It can intercept the state changes of some sensors and it can change the states of other devices in response. It can also send email, SMS, etc to notify you about the changes. It’s a fairly versatile mechanism for defining what should happen in the system when certain events occur. The funky part of it is that you, as the user, can define the automation rules graphically! Yepp, that’s right. The event editor in Domoticz, called Blockly, is a visual programming interface which basically makes it possible to create simple functions of how devices should interact to each other’s state changes by using graphical blocks. To be more exact, Blockly is an open-source web-based visual programming editor made by Google. It’s amazingness lies in the fact that people who are not well versed in software development can still create simple programming rules. And that is what Domoticz events are all about!

Let’s take an example:

Simple kitchen light automation event

The rule in the image is as simple as it looks. It tells Domoticz that if the motion sensor in the kitchen is on (it detects movement) and the light intensity in the kitchen (measured by the light intensity sensor) is below 10 lux, then it should set the state of the kitchen lights to on. And it was all dragged together in just a few seconds using the Blockly visual programming editor. Note that you see 4 main puzzle-like blocks in the image:

  • Kitchen MS Motion is the name of the motion sensor Domoticz device
  • Kitchen MS Light is the name of the light intensity sensor Domoticz device
  • Kitchen Lights is the name of the kitchen lights device in Domoticz
  • 10 is a user constant which could have any value you like

And of course you could change the names of your Domoticz devices to anything you want, even if they are already participating in event rules. Just go to the devices and rename them in the Switches, Temperature, Weather or Utility main menus.

To create an event rule of your own in Domoticz, open up the visual editor (Setup -> More Options -> Events) and start dragging in the different pieces of the puzzle from the left side menu:

  • Control – conditions
  • Logic – value comparisons, complex conditions, setters, user constants
  • Time – time constants and comparisons
  • Messages – strings, URLs, emails, SMS messages
  • Security – related to the built in home alarm system of Domoticz
  • User variables – Domoticz user variables and constants
  • Debug/log – writing to the log of Domoticz
  • Devices – the list of your Domoticz devices (switches, sensors, lights, meters, etc.)

The pieces of the puzzle can be combined into ever more complex larger pieces and this way some really intricate automation rules can be defined.

When you’re done, give the event a name in the upper right corner of the page, check the “Event active” check box and Save it.

That’s it! If you set up everything right, your lights will now turn on automatically whenever the motion sensor detects movement.

 

Turning the lights off automatically

So now that your lights turn on automatically, it’s time to make them also turn off automatically and forget that you ever had to switch them on/off manually. This, however is more tricky then turning them on, because when motion is detected in the room it’s obvious that there is presence and the lights should be turned on, but the length of period of inactivity after which they can be turned off depends on your preference, on the type of the room, etc. For example you know that you move around a lot in the kitchen and that means that if there was no movement for 2 minutes, it’s safe to assume that the lights can be switched off. But you may be sitting or lying down in the living room frequently and there you may wish to turn them off only after 15 minutes of inactivity. This way if the lights turn off but you did not want that (you’re still in the room and still need the light), you can wave your hand to turn them back on and you only have to take this corrective action every 15 minutes, not every 2 minutes.

If you have a versatile motion sensor like the Fibaro motion sensor, for which you can change the duration of the time frame for which it reports its state as “on” after it senses motion, you’re lucky. In this case you can simply configure the duration in the sensor settings and add one more Domoticz event rule, which does the opposite of the one we have examined earlier: it turns the lights off when the sensor reports an “off” state (regardless of the light intensity levels). For this specific sensor you can configure the motion alarm duration parameter like this:

  1. Go to Setup->Hardware in Domoticz
  2. Select the Razberry Z-Wave controller from the hardware list and click Setup next to it.
  3. Now select the Fibaro motion sensor in the device list, find the parameter named “Motion alarm cancellation delay” and change it to the desired value.
  4. Finally click “Apply configuration for this device” at the bottom of the page.

If you want to set a value which the sensor will not accept or if you have a less configurable sensor, then it’s time to take out the big guns and start using one of the most advanced home automation features of Domoticz: lua scripts.

Writing a script in the lua programming language is considerably harder than creating a graphical event using Blockly, but no reason to start getting scared, it’s not extremely complex either. However you do need some minimum programming skills and Linux command line knowledge, because the first thing that needs to be done is to create a new text file for the script in the correct sub-directory of the Domoticz installation folder. So find the folder where you have installed Domoticz (for example: /home/pi/domoticz) and enter the scripts/lua sub-directory. Here you need to create a new text file with the appropriate name. By appropriate I mean that the file name of the lua scripts executed by Domoticz determines when and how they are executed. In our case the intent is to create a script which is executed once every minute and checks the state of the motion sensor. This is needed because the script will count the minutes elapsed since there was no movement and it will turn off the lights when enough minutes have passed. The file name of such a script must have 3 components separated by underscore:

  1. script (fixed!)
  2. time (fixed!)
  3. any name you like

So the file name must look something like this: script_time_TurnOffKitchenLightsIfNoMotion.lua

Let’s go ahead and create (or open) this script:

nano script_time_TurnOffKitchenLightsIfNoMotion.lua

Now let’s see an example of such a script and try to understand how it works:

-- script_time_TurnOffKitchenLightsIfNoMotion.lua

local deviceName_MotionSensor = 'Kitchen MS Motion'
local deviceName_Lights = 'Kitchen Lights'
local userVariableName_NoMotionCounter = 'KitchenNoMotionCounter'
local userVariableName_NoMotionMaxMinutes = 'KitchenNoMotionMinutesMax'

commandArray = {}

currentMinutesWithoutMotion = tonumber(uservariables[userVariableName_NoMotionCounter])
maxMinutesWithoutMotion = tonumber(uservariables[userVariableName_NoMotionMaxMinutes])

if (otherdevices[deviceName_MotionSensor] == 'Off') then
 currentMinutesWithoutMotion = currentMinutesWithoutMotion + 1
else
 currentMinutesWithoutMotion = 0
end

commandArray['Variable:' .. userVariableName_NoMotionCounter] = tostring(currentMinutesWithoutMotion)

if (currentMinutesWithoutMotion >= maxMinutesWithoutMotion) then
 print('<font color="blue">Turning OFF ..deviceName_Lights.. due to no motion.</font>')
 commandArray[deviceName_Lights]='Off'
end

return commandArray

At the beginning of the script we need to specify the name of two Domoticz devices: the name of the motion sensor device and that of the lights device. There are two additional names that we must customize, two user variable names. These are the names of the two Domoticz user variables that we will set up a bit later (see below). The first one (userVariable_NoMotionCounter) is a temporary variable which is used by the script to count the elapsed minutes since there was no motion sensed and the second one (userVariable_NoMotionMaxMinutes) is a user defined constant which tells the script how many minutes must elapse before the lights are turned off. Basically this second variable is how you define the length of the period after which it turns off the lights.

The rest of the script only needs to be changed if you want to do some very heavy customization to how it works, but if you’re set out to do that, then there’s no need to explain to you how it works, because you already understand 😉

The final step to making the bulbs switch off automatically is to create the two user variables that the lua script needs. Go to Setup->More Options->User Variables in Domoticz and add two variables:

  • name = userVariable_NoMotionCounter, type = Integer, value = 0
  • name = userVariable_NoMotionMaxMinutes, type = Integer, value = 2

Note that for the second variable you should add your own desired value instead of 2. This will control the duration (in minutes) of the time frame after which the lights turn off.

Domoticz - Adding user variables

If everything was set up correctly, your lights should now automatically turn off after the specified amount of minutes of no movement. If it does not work, go to Setup->Log in Domoticz and try to find out what is happening. You may add debug messages to the lua script using the print statement. You can find an example of this in the script itself.

 

Final word

The methods discussed above to turn on and off the lights automatically are likely to be suitable for many needs. However there may be situations where you would not want this kind of automation. For example it would not be a good thing if the lights turned on by themselves in your bedroom whenever you made a small movement in the bed at night. Also, you might not like the lights to turn off too often in a room where you stay a lot but make little movement. Otherwise, it should be fun to play with this. Enjoy!

 

A simple home security system with Domoticz and the Fibaro motion (multi) sensor

Fibaro motion sensor in Domoticz

The Domoticz home automation software contains, among many other nice features, complete support for a home security system. Any security system consists of five main component types:

  • Sensors to detect intrusion
  • Cameras to record the unwanted events
  • Sirens to sound the alarm
  • Arming/disarming devices (such as keypads, RFID tags, etc.)
  • A main unit to coordinate all the other components

Domoticz comes more or less equipped with the latter three. The software itself acts as the main unit, which communicates with the sensors, sirens, etc. It handles all the events and dispatches the necessary messages accordingly.

For arming and disarming the security system, it offers a software keypad, which can be accessed from Setup -> More Options -> Security Panel:

Domoticz - Security panel

In this panel the user can trigger the home arming, away arming and disarming procedure by entering the security code which was previously set in Setup -> Settings -> System (in the Security Panel section). The delay of the arming (the beeping time frame) can also be changed in the same section of the settings.

A shortcut for accessing the security panel is the security device:

Domoticz - Security deviceIt will show up in the Dashboard after the security panel has been used at least once. This is a convenient shortcut and it makes it much more comfortable to arm/disarm the system from a computer or a phone, but let’s admit it, it is still a bit cumbersome to do it without a dedicated arming/disarming device, such as a keypad or an RFID tag. Not to worry though, it is absolutely possible to connect dedicated arming/disarming hardware to Domoticz. A good tutorial detailing how to use a Z-Wave keypad (as well as RFID tags) can be found here. However, if you do not wish to invest into dedicated arming/disarming devices, you can use the built in software keypad for free!

Perhaps the most important component of the security system is the one which notifies the owner (and/or the police, security company) about breaches. In a conventional setup there is usually a siren meant to alert those who are nearby and most systems are also connected to a phone line which is used to call the police, security company and the owner. Wireless sirens can be connected to Domoticz. Getting notified about alarms is also easy. All that needs to be done is to set up an event, which sends an SMS, email or other type of notification when the status of the Security Panel device is armed and when a sensor signals intrusion.

Events can be created in Setup -> More Options -> Events quite easily using the Blockly visual programming component, which makes simple programming accessible to everybody. All you have to do is drag some puzzle-like pieces together to form an “if-this-than-that” type of rule. Here is an example of an event which tells Domoticz to send an email to the owner and to the police if the kitchen motion sensor is triggered while the security status is “Armed Away”:

Domoticz - Kitchen alarm event

It is equally simple to send other types of notifications (like SMS, etc) instead of emails, but for that you will have to set up an appropriate notification service and use it in Domoticz. SMS sending services are usually not free, but cheap enough, so if you’re considering building a security system based on Domoticz, you should probably consider investing into one. The various notifications can be configured in Setup -> Settings -> Notifications.

A nice (but optional) touch to a home security system is adding a camera to see what’s going on in the building and also to record unwanted events. With Domoticz this is as easy as connecting a cheap webcam (or some more expensive Full HD camera) to a USB port of the computer on which Domoticz is installed. Of course, wireless cameras may also be used. Configuring the cameras can be done in Setup -> More options -> Cameras. There you can also view the stream from each camera.

Finally we arrive to the one type of essential component in each security system which Domoticz doesn’t and cannot supply by default: sensors which detect intrusion. These can be many types of devices, such as:

  • motion sensors
  • door/window sensors
  • glass breaking sensors
  • etc

In the simplest of configurations we will check how Domoticz works with a wireless motion sensor.

 

The Fibaro motion (multi) sensor

Fibaro motion sensor

One of the nicest motion sensors that I ever had the pleasure to come across is the Fibaro motion (multi) sensor. It is a Z-Wave device, which works well with Domoticz. To learn how to build a cost effective Z-Wave server based on a Raspberry Pi and Domoticz, read this article.

The Fibaro motion sensor is actually a device which incorporates four different sensors:

  • a motion sensor
  • a light intensity sensor
  • a temperature sensor
  • a tampering sensor (accelerometer)

This combination makes is much more powerful than a regular movement detector. Of course it’s primary role is to work as a motion sensor, but the other three sensors complement this function nicely. For example the tampering sensor can trigger the alarm even if the intruder manages to somehow avoid the motion sensor’s line of sight and attempts to disable it. When the sensor is touched and slightly moved, the tampering sensor is activated and the alarm is triggered. The light intensity sensor can be used to automatically detect day/night and activate the security system as necessary. It also helps to know if there is enough light in the room, making it possible to automate turning the lights on and off based on movement. The temperature sensor is simply a convenient thing because if you install a device in a room anyway (for motion sensing purposes), it’s great that it can report the temperature too and you don’t need to install a separate sensor for that. Because of this the Fibaro motion sensor can also be used in automated home heating systems.

So this sensor is very functional. But it is also extremely nice looking. To be honest, I haven’t found one that is more elegant. It kid of looks like a cat’s eye (nice touch!) which lights up in different colors when motion is sensed. It can be configured to always glow in a given color, but the nicest way to set it up is to change its color based on the measured temperature. That way whenever you move in your room, you can just look at the sensor and know the approximate temperature based on the color it glows in. Very nice!

The sensor is also very discreet, almost completely white and very small. Works with a CR123A battery, which is expected to last for about 2 years under average operating conditions. Comes with two wall mounting options: a screw and a small but very strong transparent double sided sticky dot. Either way, the mounting point is out of sight.

The line of sight and range is pretty good, one sensor can more or less cover an entire large room. The motion detection works well, it is configurable and it can automatically filter out pets. However it can easily be fooled by moving hot air, so it’s not a good idea to install it directly above a heat source.

A detailed manual of the device can be found here.

 

Using the Fibaro motion (multi) sensor with Domoticz

Fibaro motion sensor in Domoticz

Since this motion sensor is a Z-Wave device, before you can use it with Domoticz, you first have to configure Domoticz to interact with a Z-Wave controller. Details about a cost effective and yet very functional option for this can be found here. In the very same article it is explained how to add new Z-Wave devices to the Z-Wave network. Follow those steps to include the Fibaro motion sensor into the Z-Wave network. When the controller is in learning mode, you will have to press the button located inside the sensor (you’ll have to open it by unscrewing the two half spheres) three times quickly. Domoticz should display a notification stating that a new device has been added.

After the sensor has been included into the Z-Wave network, it will show up in the list of unused devices in Domoticz (Setup – > Devices -> Not Used) as several devices. The motion sensor and tampering sensor will appear as switches, the temperature sensor will appear as a thermometer and the light intensity sensor will be a light sensor. To exact types and sub types are as follows:

  • Motion sensor: Lighting 2, ZWave
  • Tampering sensor: Lighting 2, ZWave
  • Temperature sensor: Temp, TFA 30.3133
  • Light sensor: Lux, Lux

Activate the devices in Domoticz by clicking the green arrow icons next to them in their corresponding rows. After that you will be able to find the motion and tampering sensor in the “Switches” section, the temperature sensor in the “Temperature” section and the light senor in the “Utility” group.
Domoticz - Fibaro motion sensor - Motion switch device Domoticz - Fibaro motion sensor - Temperature sensor device

Domoticz - Fibaro motion sensor - Light sensor device

You may add them to your Dashboard by clicking the star icon on each of these devices.

Note that the motion and tampering switches are “read-only” switches, meaning that their state cannot be changed by the user, they simply reflect the physical state of the respective sensors (whether the motion alarm or tampering alarm has been triggered or not). Also note that the Fibaro motion sensor does not seem to be 100% compatible with the Raspberry Pi + Razberry + Domoticz Z-Wave server combination, in the sense that the tampering sensor is shown as always on, making it pretty much useless. But the other three sensors (motion, light and temperature) work just fine.

In case you wish to fine tune the Z-Wave parameters of the Fibaro motion sensor, this can be done in Domoticz by going to Setup -> Hardware, selecting the Razberry Z-Wave controller from the hardware list and clicking the “Setup” button next to it. A list will come up with the associated Z-Wave devices (which are included in the network) and there you may select the desired Fibaro motion sensor. Doing so will display its Z-Wave parameters below it. the values of the parameters can be acquired and saved using the “Request current stored values from device” and “Apply configuration for this device” buttons. Since these are battery operated devices, they are configured to wake up rarely (once in every one or two hours) in order to prolong battery life. The settings will only be acquired and saved during such a wake up, so don’t expect them to show up and take effect immediately.

 

Using the Milight / LimitlessLED / EasyBulb wireless smart LED lights with Domoticz

Milight in Domoticz

In the past we have talked about how you can control the MiLight / LimitlessLED / EasyBulb wireless LED bulbs using a Raspberry Pi and a command line utility. The details can be found in this article. We have also examined the very nice free home automation software named Domoticz. Now it is time to put the pieces together and take a look at how we can configure Domoticz to control the Milight lights directly and making them part of an integrated home automation system.

 

About the Milight / LimitlessLED / EasyBulb lights

MiLight Bulb E27I’ve been using the MiLight / LimitlessLED / EasyBulb wireless LED bulbs for over two years now and they are still my favorite. That’s because even though they are considerably cheaper than more famous brands, like the Philips Hue, LifX or Belkin’s WeMo smart lights, they are reliable (I have installed over 15 RGBW 9W Milight bulbs in my house, most of them have been in use for over two years and all of them are working perfectly) and fit all my regular smart household usage needs. Their luminous flux of over 800-850 lumens gives plenty of light for a smaller room (like a bathroom) and two or three of them together shine plenty of light even in a larger room (like a living room). In manual (non-automated) mode it’s easy and comfortable to control them using either the wall switch or the remote control, which works with radio waves and the signal passes through walls. When it comes to interaction between other devices and the Milight bulbs, the Milight bridge does its job well translating commands sent over Wi-Fi to 2.4 Ghz radio waves that the bulbs understand, making the task of controlling the LED bulbs a very simple one. Same goes for LED strips connected to a Milight LED strip controller. Very easy to handle manually or over Wi-Fi. Switch them on or off, dim them, change the color, it’s all a breeze.

The only weak side of the Milight lights is that they are stateless. And by that I don’t mean that they forget their state when turned off or when power is lost. They do remember their state (on/off, color, brightness, etc.). But you cannot query their state. It is not possible for a controller to ask the lights for information about their on/off state, about their brightness level or about the current color. This makes some more advanced home automation tasks difficult (if not impossible) and it is the only thing that I can bring up as a negative about the Milight bulbs and LED strip controllers.

 

Configuring Milight / LimitlessLED / EasyBulb in Domoticz

Let’s see how we can extend the capabilities of Domoticz to make it able to control Milight devices. Luckily Domoticz supports the Milight hardware out of the box, so we can simply open up the web interface of Domoticz, go to Setup -> Hardware and add a new hardware controller of type “Limitless/AppLamp/Mi Light with LAN/WiFi interface“:

Domoticz - Add Milight hardware

The Remote Address field should contain the IP address (or domain name) which can be used to access your network from the outside. This is needed if you wish to be able to control your lights within Domoticz from outside networks. The Port field should contain the port number used to access the Milight wireless bridge (8899 by default). No need to set a Data Timeout.

The next step is to configure the newly added Milight interface by setting the type of lights that you wish to use. Click on the “Set Mode” button next to the Milight hardware (in the list of hardware added to Domoticz (Setup -> Hardware)) and choose the type of your bulbs or LED strips: RGBW, RGB or White.

Now that the hardware interface is set up, it’s time to activate the Milight switches. Go to Settings -> Devices and hit the “Unused” button. There you should see 5 new inactive devices corresponding to the master switch (which controls all 4 Milight zones) and to the 4 individual Milights zones:

Domoticz - Activate Milight devices

Activate each of these 5 new devices by hitting the green arrow icon at the right side of their row. You can give them descriptive names like “All lights”, “Living Room Lights”, “Kitchen Lights”, etc.

If everything went well, you should be able to see your light switches in the Switches menu:

Milight switch devices

You may set a light bulb icon for them (if they show up with a different icon) by hitting the “Edit” button for each of these switches. You can also add them to your Dashboard by clicking the star icon on each switch device.

You should now be able to control your MiLight / LimitlessLED / EasyBulb lights from within Domoticz. Enjoy!

 

Home Automation with Raspberry Pi, Z-Wave devices and Domoticz

Raspberry Pi + Z-Wave + Domoticz

Home automation is something that has only recently become widely available and, as all new things, it is trying to develop in many different directions. As it does, manufacturers of home automation devices are trying to create standards to help ensure that all home automation devices conforming to those standards will behave in a known way and will be compatible with each other. For now there are many home automation standards and protocols out there and Z-Wave is one of the most widely adopted ones.

 

About Z-Wave

Z-Wave

Z-wave is a standard for wireless communication between home automation devices. Some of its main characteristics are:

  • low power requirement (so that battery operated devices can adopt this standard)
  • low communication latency (to encourage system responsiveness)
  • reliability (for obvious reasons)

The devices communicate through radio waves  with a frequency around 900 Mhz. Depending on the region of the world the frequency is slightly different:

  • 868.42 MHz (Europe)
  • 908.42 MHz (United States)
  • 916 MHz (Israel)
  • 919.82 MHz (Hong Kong)
  • 921.42 MHz (Australia/New Zealand)
  • 865.2 MHz (India).

Z-Wave networks limit the amount of emitted radio waves (devices can only emit radio waves in 0.1% of the time) to reduce the irradiation levels and interference with other devices to a minimum.

The Z-Wave communication specification is supported by hundreds of manufacturers and there is even a Z-Wave Alliance that consists of several major manufacturers, which certifies Z-Wave devices for correct interoperability. The devices that are found to conform to the requirements receive the Z-Wave Plus certification. The fact that the standard is clear, the support by a huge number of manufacturers, the guarantee of conformity by certification of devices and the security imposed by the standard makes Z-Wave an attractive choice for home automation enthusiasts. On the other hand it also sets the prices of devices quite high. Quality has its price.

The Z-Wave home automation networks consist of at least one main controller node (you could call it the Z-Wave server) and several slave devices (home automation components like sensors, switches, lights, dimmers, etc.). The main node manages the Z-Wave network of devices, but the slave devices can also interact with each other directly. Slave devices can be included in and excluded from the network at any time. Each node also acts as a re-transmitter to ensure that the signals get from the sender device to the receiver device. So if a network contains two Z-Wave devices which are not close enough to communicate with each other reliably, a third one can be included in the middle to pass along the messages.

 

Raspberry Pi + Razberry = Z-Wave Server

The Z-Wave communication protocol has a complex hardware and software implementation. It’s is not easy to build a device that speaks Z-Wave. It’s far easier to just buy one. But Z-Wave main nodes (Z-Wave network controllers) are far from being cheap. The most well known ones, like Fibaro Home Center, the Vera family, the Zipa family, etc. cost hundreds of dollars. But… there is a cost-effective alternative: building a Z-Wave server from a Raspberry Pi and a Razberry daughter card.

Razberry

The different versions of the Raspberry Pi are cheap and yet effective ARM computers that usually run different versions of Linux. An adequately equipped Raspberry Pi, with power supply, SD card and USB Wi-Fi dongle cost as little as 70-80$ in total. Raspberry Pis are used as many kinds of servers. To turn one into a Z-Wave server, all you need is a Razberry daughter card!

The Razberry is a small add-on for the Raspberry Pi (compatible with both Raspberry Pi version 1 model B+ and with version 2) that plugs directly into the GPIO pins of the Raspberry Pi and sits on the top of it, much like an Arduino shield sits on the top of an Arduino. The Razberry daughter card only uses one 3.3V, one GND and the RX and TX pins of the Raspberry Pi, but for the sake of stability it plugs into 10 GPIO pins and further restricts access to an additional 4 pins, making a total of 14 GPIO pins inaccessible, which can be a bit annoying because access to 10 GPIO pins is lost for apparently no reason. This is because the Razberry daughter card does not have pins on top of it to break out the unused pins. On the other hand this allows it to fit nicely into a conventional Raspberry Pi case.

Razberry on Raspberry Pi

In general the Razberry is a great add-on for the Raspberry Pi. Unlike the other Z-Wave controllers, it is quite cheap (cost around 70$). It handles all the Z-Wave communication and acts as a Z-Wave controller (gateway) in a Z-Wave network. In short, it transforms a Raspberry Pi into a Z-Wave server.

The Z-Wave communication on the Razberry is handled by a Sigma Designs ZM5202 Z-Wave transceiver module (5th generation) and by a small PCBA antenna which has a surprisingly good range. As an example, it seems to be able to communicate with Z-Wave devices that are 10 meters away, behind 3 concrete walls (as a reference: 2.4 GHz Wi-Fi signals barely get through the same 3 walls).

The software that comes with the Razberry is called Z-Way. It consists of several levels of software built on top of each other and has an API that can be used to interact with the card in multiple ways (from web, from mobile apps). It encourages developers to create wrappers around the basic API in order to provide elegant access interfaces. By default it comes with a free web interface which contains all the necessary functionality and does it’s job, but I’ve personally found it a bit cumbersome to use and not very elegant. So, unless you are inclined to develop your own elegant interface for it, you are likely to soon look for alternatives. That is why we’re going to examine how Razberry can be integrated with Domoticz, which is a very nice and free home automation software, as discussed in a previous article.

 

Configuring Domoticz to work with Razberry

RaspberryPi + Razberry + Domoticz

If you already have a Razberry daughter card plugged onto a Raspberry Pi, it is time to install Domoticz on your Pi and configure it to work with Razberry.

  1. The guide about the installation of Domoticz on the Raspberry Pi can be found at the end of this article.
  2. There is an excellent guide provided by Vesternet which explains in great detail how to configure Domoticz to work with the Razberry Z-Wave controller.

I’m going to take a quick detour here to tell you about Vesternet. It is a UK-based home automation website and online store that I personally like them very much for several reasons. The most important reason is that they offer a very large amount of free technical guides, free technical advice, compatibility charts, etc. The impression they give off is that they really want to help people with their home automation projects, they are not just trying to convince you to buy items from them. Their products have really detailed and clear technical descriptions, so you exactly know what you are buying if you take the time to read the descriptions. Also, they have a very wide range of Z-Wave products, so if you’re looking to build a network of Z-Wave devices, I strongly recommend to visit Vesternet.com. Note that I do not have any personal interest in recommending Vesternet, I was simply impressed by their attitude and by their variety of items, that is the only reason why I’m recommending them.

 

Configuration details

  1. Along the lines of the Vesternet guide for configuring Domoticz to work with Razberry, the first thing to do is to trick Domoticz into thinking that it’s accessing Razberry via the USB interface. Razberry actually communicates through the serial interface (RX, TX pins) of the Raspberry Pi, but Domoticz can only handle Z-Wave devices via its OpenZWave USB interface. That’s why a symbolic link needs to be created to redirect the USB interface used by Domoticz to the serial interface. To do this, open the file /etc/udev/rules.d/09-tty.rules in a command line window and add the translation rule from USB to serial:
sudo nano /etc/udev/rules.d/09-tty.rules
add line: KERNEL=="ttyAMA0", symlink+="ttyUSB20"
sudo reboot

2. The next step is to add Razberry to the list of hardware managed by Domoticz. To do this, open the user interface of Domoticz, go to Setup -> Hardware and add the Razberry as a new piece of hardware:

Domoticz - Add Razberry Hardware

Make sure to select the USB interface that we redirected earlier to the serial interface.

Congratulations! At this point you should have a cheap but effective Z-Wave Server that you can control using Domoticz.

 

Adding devices to the Z-Wave network

Having a Z-Wave controller is great but you can’t do much with it unless there are some Z-Wave slave devices for it to communicate with. So the next step is to include your devices into the Z-Wave network.

  1. In Domoticz go to Setup->Hardware and select the Razberry Z-Wave controller (that we have just added). Click the Setup button next to it.
  2. A list of your Z-Wave devices comes up (in a newly created network the list should be empty) and at the top of the list you can find a “Node management” combo box. Click it and select “Include node”.

Domoticz - Razberry - Include node3. When you click “Include node”, the controller goes into learning mode for a few seconds (usually 20 seconds), which means that it’s listening for a special signal from new slave devices that are to be included into the network. You should now press the include button on your Z-Wave slave device that you are trying to include. Each device has its own different way to be included. Some require a single push of a button, others may need a double or even triple push to send the magic signal to the controller which will discover them and include them into the network. To find out how to include your device, consult its instruction manual. If everything goes well, Domoticz should display a message for a few seconds which states that a new device was included and some of the slave devices have their own way to signal that they have been included into a Z-Wave network. Finally, you should see the included device appear in the list of devices that appears when you go to the configuration page of your Razberry controller in Domoticz.

 

Using Z-Wave devices with Domoticz

The final step before you can use your newly included device is to activate it in Domoticz.

  1. Go to Setup->Devices and hit the “Not Used” button.
  2. In the list of not used devices you should see the newly included slave device. Click the little green arrow icon next to the device.

Domoticz - Activate device

3. A window opens where you can give the new device a name.

Domoticz - Name newly activated device4. Hit “Add device”.

5. Depending on the type of the device that you have just added, you can now find it in Domoticz under one of the following categories:

  • Switches
  • Temperature
  • Weather
  • Utility

Domoticz - Device headers

6. If you wish your new device to appear on your Domoticz dashboard, click the little start icon next to it. Turn the star’s color from grey to yellow and it will always be present on the dashboard.

Domoticz - Add device to dashboard

 

Final word

Home automation in general is a great but rather expensive activity (or hobby, if you will), partly because it’s a new trend and the devices are not yet widely spread (not sold in huge quantities), but also because they contain advanced technology. Z-Wave is one of the leading home automation standards, with a great variety of available devices that conform to it (sensors, switches, locks, etc.). Unfortunately Z-Wave controllers, which are the most essential components in a Z-Wave network, have very steep prices (in the range of hundreds of dollars), which for many people is probably the first obstacle in the way of building a Z-Wave home automation network. However, building a Z-Wave server out of a Raspberry Pi and a Razberry daughter card, plus using free Domoticz home automation software on top of them results in an affordable, yet very functional, configurable, good looking and enjoyable Z-Wave home automation system.

 

Domoticz on Raspberry Pi

Domoticz on Raspberry Pi

Introduction to Domoticz

Domoticz is a very nice free home automation software. It is not only very functional, but it also has a good looking user interface. What I found really great about it is that Domoticz offers useful functionality and a fun experience for every user, regardless of their level of knowledge about the software and experience with it. Right out of the box it comes packed with many features for the beginner to enjoy, and later, as the user becomes more skilled, automation can be taken to the next level.

As every home automation software, Domoticz takes input data from several sources and sends output data to all kinds of devices. Automatic actions can be added that respond to the input and trigger some kind of output.

Some of the most important inputs (sensors) that are available in Domoticz out of the box are:

  • Temperature and humidity sensors
  • Light sensors
  • Electric meters (voltage, current, power, energy)
  • Gas sensors
  • Weather sensors (temperature, humidity, pressure, wind, rain, UV, irradiation, air quality, etc.)
  • User variables
  • Etc.

The first very handy thing that can be done with the data taken from these sensors is to visualize them on some extremely good looking graphs:

Temperature (click on the image to enlarge):

Domoticz - Bedroom temperature graphs

 

Wind (click on the image to enlarge):

Domoticz - Wind graphs

Power usage (click on the image to enlarge):

Domoticz - House power usage graphs

Total energy usage (click on the image to enlarge):

Domoticz - House total energy usage graphs

Based on the values shown on these graphs the user can decide to manually trigger some outputs, for example to turn on/off various devices:

Domoticz Switches

Moreover, the values coming from the sensors can not only be seen on graphs. Widgets that show sensor values and that command devices can be organized into a cool dashboard (for instant access when you access Domoticz)(click on the image to enlarge):

Domoticz dashboard view

You can even add a floor plan image of your house and see the sensors and devices in their real physical locations (click on the image to enlarge):

Domoticz floorplan view

 

As users become accustomed with the software, they can add so called scenes which define automatic actions (for example the boiler can be turned on automatically when the temperature in the house drops below a certain value or the alarm can be triggered when a motion sensor detects the presence of somebody in the house). For those who even this is not enough, there’s a possibility to add automation scripts. These scripts are able to accomplish automation tasks beyond the wildest imagination but require a bit of technical knowledge.

 

Supported devices

Domoticz supports a lot of devices (hardware and virtual) today, but it is constantly being developed, so the list of supported devices is very likely to grow. Some of the most important devices it can use today:

  • All kinds of physical temperature, humidity, pressure and light sensors
  • Many types of electric meters
  • Solar (photovoltaic) monitors
  • Smart lights
  • Several weather APIs
  • Generic hardware interfaces (including the great Razberry daughter card for Raspberry Pi through OpenZWave)), which can gather data from virtually any sensor.
  • USB sticks
  • Devices through LAN.
  • Motherboard sensors (to collect data from the computer on which it runs).
  • Virtual devices
  • Etc.

 

How it works

So Domoticz looks good, works great and supports a lot of devices. But how does it work? Well, the working principle is quite straightforward actually: it runs as a server application which communicates with the hardware through several interfaces and with the user through a web-based interface, which can be accessed through any browser. You just type the address of the computer on which Domoticz is installed and the port number that it listens on and you immediately enjoy the full-featured user interface, which, by the way is nicely optimized both for desktop computers and for mobile devices (phones, tablets). For example from home it can be accessed (depends on the configuration) like this:

192.168.1.21:8080

There are some smart phone applications too that can display a different user interface for it, but the default web-based interface is so nice, that it’s not really tempting to install an extra app.

The only thing that you really need for Domoticz to run is a computer which is up and running 24/7. This would have been a major problem for most folks a few years ago, because a conventional PC is noisy and it also uses a lot of electricity, so you would not want it running all the time. Luckily for us, we are now in the booming age of single-board micro computers, which use very little electricity and are completely noiseless. Installing Domoticz on one of these boards is an ideal solution. And which better single-board micro computer to use then the famous, well supported, easy to use and ultra-cheap Raspberry Pi?

 

Installing Domoticz on Raspberry Pi

1. Log in as pi (or your preferred user) onto your Raspberry Pi.

2. Create a directory for Domoticz and enter that directory:

mkdir domoticz

cd domoticz

3. Download the binaries into the newly created directory and extract them from the archive:

wget http://domoticz.sourceforge.net/domoticz_linux_armv6l.tgz

tar xvfz domoticz_linux_armv6l.tgz

4. Optionally delete the downloaded archive (you don’t need it anymore):

rm domoticz_linux_armv6l.tgz

5. Configure domoticz to start at boot:

sudo cp domoticz.sh /etc/init.d

sudo chmod +x /etc/init.d/domoticz.sh

sudo update-rc.d domoticz.sh defaults

6. Configure Domoticz to run with your preferred user name, form you installation directory and listen on a specific port:

Open the Domoticz configuration file: nano /etc/init.d/domoticz.sh

Change the user name as necessary in the following line:

USERNAME=pi (change to your preferred user name)

Change the installation directory if you installed it in a place different from your preferred user’s home directory:

DAEMON=/home/$USERNAME/domoticz/$NAME

Change the default port 8080 to something else if you wish (this is the port that will be used to access the Domoticz UI from a web browser)

7. Start the Domoticz service:

sudo service domoticz.sh start

You should see a message confirming that Domoticz is running.

You may stop it or restart it at any time with the commands:

sudo service domoticz.sh stop

sudo service domoticz.sh restart

8. At this point you should be able to access and use Domoticz from a web browser by typing into the web browser’s address bar the address of your Raspberry Pi and the Domoticz port number configured above:

RaspberryPi_IP:Domoticz_Port_Number

For example:

192.168.1.101:8080