P1 Energy Meter for Domoticz

Step-by-step how-to guide connect the P1 Landis+Gyr Energy meter, on a Raspberry Pi 4, with the latest Raspbian Buster image and Domoticz.

This how-to is part of a bigger series of Domoticz how-to’s on sancla.com!

Until recently most Dutch household’s where provided with an old analog energy meter, for electricity and natural gas. These meters have been replaced in recent years (per designation of Dutch law) with a new generation P1 smart energy meters. Apart from the fact that the energy companies can now remotely read out the meters, they are also equipped with a local data port. This port can be utilized to constantly monitor these energy-meters including the meter values.

In this how-to we are going to connect this smart meter to our Raspberry Pi based Domoticz installation.

This tutorial has been verified with:
Domoticz 2020.1

Prerequisites

Tested with

  • Raspbian Buster Lite 4.19, Februari 2020
  • Domoticz Stable 2020.1 (compile date 22-3-2020)
  • TFDI FT232RL based USB to serial to RJ11 cable (P1 cable)

USB to serial to RJ11 cable

Our Chinese friends are well versed in preparing and making P1 cable solutions that also work well in combination with Domoticz. Under prerequisites are 2 links included with which you can order them ready-made. Also, these cables can often be ordered well through European web shops with a shorting shipping time (but often the price is higher).

For this post I ordered a cable from China and took it apart for you, so that you can see for yourself how they work. That way you can save even more costs by ordering the parts separately in China and assembling them yourself.

Configuring the P1 Smart Meter

Once you have the right cable, you can hook it up to your energy meter and Domoticz. After this, configure the new hardware device as follows:

  • Enabled: Enabled
  • Name: P1 Energy Meter
  • Type: P1 Smart Meter USB
  • Data Timeout: Disabled
  • Serial Port: Select your USB to serial adapter, in this case the TFDI FT232RL chip based adapter
  • Baudrate: 115200 bits per second (baud)
  • CRC message validation: Enabled
  • Rate Limit: empty
Configure the P1 hardware in Domoticz
Configure the P1 hardware in Domoticz

It can take a while for all devices to become visible in Domoticz, as these devices will only receive an update if the value in the meter changes. For example the gas meter, it will often take a while before it becomes visible. Certainly in the summer, when gas consumption is low, this can take some time.

P1 devices appear in Domoticz
P1 devices appear in Domoticz

READ MORE

Backup Domoticz with Duplicati

Step-by-step how-to guide install and configure Duplicati with the latest Raspbian Buster image and Domoticz.

Duplicati is a fantastic and very intuitive backup solution that support a wide range of backup targets. Combined with a webinterface, this makes it perfect for a backup solution for our beloved Domoticz installation.

Duplicati supports not only various online backup services like OneDrive, Amazon S3, Backblaze, Rackspace Cloud Files, Tahoe LAFS, and Google Drive, but also any servers that support SSH/SFTP, WebDAV, or FTP.

It does however need the mono framework as it is mainly written for the Windows platform and this makes it a bit heavy for Linux. Nonetheless, it’s one of my favorite open-source backup products.

Tip: Duplicati is more about making a backup of the most important files. If you are looking for a complete system backup solution, perhaps this is more what you are looking for:
https://www.hackviking.com/single-board-computers/raspberry-pi/automated-raspberry-pi-backup-complete-image/

This how-to is part of a bigger series of Domoticz how-to’s on sancla.com!

This tutorial has been verified with:
Domoticz 2020.1

Prerequisites

Tested with

  • Raspberry Pi 4 (MEM 2GB with 16GB sd-card)
  • Raspbian Buster Lite 4.19, Februari 2020
  • Domoticz Stable 2020.1 (compile date 22-3-2020)
  • Duplicati BETA v2.0.5.1-2.0.5.1_beta_2020-01-18

Step 1: Install the Mono Framework

This step can take a bit of time…

sudo apt install mono-complete ca-certificates-mono -y

Step 2: Sync the certificates

sudo cert-sync /etc/ssl/certs/ca-certificates.crt

Step 3: Install Duplicati

wget https://github.com/duplicati/duplicati/releases/download/v2.0.5.1-2.0.5.1_beta_2020-01-18/duplicati_2.0.5.1-1_all.deb
sudo apt-get install ./duplicati_2.0.5.1-1_all.deb -y

Step 4: Install missing dependencies

Sometimes Raspbian is still missing some required dependencies.
Just to be sure, run the following command so we are not missing out on any:

sudo apt -f install -y

Step 5: Configure the service file

We need to edit the service file in order to make it possible to run this as a service. So go open the file with the nano text editor with the following command:

sudo nano /etc/systemd/system/duplicati.service 
The duplicati.service file

Copy-paste the following configuration and save the file.
To exit and save the changes, press CTRL+X first and confirm to save the file with “Y”).

[Unit]
Description=Duplicati web-server
After=network.target

[Service]
Nice=19
IOSchedulingClass=idle
EnvironmentFile=-/etc/default/duplicati
ExecStart=/usr/bin/duplicati-server $DAEMON_OPTS
Restart=always

[Install]
WantedBy=multi-user.target

Step 6: Configure the initscript file

Next is to edit the initscript file with the following command:

sudo nano /etc/default/duplicati
The duplicati initscript

It should resemble the below configuration. You have to add the last “DAEMON_OPTS…” line to the file and save the changes. To exit and save the changes, press CTRL+X first and confirm to save the file with “Y”).

