Linux

From Domoticz
Jump to: navigation, search

This page describes how to compile/build the latest beta snapshot of Domoticz for Debian-based Linux operating systems. There's no need for all this if you're just installing a pre-built binary (see the downloads page for that).
This procedure has been tested on Ubuntu Server 14.04 LTS and 16.04 LTS

You can freely download them on this site: http://ubuntu.mirrors.proxad.net/16.04.2/ubuntu-16.04.2-server-amd64.iso


Installing the required libraries

Note: If you are running Ubuntu 16.04 or higher it is recommended to use apt instead of apt-get.

First update your system:

sudo apt-get update
sudo apt-get upgrade

This can take a while if you haven't done it recently.

Then install the development tools and libraries needed for compiling Domoticz:

sudo apt-get install build-essential nano cmake git libboost-dev libboost-thread-dev libboost-system-dev
sudo apt-get install libsqlite3-dev curl libcurl4-openssl-dev libssl-dev libusb-dev zlib1g-dev python3-dev


Fixing possible dependency problems with Ubuntu 12.04 LTS and older

Using the above method on older versions of Ubuntu (12.04 LTS) may result in the compilation failing with errors like: error: ‘class boost::asio::io_service’ has no member named ‘stopped’ In this situation you need to update your boost libraries to a later version than that installed by apt-get. The simplest way to do this is to follow the instructions on the Raspberry Pi page HERE

CMake version

To use Python Plugins cmake version 3.0.1 or above is required so that Python 3 is discovered properly. To discover the version of cmake on your system use:cmake --version. If it is at not at least version 3 the cmake process can not find python 3.

Download and build 3.9.2 of cmake using:

sudo apt-get install build-essential
wget https://cmake.org/files/v3.9/cmake-3.9.2.tar.gz
tar xf cmake-3.9.2.tar.gz
cd cmake-3.9.2
./configure
make
sudo make install

Compiling/building the Domoticz binaries

Note: If you need support for Z-Wave and/or Tellstick you need install support for them before compiling Domoticz. Read in the following sections how to install support for Z-Wave and Tellstick.


Compiling will take about 10-15 minutes on a slower PC. If you have a multicore system you can pass the -j flag to 'make' to use several cores, which is a lot faster. On a quad (four core) system you can for example write make -j4 instead of only make.

Get the latest Domoticz sourcecode and compile/build by running:

cd ~
git clone https://github.com/domoticz/domoticz.git domoticz
cd domoticz
cmake -DCMAKE_BUILD_TYPE=Release .
make

Note: If you have any hardware connected via USB or serial interfaces you need to enable access to ttyUSB ports before starting Domoticz. Follow these instructions.

Some older Boost libraries on certain hardware can give you If linkage error. In that case you could try adding the flag -DCMAKE_EXE_LINKER_FLAGS=-lboost_atomic to the cmake command.

To start Domoticz type:

./domoticz

When you open your browser at http://ip_of_your_machine:8080, you should be presented with the Domoticz web interface.

For additional parameters of the Domoticz daemon, run:

./domoticz -h

To start Domoticz automatically when the system boots follow these instructions.

Allow non-root user to access ttyUSB* ports

If you don't plan on interfacing Domoticz with USB and/or serial devices, you can skip this step.

By default (at least on Ubuntu) a non-root user has no permission to access the ttyUSB* ports. So if you have Domoticz running under a separate user (which is always a good idea to make the system more secure), Domoticz isn't allowed access to your RFXCOM for example. Here are two methods of doing it. For most people the first one by adding the user to the dialout goup is enough and by far the easiest.

Adding the user to the dialout group

This can be done by running the command below:

sudo usermod -a -G dialout YOURUSERNAME

(Where you replace YOURUSERNAME with the user that runs Domoticz.)

Setting up a udev rule

Alternatively you can setup (as root) a udev rule that matches the RFXCOM device. To find which attributes match your device use the command:

udevadm info -a -p $(udevadm info -q path /dev/ttyUSB1) | less

Where /dev/ttyUSB1 is the device. If you wish to run Domoticz under the YOURUSERNAME credentials, who is member of the YOURGROUPNAME group and your device has serial YOURSERIAL a suitable udev rule would be:

SUBSYSTEM=="tty", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{serial}=="YOURSERIAL", ATTRS{idProduct}=="6001", SYMLINK+="ttyUSB21", OWNER="YOURUSERNAME", GROUP="YOURGROUPNAME"

Save it to a file under /etc/udev/rules.d/ with the .rules extention and run:

service udev reload

Unplug and replug the device and execute:

ls -l /dev/ttyUSB*

You should see something like

crw-rw---- 1 domoticz domoticz 188, 1 Nov 10 15:27 /dev/ttyUSB1
lrwxrwxrwx 1 root     root          7 Nov 10 15:27 /dev/ttyUSB21 -> ttyUSB1

