Domoticz on a Raspberry Pi - Déjà Vu All Over Again
May 20, 2017
-- Workflow when Working with a Headless Raspberry Pi->

The plan is to make two series of posts showing how I use the home automation software Domoticz on the very popular Raspberry Pi single board computer. The first two posts will be common for both series. Then one series of posts will be about using X10 power line hardware with Domoticz on an older Raspberry Pi. The second series of posts will be about using ESP8266 based hardware, mostly reprogrammed Sonoff WiFi switches from ITEAD, with Domoticz on the newest Raspberry Pi.

Two reasons explain why I am doing this. Most of my X10 power line devices will soon have a new home. Lamp modules, appliance modules, socket receptacles, a couple of old Radio Shack plug'n power remote controller, a CM11A computer power line interface and an older Raspberry Pi hosting a Domoticz home automation server will be going to my sister's house in a few weeks.

At the same time, I trashed the SD card on the Raspberry Pi 3 running my current version of Domoticz. This is a lesson in the importance of backing it up regularly. This is also a great opportunity to start over and hopefully improve things the second time around. At the same time I am getting rid of some of the clutter associated with using what I now consider legacy hardware. However, until I build controllers to replace the wireless controllers that I presently use, support for X10 wireless hardware will be installed on the newer Pi.

Table of Contents

  1. Hardware
  2. Install Raspbian Jessie Lite
  3. Boot and Log In with Keyboard and Monitor
  4. Boot and Log In with SSH
  5. Udpate Raspbian
  6. Static IP Address and Wireless Connection
  7. Routing Around in the Router
  8. Raspberry Pi Configuration
  9. SSH Session
  10. Journalling Tweak
  11. Install Domoticz
  12. Basic Domoticz Settings

  1. Hardware
  2. My sister's home automation server will be a Raspberry Pi model B (Rev 2.0 with time stamp of 2011.12). This is an early model, with two USB 2.0 ports, one 10/100Mb Ethernet port and 512 MB of memory. The CPU is a single-core, 32 bit, ARM1176JZF-S which runs at a nominal 700Mhz but which is slightly overclocked to run at 800Mhz.

    My own home automation system will be Domoticz on a Raspberry Pi 3 model B. It has four USB 2.0 ports, one 10/100Mb Ethernet port, built in WiFin and 1 GB of memory. The CPU is a quad-core, 64 bit, ARM Cortex-A53 which runs at 1.2GHz. As of the 21st of May 2017, this is the latest Raspberry Pi model, aside from the Model Zero.

    There are very few differences between the two systems when it comes to installing the operating system and the home automation software. Hence this post applies to both.

  3. Install Raspbian Jessie Lite
  4. There's a new way to burn an image on an SD card: ETCHER. Its available for Linux, Windows and OS X, so flashing the SD card with the OS should be, for the most part, the same in all cases.

    1. Download the latest version of Raspian Jessie Lite. I obtained version 2017-04-10, Kernel 4.4, but the foundation will update this file from time to time so expect small changes to the configuration procedure. There is no need to extract the image file.
    2. Download the correct version of ETCHER.
    3. Extract the application. In Linux 64 bit, it is called Etcher-1.0.0-linux-x64.AppImage.
    4. Insert the SD card into a card reader.
    5. Double-click on Etcher-1.0.0-linux-x64.AppImage. When asked if the desktop file should be installed, I answered No, but if you think you will reuse this application often you can answer Yes.
    6. Wait until Etcher launches.
    7. Click on Select image and select the downloaded Raspian Jessie archive.
    8. Click on Change if the target SD card is not correct. Since one SD card connected was connected to the desktop computer, ETCHER found it without problem.
    9. Click on Flash!.
    10. Wait until Etcher has flashed the card and checked its content and then close it.

    Simple, straightforward, ETCHER (or is it Etcher?) is very good. Thank you to the developers.

    The easiest way to start using the Raspberry Pi is to connect a keyboard and monitor to it and to power it up. This is described in the next section. If a free keyboard and monitor or not available, go to the section named Boot and Log In with SSH.

  5. Boot and Log In with Keyboard and Monitor
  6. Insert the SD memory card into the Raspberry Pi, connect a USB keyboard (there is no need or use for a mouse) and a monitor, and finally connect the power supply. If all goes well, Raspbian will boot up. It may resize the file system, in which case it will reboot very quickly. Log in after the boot sequence:

    Raspbian GNU/Linux 8 raspberrypi tty1 raspberrypi login: pi Password: raspberry nothing will show on the screen Last login: ... pi@raspberrypi:~ $

    Later on, I will show how to change the password. That should always be done. Remember, numerous hackers get into systems because well-known default passwords are not changed. For now, skip the following section and move on to Update Raspbian.

  7. Boot and Log In with SSH
  8. If a keyboard and monitor are not available then it may be possible to boot the Raspberry Pi and log in using an SSH session from a desktop computer. By default, the Raspberry Pi SSH server is not enabled. However adding a file named ssh in the boot partition will enable it (see 3. Enable SSH on a headless Raspberry Pi. As explained in those instructions, the file can contain anything or even be empty.

    Once ETCHER has finished copying the OS image on the SD card, the latter will be mounted on a Linux system. In Ubuntu, the two partitions created on the card it shows up in the launcher bar. The drives are actually mounted in a directory called /media/user where of course user is your user name. The following shows how to create an empty file with the touch utility in Linux. First open a terminal by pressing simultaneously on the three keys Alt Ctrl T.

    michel@hp:~$ cd /media/michel michel@hp:/media/michel$ ls boot f2100b2f-ed84-4647-b5ae-089280112716 michel@hp:/media/michel$ touch boot/ssh
    If you will connect the Raspberry Pi to the local network with an Ethernet cable, then that may be all that is necessary. Note that the Raspberry Pi will be assigned an IP address by the DHCP server on the network which in all probability is the router supplied by the Internet service provider (ISP). So you must have a way of finding out that address. ....

    Alternatively, a static IP address can be assigned to the Raspberry Pi. This can be done by editing configuration files in ext partition created on the SD card. This is done with relative ease from the desktop computer if it is a Linux system (and perhaps with a Mac) but it probably requires installing some additional drivers in Windows to access ext partitions.

    Since I have a Ubuntu desktop, I went ahead and edited the configuration files. The mounting point of the partition was the GIUD type name shown in the /media/user directory. It is rather tedious to type in such a long name, so I first made it the working directory with the cd command. By editing the etc/dhcpcd.conf file, a static address was assigned to both the ethernet link (eth0) and the WiFi link (wlan0).

    michel@hp:/media/michel$ cd f2100b2f-ed84-4647-b5ae-089280112716 michel@hp:/media/michel/f2100b2f-ed84-4647-b5ae-089280112716$ sudo nano etc/dhcpcd.conf
    interface eth0 static ip_address= static routers= static domain_name_servers= interface wlan0 static ip_address= static routers= static domain_name_servers=

    Save this configuration by press on the keys Ctrl O (letter O not the number 0) simultaneously and then press Enter to save the file with its current file name. Exit nano by pressing span class="key">Ctrl X.

    To complete the configuration of the WiFi interface, the SSID and password of the WiFi network must be specified in a file named wpa_supplicant.conf in the directory named etc/wpa_supplicant/ in the ext partition.

    michel@hp:/media/michel/f2100b2f-ed84-4647-b5ae-089280112716$ sudo nano etc/wpa_supplicant/wpa_supplicant.conf
    network={ ssid="Name_of_your_wifi_network" psk="your_wifi_password" }

    Insert the SD memory card into the Raspberry Pi and connect it to the local area network (with an Ethernet cable if not using WiFi) and finally connect the Raspberry Pi to its power supply. If all goes well, Raspbian will boot up and eventually the SSH server will start. Read the section SSH Session to find out how to log in from the desktop computer with an SSH session. Then go back to the previous sections to Update Raspbian and Raspberry Pi Configuration. Finally continue with 10 Journalling Tweak.

  9. Udpate Raspbian
  10. I updated and upgraded Raspbian immediately because it was possible to connect the Raspberry Pi to the local area network with an Ethernet cable.

    pi@raspberrypi:~ $ sudo apt-get update ... pi@raspberrypi:~ $ sudo apt-get upgrade ... 47 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. Need to get 102 MB of archives. After this operation, 4,491 kB of additional disk space will be used. Do you want to continue? [Y/n] y

    On the first generation Raspberry Pi, this last step will take a long, long time. Treat yourself to a coffee. You may have time to finish reading Tolstoy's War and Peace. On the Raspberry Pi 3, you will have time to savour a chocolate bar along with your coffee.

    If you can only manage a WiFi connection, go to the next step immediately and upgrade latter.

  11. Static IP Address and Wireless Connection
  12. The home automation program Domoticz contains a Web server which is accessed with a Web browser such as Firefox, Edge, Safari etc. This means that the Web server must be at a fixed, static IP address. However, by default the Raspberry Pi uses the DHCP protocol to obtain a variable, dynamic IP address from a DHCP server on the local area network. That server will in all likelihood will be the router provided by the Internet service provider.

    That means that some changes have to be made to the network configuration. It also means that a decision must be made as to which interface will be used. The Raspberry Pi 3 contains two network interfaces: a wired Ethernet link (Cat5 or Cat6 cable with RJ45 connectors) and a wireless WiFi link. I use the wireless interface because it allows me to place the Raspberry Pi out of the view under a small bookcase. A USB-WiFi dongle provides wireless connection to the LAN on the older Raspberry Pi. I do not yet know which one of the wired or wireless interface will be used. Hopefully, it will be possible to set the small computer close to the router and to use an wired connection because there are only two USB connectors on the older Raspberry Pi and I would like to avoid using a USB hub.

    Here is how to set the static IP address for the wired and wireless interfaces. Open the dhcpcd configuration file in the nano editor and add the following lines, albeit with appropriate changes!

    pi@raspberrypi:~ $ sudo nano /etc/dhcpcd.conf
    interface eth0 static ip_address= static routers= static domain_name_servers= interface wlan0 static ip_address= static routers= static domain_name_servers=

    By "appropriate changes" I meant that you will have to choose the correct local area network (LAN) addresses for the interfaces, router and domain name server for your LAN. Remember, interface eth0 refers to a wired link to a switch or router on the local area network (LAN) over an Ethernet cable while interface wlan0 refers to a wireless link to a WiFi router on the LAN. Of course, in some cases it would be perfectly acceptable to have only one static address. However if you do have two, then their IP addresses must be different. And of course, the assigned IP addresses must not be used by other devices connected to the LAN.

    Since I am preparing two servers and will be running both of them on the same network, at least for a few weeks, each got a different set of static addresses. For argument's sake, I'll suppose from now on that the static IP address used by the Raspberry Pi is

    Save the configuration file. In the nano editor, do that by pressing Ctrl O (letter O not the number 0) simultaneously and then press Enter to save the file with its current file name. Exit nano by pressing Ctrl X.

    There is an extra step required to enable the wireless connection if used. The following instructions comes from the Raspberry Foundations's documentation. Open the wpa-supplicant configuration file with the nano editor and add the following at the bottom of the file.

    pi@raspberrypi:~ $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
    network={ ssid="Name_of_your_wifi_network" psk="your_wifi_password" }
    Save this configuration file as before: press Ctrl O (letter O not the number 0) simultaneously and then press Enter to save the file with its current file name. Exit nano by pressing Ctrl X.

    Time to test. First cycle the Raspberry Pi off and then back on, or better yet reboot the Raspberry Pi and then log on.

    pi@raspberrypi:~ $ sudo reboot ... raspberrypi login: pi Password: raspberry nothing will show on the screen Last login: ...

    Secondly, check the network interface configuration.

    pi@raspberrypi:~ $ ifconfig pi@domo:~ $ ifconfig eth0 Link encap:Ethernet HWaddr b0:c7:eb:ff:56:fd inet addr: Bcast: Mask: inet6 addr: 3718:fea8:f081:da5:663a:339e:a15b:e3b4/64 Scope:Global ... RX bytes:37439 (36.5 KiB) TX bytes:29853 (29.1 KiB) lo Link encap:Local Loopback inet addr: Mask: ... RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) wlan0 Link encap:Ethernet HWaddr b8:27:eb:aa:03:a8 inet addr: Bcast: Mask: inet6 addr: de00:eb:ad4b:71b2:cce9:8e3e:e948:8986/64 Scope:Global ... RX bytes:26657 (26.0 KiB) TX bytes:21434 (20.9 KiB)

    If you don't see something like inet addr: as shown above then it may be that only version 6 IP addresses are assigned to interfaces. I have had that problem with Raspian Jessie. After some searching, I found the following solution. Create the file /etc/sysctl.d/local.conf containing a single line disabling IPv6.

    pi@raspberrypi:~ $ sudo nano /etc/sysctl.d/local.conf

    Save this configuration file in the usual way. Press Ctrl O (letter O not the number 0) simultaneously and then press Enter to save the file with its current file name. Exit nano by pressing Ctrl X.

    Even if the IP version 4 static addresses are assigned, you may want to disable IP version 6 on the Raspberry Pi as shown above. As far as I can tell, there is no real need for the newer version of IP on a local area network and by not running that stack you may be giving the Raspberry Pi a little bit more breathing space. Having said that, my ISP provided router supports IPv6 so who knows what is coming up?

    Reboot and check with ifconfig. Everything should now work. If it does not seem to work look at the next section.

  13. Routing Around in the Router
  14. Since you had to find the router's IP address, you may want to change some of its settings. This is optional. Remember that not only must you know the IP address of the router but you will also need the the user name and password. A good search engine may be your best friend to find out how to log onto the router's web server and how to change settings.

    First, I suggest that you change the default password. Routers are small computers and they can be hacked in some cases.

    My second suggestion is to is to limit the range of IP addresses that can be assigned by the DHCP server. In that case, you should always choose a free static address outside of that range. That will avoid all possible conflicts (except those you create yourself by assigning the same static address to another device... it happens, believe me).

    If you could not get a static IP address to stick by modifying the Raspberry Pi configuration, then you can probably do it with the router. This is done by assigning an IP address to a device based on the universally unique media access control address (MAC address) that all network interfaces have. Again, setting parameters on each router is different, but with my router, I need to click on the DHCP Reservation button on the Basic Settings page and then scroll to the Manually Add Client area. Basic Settings Then I specify an Client Name ("Domo" for example) the desired static IP address ("") and the interface MAC address ("b0:c7:eb:ff:56:fd") which is called HWaddr in the output of the ifconfig utility.

    If everything failed and you could not get a static IP address, I suggest that you increase the DHCP lease time as much as possible. Basically that "reserves" an IP address for a device for the specified time even if the device goes offline. On my router I can specify a "forever" lease time. That would almost amount to a static address I assume. But it does not have to be "forever", just choose the longest lease available.

    While I managed to define a static address in the Raspberry Pi, I still found it useful to have a longish lease time. It helps with IoT type devices (such as Sonoff switches) so that their IP address does not change on every reboot.

    As you can see, except for the password change, all my suggestions can be done in a single Basic Settings page on my router: Basic Settings But remember, things will be done differently on other models.

  15. Raspberry Pi Configuration
  16. It is far easier to run the Raspberry Pi as a "headless server", which means running it without a keyboard and without a monitor. Remember, I hide my home automation system under a bookcase and I adjust the Raspberry Pi from my desktop computer wired to the same local area network using an SSH session. But before that can be done, the Raspberry Pi SSH server must be enabled. Other parameters should be set at the same time. All this can be done with the raspi-config utility:

    pi@raspberrypi:~ $ sudo raspi-config

    The following text mode window will appear. Use the up and down cursor keys to move the selection bar in the menu, and the tab key or the right and left cursor keys to move from the menu to the action buttons at the bottom. main menu - Change User Password It is a "very good thing" to change the password, which is the first configuration option. Click on the Tab key to move to the <Select> action and press on the Enter key or the space bar to continue with setting a new password.

    Returning to the main menu, the host name can be changed. main menu - Hostname I changed the host name from raspberrypi to domopole on the older Raspberry Pi and to domo on the newer. This is optional, but useful.

    The Boot Options do not need to be changed. But the Localisation Options should be set.
    Advanced Options - Localisation Options

    At a minimum the Timezone should be set by selecting the nearest city picked from a list. main menu - Localisation Options Activate <Select> to get to the list.

    First select the continent (Geographic area): Localisation - Change Timezone

    Then select the city. Change Timezone - Geographic Area They are almost sorted alphabetically. Typing a letter moves the selection to the first city starting with the corresponding letter.

    It is now time to enable the SSH server. First select the Interfacing Options in the main menu: Main menu - Interfacing Options

    Then select SSH in the following window: Interface - SSH

    And answer Yes when asked to enable the SSH server: SSH - Enable SSH server From this point on, this can be done from another computer on the local area network over an SSH connection, as explained in the next section.

    Back in the main menu, select Advanced Options:
    Main menu - Advanced Options

    If this was not done on the first boot, select the Expand Filesystem option: Advanced Options - Expand Filesystem and click on Ok when the root partition has been resized:
    Advanced Options - End of Expand Filesystem I think, there will be no harm done if you expand an already expanded file system.

    When back in the Advanced Options screen, select the Memory Split option: Advanced Options - Memory Split and set the GPU memory to the minimum value, 16 MB: Advanced Options - GPU Memory Again, this will be a headless server that will not be offering a graphical user interface. There is no need to allocate memory to the graphic processor.

    To optionally speed up the system, select the Overclock option in the main configuration menu. Below I show how I increased the speed of the older Rapsberry Pi. I could not overclock the Rapsberry Pi 3 using this utility, but if you insist there is some information on the Web. Advanced Options - Overclock Read the warning: Advanced Options - Overclock warning And then leave the CPU frequency and voltage unchanged or increase them at your own risk Advanced Options - Overclocking If you do overclock the system, you should consider dissipating the extra heat with heatsinks and a fan.

    There should be no need to Update since that was done with the system wide update. The final step is to select Finish in the main menu: Main menu - Memory Finish If asked, reboot: Main menu - Finish - reboot If not asked, but you changed the hostname, it is better to reboot. Be brave, throw caution to the wind and reboot anyway, just to be safe:

    pi@raspberrypi:~ $ sudo reboot ... domopole login: pi Password: your_new_password nothing will show on the screen Last login: ...

    There are numerous ways to check the size of the file system, if you are wondering if it has been expanded to fill the SD card. Here is one of them:

    pi@domopole:~ $ df -h --output=source,fstype,size,target -x tmpfs -x devtmpfs Filesystem Type Size Mounted on /dev/root ext4 15G / /dev/mmcblk0p1 vfat 41M /boot
    which corresponds to my 16G SD card.

  17. SSH Session
  18. From now on, I will control the Raspberry Pi from my desktop, called hp (guess why?). For that, I open an SSH session. Since this is the first time, a security key will be added.

    michel@hp:~$ ssh pi@ The authenticity of host ' (' can't be established. ECDSA key fingerprint is 1e:21:76:b1:3f:81:a7:21:68:1c:44:33:1d:c8:18:f9. Are you sure you want to continue connecting (yes/no)? yes pi@'s password: enter new password The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Sat May 20 09:05:46 2017 pi@domopole:~ $

    Loging in for an SSH session will be simpler after:

    michel@hp:~$ ssh pi@ pi@'s password: enter new password ...blah blah blah pi@domopole:~ $

    Since everything seems to be working, I have disconnected the keyboard and monitor from the Raspberry Pi.

    It is not necessary to use a desktop, it is just simpler for me. Everything shown below can be done using the connected keyboard and monitor.

    If you could not log in and got a long message such as

    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. ... Host key verification failed.
    there is probably nothing nefarious going on. Whenever I have had that message it was because I had already opened an SSH session with a different device at the same IP address but it had a different security key. As told in the message, you should enter
    michel@hp:~$ ssh-keygen -f "/home/michel/.ssh/known_hosts" -R
    which will erase the old key, and then try to log in as explained above.

  19. Journalling Tweak
  20. By default, logs or journals are files saved on the SD card by systemd. This may not be the best thing, since there is a limit on the number of reads and writes that can be performed on an SD card. It is best to write the log to memory.

    Edit the journald configuration file, changing three lines as shown next.

    pi@domopole:~ $ sudo nano /etc/systemd/journald.conf
    # This file is part of systemd. # [Journal] Storage=volatile Compress=yes RuntimeMaxUse=48M

    The source for this tweak is the Domoticz wiki. It may be best to hold off until all is stable before doing this so that logs will be persistent.

  21. Install Domoticz
  22. As the download page at Domoticz says, a one-line script will install the program.

    pi@domopole:~ $ sudo curl -L | bash

    There's a bit more to it of course. A few questions must be answered, but the default answers are acceptable:


    The first screen shown by the installer is a reminder that a static IP address is required, and a suggestion to donate to the project: Next is a screen asking if HTTP and HTTPS (secure HTTP) access to the server is to be allowed. As can be seen both are enabled by default. So I accepted that but HTTPS access is problematic without security certificates. The next two screen ask for the HTTP and HTTPS port numbers I accepted the default port 8080 for HTTP requests and the default port 443 for HTTPS requests.

    Then the installation folder must be specified: Again I accepted the default value. The final screen gives the addresses of the HTTP and HTTPS access pages and gives the addresses of the Domoticz Wiki ( and and Forum (

    The installation then concludes:

    ::: Restarting services... ::: ::: Enabling service to start on reboot... done. ::: ::: Starting service... done. ::: done. ::: ::: Installation Complete! Configure your browser to use the Domoticz using: ::: ::: pi@domopole:/ $

    Start a web browser on your desktop and connect to the Domoticz built-in web server on the Raspberry Pi at You will not see much, because nothing is installed, but at least you are now assured that everything is working.

    If you want to change the HTTP and HTTPS ports used by Domoticz, edit the -www and -sslwww arguments in the script file in the /etc/init.d directory. You have to be root. Here is an example.

    pi@domopole:~ $ sudo nano /etc/init.d/
    ... DAEMON_ARGS="$DAEMON_ARGS -www 8888" DAEMON_ARGS="$DAEMON_ARGS -sslwww 444" ...
    The template for this start up script can be found in the home directory ~/domoticz/ and it contains the default values 8080 and 443. I have renamed the template file to make sure that I don't confuse it with the actual start script.

  23. Basic Domoticz Settings
  24. Its time to define some basic system settings. Click on the Setup button at the top right and then select Settings. By default the System tab is opened.

    At a minimum, the Location (longitude and latitude) should be defined. Presumably, that information is used to calculate sunset and sunrise. I used my car's GPS to find the exact values. Perhaps a GPS equipped smart phone or tablet could be used. If none of these possibilities are available, Domoticz can provide reasonably accurate coordinates given a street address. Click on the Here link underneath the Longitude box.

    It is a good idea to password protect the website. Provide a username and a password in the Website Protection section. It does become cumbersome to log in every time. Thankfully, it is possible to specify "login free" local networks. Using a browser on a machine located on any one of those specified networks will log in automatically, bypassing the login requirement. You will notice that I did not include the suggested local host network 127.0.0.* because I run a Tor service on the server instead of "port forwarding" outside requests through the router. If 127.0.0.* were included as a local network, the password would not be required when connecting with the Tor browser from outside the local area network.

    Do not forget to click on the Apply Settings button, otherwise the changes made will not take effect.

    Consult the Domoticz wiki page Application Settings for more information about other settings.

    Consult the page dedicated to installation on the Raspberry Pi. In particular you should look at the section entitled Raspberry Pi additional software installations. You will notice that I shamelessly copied the "Setting up a RAM drive on Raspberry Pi" from that page.

-- Workflow when Working with a Headless Raspberry Pi->