# Defaults for duplicati initscript
# sourced by /etc/init.d/duplicati
# installed at /etc/default/duplicati by the maintainer scripts

#
# This is a POSIX shell fragment
#

# Additional options that are passed to the Daemon.
DAEMON_OPTS="--webservice-interface=any --webservice-port=8200 --portable-mode"

Step 7: Enable Duplicati service

Now its time to enable and start the service.
Execute the following commands:

sudo systemctl enable duplicati.service
sudo systemctl daemon-reload
sudo systemctl start duplicati.service	
sudo systemctl status duplicati.service

You should now have Duplicati up-and-running and see the below results of a running service:

Duplicati service is running correctly

Step 8: Open the Duplicati web-gui

Next is to navigate to the web interface/gui. It is configured in the initscript file to run on port 8200. In my case, the IP address of my Raspberry Pi is 10.1.3.51. So in order the reach the web gui, I have to open the following address in my browser:

http://10.1.3.51:8200
Duplicati First Run Setup

The first time you open the Duplicati interface, choose the first option “No, my machine has only a single account”.

You should now be able to configure a backup job!

A couple of tips when creating a backup job (see screenshots below for further guidance):

  • Include one of these directories:
    • /home/pi
    • /home/pi/domoticz
  • Enable automatic backup in the Domoticz setup menu so you get consistent backups of your database.
  • Keep your encryption password in a safe place that you can find back should you ever need it (or just do not use an encryption password)!!
  • You can also run scripts in advance or after the backup
  • Configure backup retention to automatically clean up old backups.
  • Enable e-mail notifications to keep track of your backups.
    See this forum post for the proper steps using Google Mail:
    https://forum.duplicati.com/t/how-to-configure-automatic-email-notifications-via-gmail-for-every-backup-job/869

Should you need to restore…

If you ever need to restore, you can do so easily by clicking on the job and selecting to restore files, as seen in the screenshot below.
Follow the steps with these instructions:

https://duplicati.readthedocs.io/en/latest/03-using-the-graphical-user-interface/#restoring-files-from-a-backup

Restore files with Duplicati
Restore files with Duplicati

Worstcase scenario

However, in the worst-case scenario, a F.U.B.A.R. situation, you don’t have a running pi anymore. For example, your SD-card or USB stick died…
First 2 steps are to get your pi running again with a fresh installation of raspbian and Domoticz. Next is to install Duplicati again the guide below. Another option is to just install Duplicati on your own system to retrieve your files. See this link for more information and instructions
https://duplicati.readthedocs.io/en/latest/03-using-the-graphical-user-interface/#restoring-files-if-your-duplicati-installation-is-lost

Further documentation

For more information on Duplicati, how to create a proper backup job and other documentation, you can visit this site:

https://duplicati.readthedocs.io/en/latest/

READ MORE

Internal Sensors for Domoticz

Step-by-step how-to guide install the Internal Sensors on Raspberry Pi with the latest Raspbian Buster image and Domoticz.

This how-to is part of a bigger series of Domoticz how-to’s on sancla.com!

As most know by now, the Raspberry Pi 4 has the reputation to run hot. Perhaps hotter then we want, even with an idle CPU with Domoticz… One way to resolve this problem is cooling this beast.

In my humble opinion, the Flirc passive cooling case has been the best accessory for the the Raspberry Pi 4 one could buy (and for only € 20,- it’s a bargin): https://www.tinytronics.nl/shop/nl/raspberry-pi/behuizingen/flirc-raspberry-pi-4-behuizing-aluminium-zwart
In this how-to we utilize this case and it has been running for over an hour at approx 40° Celsius with Domoticz, i-love-this-case!!

Flirc case for the Raspberry Pi 4
Flirc case for the Raspberry Pi 4

However, besides making sure your Raspberry Pi 4 gets proper cooling, it doesn’t hurt to monitor the temperature in Domoticz. Doing so also enables you to configure alerting if the temperature gets to high and cool down your Raspberry Pi with a big bucket of conductive water…..

This tutorial has been verified with:
Domoticz 2020.1

Prerequisites

Tested with

  • Raspberry Pi 4 (MEM 2GB with 16GB sd-card)
  • Raspbian Buster Lite 4.19, Februari 2020
  • Domoticz Stable 2020.1 (compile date 22-3-2020)

Configuring internal sensors in Domoticz

In Domoticz, go to hardware and add a new device:

  • Name: Raspberry
  • Type: Motherboard sensors
  • Data Timeout: 10 minutes
Adding the Motherboard Sensors in Domoticz
Adding the Motherboard Sensors in Domoticz

After a couple of minutes, the internal devices are starting to appear under devices. Click on the green button to enable the monitoring of the device. You can give it a any name you want, such as “Internal Temperature” for example:

Motherboard Sensor devices appearing in Domoticz
Motherboard Sensor devices appearing in Domoticz

The temperature of your Raspberry Pi is now visible in Domoticz under temperature. You can take the same steps for the other sensors should you wish to monitor them.

The internal Raspberry Pi temperature in Domoticz
The internal Raspberry Pi temperature in Domoticz with the Flirc case

As shown in above image, you can configure “Notifications” for each enabled device. So you receive a notification if your Raspberry Pi is starting to run to hot:

Configuring notifications for the internal temperature sensor in Domoticz
Configuring notifications for the internal temperature sensor in Domoticz
READ MORE