Home Automation With Domoticz

May 2017

Let it be said right away: This is a sidetrack. It has nothing to do with neither train nor model building. NOTHING!

We had a go-home meeting at work on home automation.

One of my colleagues had found domoticz.com, which is a program that can be installed on virtually anything – including: Raspberry Pi and NASs from Synology and other manufacturers.

And the meaning? Alright – it may be just for fun. But so is model railroading.

This is about collecting input from everything in your home and making sure that most of those things and other things you have in the same home can be controlled from a computer of some sort. Events can be logged. And they can be used to trigger the things that can be controlled.

For example, I intend to monitor water consumption. And if too much water is used for too long (“one” is watering the garden, it’s getting late and “one” goes to sleep), the Internet radio turns into the living room with “Raindrops are dripping in my hair” on a volume to wake “one” up from “one’s” slumber and turn off the sound and close the water.

Another detail is that Domoticz always knows when the sun rises and sets. This means that instead of using a normal timer to control the Christmas lights (which may be referred to as winterlight in January, February and March), it is quite smart to use Domoticz so you can set the timer to follow the sun instead of using fixed time.

Others use it to see if too much heat is used or too much power is being used on TV sets and the like.

Hardware-wise a mix of Raspberry Pi, Arduino, ESP8266, various sensors, etc. etc. is needed. My colleague buys most of it from China (dx.com). And I’m going to do likewise. You just have to remember to order for less than 80 kroner at a time. Then you stay under Skat’s limit. And the items do not cost more than 15-45 kroner – except the Raspberry Pi and various gateway things. But they can be ordered from Europe – e.g. Reichelt.de.

Software-wise, the primary need is Domoticz. But there is also something else to do. Lots of scripts are already available via domoticz.com. Eg. a script to access my Denon amplifier, so that I can both control and monitor it. And also a complete meteorological station for less than 100 kroner, based on the above mentioned ESP8266.

And it is also possible to control lights and electrical outlets throughout the house. There are technologies for everyone. But I have an IHC system in the house, so it must of course be integrated. And such an integration already exists online. See https://sourceforge.net/projects/ihcsoftwarekit/files/IHC%20Server%20(duffman)/ A good man has been sweating and done a great job. Really great job!

I’ve already snatched some of it (and that is permitted, since it is open source) to access my Denon Amplifier in a slightly more sophisticated manner than the Bash script located at Domoticz.com. Specifically, I have been strongly inspired to create a C ++ program that can be configured using a text file.

Here you can (together with Denon’s own specification) see how a Denon or Marantz receiver can be controlled: http://blue-pc.net/2013/12/28/denon-av-reciever-ueber-http-steuern/

And I’m going to use the entire ihcserver unchanged when the RS485 interface for Raspberry Pi, which I ordered from dx.com, arrives. I think I can access both ihcserver (and thus my IHC system) and Domotics via their respective JSON RPC WEB interfaces from my own C ++ program, which I’m going to write to put the two ends together.

And then I will build the ESP8266 (Wemos D1 mini) based meteorology station, proposed in the Domoticz WIKI or on mysensors.org. And a Sonos integration. And it does not end there ……

There are alternatives to Domoticz. I have tried to install OpenHAB, or rather the version to Raspberry Pi, called openhabian. OpenHAB appears to be something that addresses more “ordinary people” and not so much to IT people, as Domoticz does. That is, more of the user interface has been made and there is much more plug-and-play in getting OpenHAB to work with various hardware. I have reached so far that OpenHAB can see the Sonos speakers I have, but not the Denon amplifier. And then, as with Microsoft products: Plug-and-play should rather be called plug-and-pray. When it does not work, it does not work and you do not know what is going on underneath the surface. In short, one is doomed.

It is the opposite way with Domoticz: It is initially more difficult to set up. But since you have direct access to various scripts, etc., it’s much easier to see what’s wrong. And thereby you can do something about it.

And since OpenHAB is in no way at the same high quality level as for example Microsoft Windows, then “pray” is not just a manner of speaking or a joke. I have seen it fail in two out of two cases. So I am not going to waste more time on it.

June 2017

The first packages from China have begun to arrive. Among other things, the long-awaited USB-RS485 interface, which enabled me to connect my IHC controller with a Raspberry Pi, on which I made IHCServer run during the two days of Pentecost. That in itself gives me a WEB page, with a button for each input and output in the IHC system. And when I press the buttons on the WEB page, the outputs or inputs of the IHC system get activated. Thus I can control the light throughout the house from my iPad. Regarding inputs there was a small error in IHCServer that I corrected and informed the author of IHCServer about. I want again to thank him for his excellent work. It was really easy to get to work.

But not only that. I have also defined all IHC inputs and outputs in Domoticz as virtual switches. Additionally, I have extended IHCServer with an ActivateOutput and a DeactivateOutput option (it has only a ToggleOutput option from “birth” because it is what is needed from its own WEB page) and made a script for each of these as well as for ActivateInput and DeactivateInput. The scripts are simple bash scripts, which, using curl, call IHCServer’s WEB service with POST commands. I am calling these scripts from the switches inside Domoticz.

That way I get IHCServer and thus the physical IHC system to respond to the Domoticz switches. But, of course, Domoticz should also be updated when there are changes in physical inputs and outputs in the IHC system. I’ve done that by adding some code inside IHCServer so it calls Domoticz ‘JSON interface every time IHCServer detects a change.

And as by magic, both Domoticz and IHCServer are now synchronized with the states of all inputs and outputs in the physical IHC system.

“And what can it be used for?”, The wondering reader probably asks.

The answer is: Almost everything. So far, I have defined intelligent timers that turn the light on or of according to the sun. But when I get the doorbell, water meter, TV, etc. integrated with Domoticz, I can, for example, make sure to turn on the appropriate light with the TV, mute the sound when the doorbell sounds, send an email to myself, if I have activated alarm mode, and some activity is detected in the house, sound the doorbell and blink with the light in the living room if too much water is used. And continue the list yourself. You can do everything. Only your imagination sets the limit. Not the options.

By the way, I have already ordered the next batch from China. This time I’m using aliexpress.com. It’s even cheaper than dx.com, which already costs almost nothing.

September 2018

IHCServer can now be found at Github: https://github.com/skumlos/ihcserver

Remember to clone the other projects from the same author. They are sub-projects.

I have added the  også at hente de andre projekter af samme forfatter. De er sub-projects.

I have added the Domoticz interface as a pull request.