SHELLY PM Mini Gen3 GATEWAY TO ZABBIX SERVER
GATEWAY FEATURES:
The Gateway is designed to transfer data from the SHELLY PM Mini Gen3 controller to the ZABBIX system by querying this meter every minute and saving the downloaded data results on the ZABBIX server. Additionally, the energy consumption is recorded in a daily cycle.
Importantly, there is no need to reprogram the meter.
The Gateway can be run on any computer with Linux. It can be the same computer on which your own instance of the SUPLA server is running or any version of a Raspberry microcomputer (even nanoPi). The tests were conducted on a VPS with the Debian system, on which the SUPLA, ZABBIX, GRAFANA servers are running, and on the NanoPi microcomputer.
GATEWAY – INSTALLATION:
1. For the script to work correctly, follow the instructions below:
sudo apt-get update
sudo apt-get install bc
sudo apt-get install jq
sudo apt-get install zabbix-agent
2. Download the file Shelly_PM_Mini.zip from the address:
https://djack.com.pl/modules.php?name=Downloads&d_op=getit&lid=357
The packed file also contains a template file to import to the Zabbix server, for the Shelly PM Mini meter
(Shelly_PM_Mini_templates.yaml)
3. After unpacking, copy the Shelly_PM_Mini.sh file to the /usr/bin directory
4. Assign the appropriate attributes:
sudo chmod a+rwx /usr/bin/Shelly_PM_Mini.sh
GATEWAY CONFIGURATION:
1. Open the Shelly_PM_Mini.sh script in a regular editor (vi, nano).
At the beginning of the script there are lines in which you should enter the described parameters:
#==========================================
#== Zabbix server IP address =======================
ZABBIX_SERVER="xxx.xxx.xxx.xxx"
#==========================================
#== Host name on Zabbix server =====================
HOST="shelly1pm"
#==========================================
#== Shelly PM Mini Controller IP Address ================
SHELLY_IP="zzz.zzz.zzz.zzz"
#==========================================
The Zabbix server IP address can be specified as an absolute address or as a domain name.
The hostname can be anything (matches the name specified on the Zabbix server). In the above example it is "shelly1pm".
The IP address of the Shelly controller will most often be given as an absolute address because it is on the local network.
2. We execute the command:
crontab –e
and enter the line:
*/1 * * * * Shelly_PM_Mini.sh > /dev/null 2>&1
The script is executed every minute.
If you have more drivers, you can duplicate the script code in one file or copy the script file and change its name.
In such a case it is good to run scripts in cron with a delay:
*/1 * * * * Shelly_PM_Mini.sh > /dev/null 2>&1
*/1 * * * * (sleep 10; Shelly_PM_Mini1.sh > /dev/null 2>&1)
*/1 * * * * (sleep 20; Shelly_PM_Mini2.sh > /dev/null 2>&1)
*/1 * * * * (sleep 30; Shelly_PM_Mini3.sh > /dev/null 2>&1)
*/1 * * * * (sleep 40; Shelly_PM_Mini4.sh > /dev/null 2>&1)
.....
Drivers with firmware supporting reporting to Zabbix server send information about state changes almost immediately, while
in case of gateway it may be with a delay of max 1 minute.
Therefore, when you need to log data more frequently than every 1 minute (e.g. every 10 seconds), you can use the following construct:
*/1 * * * * Shelly_PM_Mini.sh > /dev/null 2>&1
*/1 * * * * (sleep 10; Shelly_PM_Mini.sh > /dev/null 2>&1)
*/1 * * * * (sleep 20; Shelly_PM_Mini.sh > /dev/null 2>&1)
*/1 * * * * (sleep 30; Shelly_PM_Mini.sh > /dev/null 2>&1)
*/1 * * * * (sleep 40; Shelly_PM_Mini.sh > /dev/null 2>&1)
*/1 * * * * (sleep 50; Shelly_PM_Mini.sh > /dev/null 2>&1)
.....
DATA REGISTERED ON THE ZABBIX:
Gateway SERVER reports data in real time (every 1 minute).
The first daily energy consumption will appear in the data list the day after the first script run.
The system can send notifications (PUSH, email) according to any criteria you specify.
Example screens in Zabbix system:
Fig.1
Fig.2
|