Domoticz Installation

From ScottWiki
Jump to navigation Jump to search

Make a domoticz user to run the service

useradd --system domoticz -d /opt/domoticz/ -G dialout
mkdir /opt/domoticz
chown -R domoticz:domoticz /opt/domoticz/

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


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

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


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 domoticz

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


Start Domoticz on startup. Open the systemd configuration file :

nano /etc/systemd/system/domoticz.service
[Unit]
       Description=domoticz_service
[Service]
       User=domoticz
       Group=domoticz
       ExecStart=/opt/domoticz/domoticz/domoticz -www 8080 -sslwww 443
       WorkingDirectory=/opt/domoticz/
       # Give the right to open priviliged ports. This allows you to run on a port <1024 without root permissions (user/group setting abo$
       #
       # 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



Enable the service

systemctl daemon-reload
systemctl enable domoticz.service

Start the service

systemctl start domoticz.service


Script to update almost automatically For updating almost automatically, i made this script

#! /bin/sh
cd /opt/domoticz/ \
&& sudo service domoticz stop \
&& git pull \
&& make \
&& sudo service domoticz start \

Apache Secure Reverse Proxy

To access Domoticz from securely via an Apache server, create the following in /etc/apache2/sites-available/domoticz.conf:

<IfModule mod_ssl.c>
    <VirtualHost _default_:443>
        ServerName domoticz.scottworld.net

        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/domoticz.scottworld.net/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/domoticz.scottworld.net/privkey.pem
        SSLCertificateChainFile /etc/letsencrypt/live/domoticz.scottworld.net/chain.pem

        ProxyPass / http://127.0.0.1:8080/
        ProxyPassReverse / http://127.0.0.1:8080/
    </VirtualHost>
</IfModule>

If Domoticz is not running on the same server as Apache, simply updated 127.0.0.1 in the two Proxy lines above to point to the appropriate IP address.

Once complete, enable proxy, site and restart Apache:

a2enmod proxy
a2enmod proxy_http
a2enmod proxy_html
a2ensite domotoicz
systemctl restart apache2.service