The added SYMLINK+= creates an additional link to the device node. This is a static name that is useful when you have multiple usb-serial devices that go into your box. Use the static link in Domoticz. For more information on udev rules have a look here: http://www.reactivated.net/writing_udev_rules.html

Starting Domoticz automatically when the system boots

There are basically two ways to do this - via init.d (which starts things serially) or via systemd (which starts things up in parallel and therefore leads to faster booting). On modern systems the systemd method is generally preferred.

Option 1: Init.d Method

To let Domoticz start automatically when the system boots (which is probably the case, as most people run it on a headless server), run the commands below, (You want to end up in /home/YOURUSERNAME/domoticz/)

cd domoticz
sudo cp domoticz.sh /etc/init.d
sudo chmod +x /etc/init.d/domoticz.sh
sudo update-rc.d domoticz.sh defaults

Edit the startup script.

sudo nano /etc/init.d/domoticz.sh

The lines you usually need to change are USERNAME, DAEMON and DAEMON_ARGS

USERNAME=yourusername
DAEMON=/home/$USERNAME/domoticz/$NAME
DAEMON_ARGS="-daemon -www 8080"
  • Change the USERNAME variable to the user you want domoticz to be run as. It's recommended to run domoticz as its own user and not as root, due to security reasons.
  • If you installed Domoticz in the USERNAME home directory /home/yourusername/domoticz you don't need to change the DAEMON variable. If you installed it in an alternate location for example /usr/local/domoticz/ you should change DAEMON to /usr/local/domoticz/$NAME
  • If you want to use another web interface port change the '8080' in: DAEMON_ARGS="-daemon www 8080" to your own port.

Note: To be able to use ports below 1024, for example the standard port for webbrowsing, 80, you need to run domoticz as the root user.

If you want to see more arguments for DAEMON_ARGS run this in the domoticz directory. This is usually not needed.

./domoticz -h

Domoticz will now start automatically when you reboot your machine.

Manually controlling the Domoticz service

This only works if you followed the above steps.

You can now start/stop/restart and check the status of domoticz with:

sudo /etc/init.d/domoticz.sh start
sudo /etc/init.d/domoticz.sh stop
sudo /etc/init.d/domoticz.sh restart
sudo /etc/init.d/domoticz.sh status

If your system supports it you can instead use:

sudo service domoticz.sh start
sudo service domoticz.sh stop
sudo service domoticz.sh restart
sudo service domoticz.sh status

Option 2: Systemd Alternative (Preferred)

Open the systemd configuration file :

vi /etc/systemd/system/domoticz.service
[Unit]
       Description=domoticz_service
[Service]
       User=domoticz
       Group=domoticz
       ExecStart=/home/domoticz/domoticz/domoticz -www 8080 -sslwww 443
       WorkingDirectory=/home/domoticz
       # Give the right to open priviliged ports. This allows you to run on a port <1024 without root permissions (user/group setting above)
       #
       # The next line was previously working, so try this on older systems.
       # ExecStartPre=setcap 'cap_net_bind_service=+ep' /home/domoticz/domoticz/domoticz
       #
       # The below works on ubuntu 16 LTS.
       CapabilityBoundingSet=CAP_NET_BIND_SERVICE
       Restart=on-failure
       RestartSec=1m
       #StandardOutput=null
[Install]
       WantedBy=multi-user.target

or on Raspberry Pi Stretch as root (remove '#' on User and Group lines to run as 'Pi' user):

[Unit]
      Description=domoticz_service
[Service]
      #User=pi
      #Group=users
      ExecStart=/home/pi/domoticz/domoticz -www 8080 -sslwww 443
      WorkingDirectory=/home/pi/domoticz
      ExecStartPre=setcap 'cap_net_bind_service=+ep' /home/pi/domoticz/domoticz
      Restart=on-failure
      RestartSec=1m
      #StandardOutput=null
[Install]
      WantedBy=multi-user.target

Enable the service

systemctl daemon-reload
systemctl enable domoticz.service

Start the service

systemctl start domoticz.service

Note: Use only one of these two alternatives (init.d method or systemd method) for auto-start.

Updating Domoticz

Once in a while, a new Domoticz version is released, and of course you want to update. You can do this with the commands below:

  1. First stop Domoticz with sudo /etc/init.d/domoticz.sh stop or sudo service domoticz.sh stop
  2. Navigate to the directory where Domoticz is installed: cd domoticz (You want to end up in /home/YOURUSERNAME/domoticz/)
  3. Pull the latest Domoticz code from Github: git pull
  4. Compile/build the files that have been downloaded: make && sudo /etc/init.d/domoticz.sh start (Compiling will take a while, but the command will automatically start Domoticz again when compiling is done, so you can go to sleep or do something else in the meantime.)

If all went correctly, Domoticz should be updated to the latest version and should be running again automatically.

