This project is describing the porting of the P1-Monitor software running on Raspberry Pi to a container version to be able to run it on any Operating System. The original software is maintained by
Since I’m running a Linux server already I didn’t want to start using a dedicated Raspberry Pi board for monitoring my smart meter. But the software provided by ZTATZ is only available as a complete system image running on a Raspberry Pi. That’s why I started converting that software to a container version suitable for running on any system with the help of docker, docker-compose, portainer or any system.
You can find the container version on Docker hub and I’m using GitHub to maintain the repository. The container version has the same functionality as the full version (although some options related to Operating System are not being used of course). Docker hub also holds the versions for other architectures so you can also run the container on ARM etc (such as Raspberry Pi).
Since I’m not using a serial port anymore (who does?) I’m using a standard USB to serial adaptor and I changed a standard phone cable (for the RJ11 connector in the Smart meter) and connected it to the serial as below. Of course its even more easy to buy a standard ‘Smart meter USB cable‘ for 15 euro or so but it was weekend and I needed the cable now 🙂
|PIN nummer P1 poort||RJ-11||RS-232|
To start with docker-compose create a new directory and create a file named docker-compose.yml. Copy the contents of below docker-compose file example to that file and save it. If needed you can modify it using your own parameters such as the location of the data (in the example script in the subdirectory alldata). That subdirectory is for creating persistence; if the container is recreated or an update is available all data is preserved since it is being stored outside the container. If your server is being rebooted the container will automatically be started again.
Next you start your containerised P1-Monitor using the docker-compose up -d command. This way a small local network will be created and the container will be started in the background. After a short while (initially the container image needs to be downloaded from Docker hub) the P1-Monitor will be available on selected port. In below example it will be running on standard port 80 but you can easily change that by modifying the port mapping parameter from 80:80 to for instance 81:80 if you want the container to be available at port 81.
Similar is the devices section; it is mapping your local serial device to /dev/ttyUSB0 in the container
Docker-compose file example
version: '3.8' services: p1monitor: hostname: p1mon image: mclaassen/p1mon ports: - 80:80 volumes: - ./alldata/data:/p1mon/data - ./alldata/usbdisk:/p1mon/mnt/usb - ./alldata/mnt/ramdisk:/p1mon/mnt/ramdisk tmpfs: - /run - /tmp devices: - "/dev/ttyUSB0:/dev/ttyUSB0" restart: unless-stopped
Upgrade to latest version
If a new container is released (usually shortly after the original P1-Monitor software has been updated) you can stop the container instance using the docker-compose down command. Do not delete any files but issue the command docker-compose pull to retrieve the latest image from Docker hub. After the pull is complete start the container again using the docker-compose up command. All historic data will be reused (if you do not change the docker-compose configuration file of course).
Migrate from original P1-Monitor instance
To migrate from the original P1-Monitor (the one you had running on the dedicated Raspberry Pi) it is easiest to export the data. To do so use the menu Settings (Instellingen) and select In- Export. In your new instance use the same menu to import the extracted data again.
The docker-compose file supports below parameters:
mapping van ports from outside to inside. If you want to use port 81 to access your instance use the setting 81:80
these are the directories being used to store the persistent data. In the example above subdirectory alldata will be automatically created (if started for the first time) and all collected information will be stored here.
mapping of your external to internal serial device. Adjustment is only needed in case you are using a different USB port on your host system.
Extra docker-compose parameters
Additional parameters can be passed to the container using the option environment. As example in above configuration adding the parameter DISABLECPUTEMP would be:
tmpfs: - /run - /tmp devices: - "/dev/ttyUSB0:/dev/ttyUSB0" restart: unless-stopped environment: - DISABLECPUTEMP=true - PROXYPATH=p1mon
On certain Operating Systems the CPU temperature is not available causing the WatchDog script to crash. Adding parameter DISABLECPUTEMP=true will disable this option. Default value of this option is set to false
Since I would like access to the data also when not at home I added a reverse proxy option. By adding parameter PROXYPATH=p1mon the configuration in the container is adjusted so you can use the subdirectory p1mon as a path in your url. Your outside url would be something like https://myhomenetwork.nl/p1mon.
Don’t forget to protect your reverse proxy (e.g. username/password) as the P1-Monitor version is not build to be internet facing.
Using a ramdisk
The original software of P1 Monitor is using a ramdisk for writing to the databases. Reason is to avoid to many write actions to the SD cards (as they can become corrupted or something). Every now and then data from ramdisk is written to the filesystem. When running on a Linux server that is not a real issue as the file IO is not that much. If you still want to use a ramdisk you can use below modification in the docker-compose file. Remove the ramdisk from the volumes section and add it to the tmpfs section as shown below:
version: '3.8' services: p1monitor: hostname: p1mon image: mclaassen/p1mon ports: - 81:80 volumes: - ./alldata/data:/p1mon/data - ./alldata/usbdisk:/p1mon/mnt/usb tmpfs: - /run - /tmp - /p1mon/mnt/ramdisk devices: - "/dev/ttyUSB0:/dev/ttyUSB0" restart: unless-stopped
This is the list of changes for the different container versions. the latest tag (if you omit the tag latest will be used) will take you to the newest version. If you would like to use a different version add it to the image tag in the compose file. E.g. If you want use container version 1.4.1b modify the image tag to mclaassen/p1mon:1.4.1b
Updates to latest released version 1.5.0
Changed to running as p1mon, fixed issues, updated vulnerable packages
Fixed issue tariff status as described by author
Based on the 1.4.1 image of ZTATZ. Also added reverse proxy capability
Based on the withdrawn image of ZTATZ. Fixed 1 second issue. Image was withdrawn by the original author but due to the nature of docker container most bugs are not applicable here.
Fixed temperature error in VM using environment variable. Modified cron
Fixed import/export functions as well as missing ping utility
added health check function. Container will show health status and restart on failure
Updates fixing some vulnerabilities in python packages and dpkg
Update to latest released version 1.3.1
Update to latest released version 1.3.0
Initial released version 1.2.0