Processing smart socket measurements with Zabbix
After installing the Tasmota Firmware on my smart socket, it is time to process the measurement results by some application. At home I am using Zabbix, wich has goot graphing possibilities, can be used to set up triggers for specific events, and has a documented API, to retrieve historic data.
In this post I will show how to add the energy monitoring measurements to Zabbix.
First you have to create a host in Zabbix for "hosting" the measurements, you can do that on the admin interface. On the Configuration/Hosts screen select Create Host.
When the data is already coming, you can check that in Zabbix/Monitoring/Latest Data.
In this post I will show how to add the energy monitoring measurements to Zabbix.
First you have to create a host in Zabbix for "hosting" the measurements, you can do that on the admin interface. On the Configuration/Hosts screen select Create Host.
When you are done with it, on the Configiration/Hosts screen, select the items for this host, and create a new item:
When this is done, then you are ready on the Zabbix side.
Next step is to get the measurement from the smart socket and push it into Zabbix. As I have most experience with PHP I have written a small PHP script and called it every minute from cron.
To get the values, I used a http request, according the Tasmota command line documentation, I have to use:
http://tasmota_ip/cm?cmnd=status 8
to get the actual power monitoring values. This return JSON formatted data, which I can process with the json_decode PHP function. The result will look the following:
stdClass Object
(
[StatusSNS] => stdClass Object
(
[Time] => 2020-03-02T17:39:17
[ENERGY] => stdClass Object
(
[TotalStartTime] => 2020-02-22T20:23:36
[Total] => 18.319
[Yesterday] => 3.844
[Today] => 2.654
[Power] => 156
[ApparentPower] => 176
[ReactivePower] => 81
[Factor] => 0.89
[Voltage] => 232
[Current] => 0.76
)
)
)
At the moment I need only two values: Power and Total.
I store the actual power consumption every minute, and store the hourly energy consumption every hour. To calculate the hourly energy consumption, in Zabbix for the energy item, you have to set: Store value - Delta (simple).
To submit the actual power consumption to Zabbix, I use the following script:
$json=file_get_contents("http://aram_mosokonyha.laco.hu/cm?cmnd=status%208");
$result=json_decode($json);
if ($result==NULL) exit;
#print_r($result);
$watt=$result->StatusSNS->ENERGY->Power;
exec("zabbix_sender -z boss.laco.hu -p 10051 -s power -k power.computers -o '$watth'");
To add it to cron, and execute it every minute and every hour:
crontab -e
then add
* * * * * php path_to_script_power.php
0 * * * * php path_to_script_energy.php
Comments