Attention: when you use Monit, be sure to disable it before doing the update process, otherwise after you have stopped Domoticz by hand yourself, it will get restarted automatically by Monit within a few minutes (because that is what is Monit should do normally).
Stopping Monit can be done by sudo /etc/init.d/monit stop and after updating it can be started again with sudo /etc/init.d/monit start.
You could also use this command: make && sudo /etc/init.d/domoticz.sh start && sudo /etc/init.d/monit start to update, start Domoticz & start Monit when updating is done.

Script to update almost automatically

For updating almost automatically, i made this script

#! /bin/sh
cd /home/YOURUSERNAME/domoticz/ \
&& sudo /etc/init.d/monit stop \
&& sudo /etc/init.d/domoticz.sh stop \
&& git pull \
&& make \
&& sudo /etc/init.d/domoticz.sh start\
&& sudo /etc/init.d/monit start

Save it as domoupdater.sh, give it executable rights (chmod +x domoupdater.sh) and call it by sh /home/YOURUSERNAME/domoupdater.sh
It will change the current path to the Domoticz folder, stop Monit, stop Domoticz, pull binaries, compile, start Domoticz, start Monit again.
Very handy to run & go do something else.

In theory it can work automatically (weekly cronjob for example), however when running as a non-root user (which is the case in my situation), it will ask for the password of the user. But after you have provided the password (almost immediately after the script has started), it will continue without needing any further user input.
In theory it is possible to let it run fully automated, but i myself prefer a bit of feedback (watching afterwards if all went well). If you want to work around this sudo password asking, look here.

Add support for Z-Wave

Follow the steps below if you want to add support for Z-Wave devices in Domoticz. This needs to be done before compiling domoticz.

Install libudev-dev

To install the specific dependencies issue the command:

   sudo apt-get install libudev-dev

Compile OpenZWave

The OpenZWave source directory needs to be in the same directory as the domoticz directory

   cd ~
   git clone https://github.com/OpenZWave/open-zwave.git
   ln -s open-zwave open-zwave-read-only
   cd open-zwave
   make
   cd ..

The directory should look something like this

   drwxrwxr-x 27 pi pi 4096 aug 12 19:59 domoticz
   drwxrwxr-x 11 pi pi 4096 aug 14 16:30 open-zwave
   lrwxrwxrwx  1 pi pi   10 aug 14 16:32 open-zwave-read-only -> open-zwave

Updating OpenZWave

To update the OpenZWave-part, run these commands:

   cd open-zwave
   git pull
   make clean
   make
   cd ..

Problems when compiling Domoticz with OpenZWave

For people having trouble compiling with OpenZWave try with a fresh source.

   cmake -USE_STATIC_OPENZWAVE -DCMAKE_BUILD_TYPE=Release CMakeLists.txt

instead of

   cmake -DCMAKE_BUILD_TYPE=Release .

when compiling the main Domoticz binary. For more information read this thread on the forum: Link

Problems locating Python

Some users, particularly those on old operating systems see the following message when starting Domoticz:

 2016-12-20 09:44:32.251 Failed dynamic library load, install the latest libpython3.x library that is available for your platform. 

this shows that, even though python3 may be on the system, the python library can not be located. This error will not stop Domoticz from starting but will mean that hardware supported by the Python Plugin Framework will not be available. To fix this, install the newest version of libpython3 for the platform. For example, RaspberryPi Jessie has python 3.4 on it but the library is not included. Executing:

 sudo apt-get install libpython3.4

should solve the issue. Note that python 3.4 is the earliest support version of python, where available later versions should always be used.
If you are building from source and python 3 is installed but Make is not able to progress, try to add

 set(Python_ADDITIONAL_VERSIONS 3.4)

just before find_package(PythonLibs 3.4) in the CMakeLists.txt

If your platform does not have a compatible version, for example RaspberryPi Wheezy, then one can be built from source using:

 wget https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tar.xz
 tar -xvf Python-3.5.2.tar.xz
 cd Python-3.5.2
 ./configure --enable-shared
 make
 sudo make install

Don't miss the enabled-shared flag otherwise libpython will not be built.

Note: Only peform this step if you are building from source and are having issues, it should not be required.
After building Python 3.5.x change CMakeLists.txt

 option(USE_PYTHON_PLUGINS "Use Python Plugins" YES)
 IF(USE_PYTHON_PLUGINS)
   set(Python_ADDITIONAL_VERSIONS 3.5)      <---- add this line
   find_package(PythonLibs 3.5)   <---- change version into 3.5
   IF(PYTHONLIBS_FOUND)

Add support for Tellstick

If you need support for Tellstick or Tellstic Duo you need to install telldus-core before compiling Domoticz. On Debian-based systems (For example Ubuntu and Raspbian) telldus-core can be installed by doing the following:

echo "deb http://download.telldus.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/telldus.list
wget -q http://download.telldus.se/debian/telldus-public.key -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install libtelldus-core-dev