Aug 10, 2024 3 min read

Domoticz: Simplifying Self-Hosting

Domoticz: Simplifying Self-Hosting
Table of Contents

Domoticz is a lightweight, open-source home automation system designed to help users manage a variety of smart devices and sensors. Its self-hosted nature makes it an ideal choice for those who value customization, privacy, and full control over their automation setups. This guide will walk you through the process of installing Domoticz, configuring it with reverse proxy settings, managing logs, performing backups, updating the app, and leveraging its unique features.

Installing Domoticz

πŸ“¦ Docker/Docker Compose Setup

Using Docker simplifies deployment and maintenance. Below is a docker-compose.yml file tailored for Domoticz:


version: '3'

services:

domoticz:

image: domoticz/domoticz:latest

container_name: domoticz

restart: unless-stopped

ports:

- "8080:8080" # Web interface

volumes:

- ./domoticz_data:/opt/domoticz/config

environment:

- TZ=Europe/Amsterdam

networks:

default:

driver: bridge

Deploy Domoticz with the below commands:


mkdir domoticz && cd domoticz

nano docker-compose.yml # Paste the above YAML

docker-compose up -d

This will start Domoticz on port 8080, storing configuration data in the domoticz_data directory.

πŸš€ Manual Installation

To install Domoticz manually on a Linux server:


sudo apt update && sudo apt upgrade -y

sudo apt install build-essential cmake libsqlite3-dev libcurl4-openssl-dev zlib1g-dev -y

wget https://www.domoticz.com/releases/domoticz_linux_x86_64.tgz

tar -xvzf domoticz_linux_x86_64.tgz

cd domoticz

./updatebeta

./domoticz -www 8080

This sets up Domoticz and starts it on port 8080. For persistent operation, consider setting it up as a systemd service.

Configuring Nginx as a Reverse Proxy

🌐 Nginx Configuration

To serve Domoticz through Nginx, create the following configuration file:


sudo nano /etc/nginx/sites-available/domoticz.conf

Add the following content:


server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://localhost:8080;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

}

Enable the configuration:


sudo ln -s /etc/nginx/sites-available/domoticz.conf /etc/nginx/sites-enabled/

sudo systemctl restart nginx

πŸ”’ SSL/TLS Setup

Secure the connection using Let's Encrypt:


sudo apt install certbot python3-certbot-nginx -y

sudo certbot --nginx -d yourdomain.com

Automate certificate renewals:


sudo systemctl enable certbot.timer

πŸ› οΈ Testing and Reloading Nginx

Verify the configuration and reload:


sudo nginx -t

sudo systemctl reload nginx

Your Domoticz instance is now securely accessible at https://yourdomain.com.

Logging and Debugging Domoticz

πŸ—ƒοΈ Enabling Debug Logs

To activate debug-level logging, modify the startup command:


./domoticz -loglevel=debug -www 8080

πŸ“„ Viewing Logs

If using Docker, view logs with:


docker logs domoticz

If manually installed, check the log file:


tail -f domoticz.log

πŸ› οΈ Troubleshooting Common Issues

  • Port Conflicts: Ensure no other application uses port 8080.

  • Permission Errors: Verify the app has write access to configuration directories.

πŸ“€ Exporting Logs

Send logs to an ELK Stack:


cat domoticz.log | curl -XPOST 'http://elkserver:9200/domoticz-logs/_bulk' -H 'Content-Type: application/json' --data-binary @-

Backup and Restore

πŸ—‚οΈ File-Based Backups

Backup Domoticz configuration files:


tar -czvf domoticz_backup.tar.gz ./domoticz_data

πŸ”„ Database Backups

Domoticz uses an SQLite database. Backup the database with:


sqlite3 domoticz.db ".backup domoticz_backup.db"

πŸ“… Automated Backup Scripts

Automate backups using cron:


crontab -e

Add the following:


0 3 * * * tar -czvf /backups/domoticz_backup_$(date +\%F).tar.gz /path/to/domoticz_data

Updating and Upgrading Domoticz

⬆️ Updating Docker Images

Update Domoticz in Docker:


docker pull domoticz/domoticz:latest

docker-compose down && docker-compose up -d

πŸ› οΈ Manual Updates

For manual installations:


cd domoticz

./updatebeta

πŸ” Checking for Updates

Navigate to Settings > Check for Updates within the Domoticz UI to verify version information.

Leveraging Domoticz’s Unique Features

πŸ”§ Enabling APIs

Enable APIs in Domoticz:

  1. Go to Settings > System > Enable API.

  2. Use the following curl command to test:


curl -X GET "http://yourdomain.com/json.htm?type=devices"

🌟 Advanced Configurations

Integrate MQTT for advanced automation:

  1. Enable MQTT in Settings > Hardware > Add MQTT.

  2. Install Mosquitto as the MQTT broker:


sudo apt install mosquitto mosquitto-clients -y

  1. Test communication:

mosquitto_pub -h localhost -t "domoticz/in" -m '{"idx":1,"nvalue":1}'

Wrapping Up

This guide has provided a detailed walkthrough for deploying, configuring, and managing Domoticz. By following the provided steps, you can leverage Domoticz’s powerful features to create a highly customized and secure home automation setup. Dive into the examples, explore the API, and enjoy full control over your smart home environment.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.