Re: import dati 123solar e metern in domoticz [GUIDA]
Inviato: 16/05/2018, 11:42
Forse questo può essere d'aiuto
https://www.domoticz.com/wiki/Domoticz_ ... counter.29
https://www.domoticz.com/wiki/Domoticz_ ... counter.29
Il Forum NON UFFICIALE per raccogliere le novità riguardo ai software 123Solar e MeterN per il monitoraggio energetico e non solo ....
https://www.flanesi.it:443/forum/
Codice: Seleziona tutto
#!/usr/bin/php
<?php
// API Interface script between 123solar from Jean-Marc Louviaux and Domoticz
//
// /var/www/comapps/123todomoticz.php
//
// script will provide multiple solar inverters with multiple strings
// see the remarks in the script for adjusting
//
// Autor: 2018-05-18 Flavio Anesi
//
// create symlink:
// ln -s /var/www/comapps/123todomoticz.php /usr/local/bin/123todomoticz
//
// put this in the crontab on the Domoticz host:
// */5 * * * * /usr/local/bin/123todomoticz >/dev/null 2>&1
/*
* Imposta IDX Domoticz
*
* Impostare di seguito l'IDX delle varie misure che si intendono inviare a DOMOTICZ
* l'IDX viene assegnato da Domoticz con la creazione del Virtual Sensor
* Inserire quindi l'IDX assegnato da Domoticz al relativo dispositivo
* o lasciare 0 se non si intende utilizzare la misura
* Nei commenti seguenti trovate anche il tipo e subtipo di sensore da utilizzare in Domoticz per ogni misura
*/
// NOME JSON IDX Value Type Subtype Data
$IDX[0] = 0; // tensione stringa 1 I1V1 IDX[0] I[0] General Voltage 170.000 V
$IDX[1] = 0; // corrente stringa 1 I1A1 IDX[1] I[1] General Current 0.600 A
$IDX[2] = 0; // potenza stringa 1 I1P1 IDX[2] I[2] Usage Electric 100.5 W
$IDX[3] = 0; // tensione stringa 2 I2V1 IDX[3] I[3] General Voltage 170.000 V
$IDX[4] = 0; // corrente stringa 2 I2A1 IDX[4] I[4] General Current 0.600 A
$IDX[5] = 0; // potenza stringa 2 I2P1 IDX[5] I[5] Usage Electric 100.5 W
$IDX[6] = 0; // tensione stringa 3 I3V1 IDX[6] I[6] General Voltage 170.000 V
$IDX[7] = 0; // corrente stringa 3 I3A1 IDX[7] I[7] General Current 0.600 A
$IDX[8] = 0; // potenza stringa 3 I3P1 IDX[8] I[8] Usage Electric 100.5 W
$IDX[9] = 0; // tensione stringa 4 I4V1 IDX[9] I[9] General Voltage 170.000 V
$IDX[10] = 0; // corrente stringa 4 I4A1 IDX[10] I[10] General Current 0.600 A
$IDX[11] = 0; // potenza stringa 4 I4P1 IDX[11] I[11] Usage Electric 100.5 W
$IDX[12] = 0; // tensione rete inv. 1 G1V1 IDX[12] I[12] General Voltage 231.400 V
$IDX[13] = 0; // corrente rete inv. 1 G1A1 IDX[13] I[13] General Current 0.400 A
$IDX[14] = 29; // potenza rete inv. 1 G1P1 IDX[14] I[14] Usage Electric 72.2 W
$IDX[15] = 0; // tensione rete inv. 2 G2V1 IDX[15] I[15] General Voltage 232.500 V
$IDX[16] = 0; // corrente rete inv. 2 G2A1 IDX[16] I[16] General Current 0.600 A
$IDX[17] = 0; // potenza rete inv. 2 G2P1 IDX[17] I[17] Usage Electric 76.4 W
$IDX[18] = 0; // tensione rete inv. 3 G3V1 IDX[18] I[18] General Voltage 0.000 V
$IDX[19] = 0; // corrente rete inv. 3 G3A1 IDX[19] I[19] General Current 0.000 A
$IDX[20] = 0; // potenza rete inv. 3 G3P1 IDX[20] I[20] Usage Electric 0.0 W
$IDX[21] = 0; // frequenza inverter FRQ1 IDX[21] I[21]
$IDX[22] = 0; // efficacia inverter EFF1 IDX[22] I[22] General Percentage 81.50 %
$IDX[23] = 0; // temperatura inverter INVT1 IDX[23] I[23] Temperature 36.4 C
$IDX[24] = 0; // temp. boot inverter BOOT1 IDX[24] I[24] Temperature 32.0 C
$IDX[25] = 30; // prod. tot. inverter 1 KWHT1 IDX[25] I[25] General kWh 12769.77 kWh
$IDX[26] = 0; // Resist. isol. Riso AWriso1 IDX[26] I[26] 20.00 MOhm
$IDX[27] = 0; // iLeak AWileak1 IDX[27] I[27] 0.00 mA
$IDX[28] = 31; // picco prod. del giorno peakotd1 IDX[28] I[28] Usage Electric 3046.8 W
$IDX[29] = 32; // picco prod. massima peakoat1 IDX[29] I[29] Usage Electric 3308.8 W
/*
*
* DA QUI IN POI NON SONO NECESSARIE MODIFICHE
*
*/
// IMPOSTAZIONI LETTURA JSON
$url_inv = '/dev/shm/123s_LIVEMEMORY.json';
$url_inv1 = '/dev/shm/123s_MEMORY.json';
if (file_exists($url_inv)) {
$json_inv = json_decode((file_get_contents($url_inv)), true);
} else { // 123s ain't running
die("Abording: Empty SHM\n");
}
if (file_exists($url_inv1)) {
$json_inv1 = json_decode((file_get_contents($url_inv1)), true);
} else { // 123s ain't running
die("Abording: Empty SHM\n");
}
// LETTURA DATI
$I[0] = number_format($json_inv['I1V1'], 1);
$I[1] = number_format($json_inv['I1A1'], 2);
$I[2] = number_format($json_inv['I1P1'], 0);
$I[3] = number_format($json_inv['I2V1'], 1);
$I[4] = number_format($json_inv['I2A1'], 2);
$I[5] = number_format($json_inv['I2P1'], 0);
$I[6] = number_format($json_inv['I3V1'], 1);
$I[7] = number_format($json_inv['I3A1'], 2);
$I[8] = number_format($json_inv['I3P1'], 0);
$I[9] = number_format($json_inv['I4V1'], 1);
$I[10] = number_format($json_inv['I4A1'], 2);
$I[11] = number_format($json_inv['I4P1'], 0);
$I[12] = number_format($json_inv['G1V1'], 1);
$I[13] = number_format($json_inv['G1A1'], 2);
$I[14] = number_format($json_inv['G1P1'], 0, ',', '.');
$I[15] = number_format($json_inv['G2V1'], 1);
$I[16] = number_format($json_inv['G2A1'], 2);
$I[17] = number_format($json_inv['G2P1'], 0, ',', '.');
$I[18] = number_format($json_inv['G3V1'], 1);
$I[19] = number_format($json_inv['G3A1'], 2);
$I[20] = number_format($json_inv['G3P1'], 0, ',', '.');
$I[21] = number_format($json_inv['FRQ1'], 2);
$I[22] = number_format($json_inv['EFF1'], 1);
$I[23] = number_format($json_inv['INVT1'], 1);
$I[24] = number_format($json_inv['BOOT1'], 1);
$I[25] = number_format($json_inv['KWHT1'], 1);
$I[26] = number_format($json_inv1['AWriso1'], 1);
$I[27] = number_format($json_inv1['AWileak1'], 2);
$I[28] = number_format($json_inv1['peakotd1'], 1);
$I[29] = number_format($json_inv1['peakoat1'], 1);
// VERIFICA LETTURE
if (empty($I[25]) || $I[25] == 0) { // 123s ain't running at night retrieve the value in csv
$dir = '/var/www/123solar/data/invt1/csv';
$output = glob($dir . '/*.csv');
sort($output);
$xdays = count($output);
if ($xdays > 0) {
$lastlog = $output[$xdays - 1];
$lines = file($lastlog);
$contalines = count($lines);
$array_last = preg_split('/,/', $lines[$contalines - 1]);
$I[25] = round(($array_last[27] * 1000), 0); //in Wh
} else {
$I[25] = null;
}
}
// INVIO DATI A DOMOTICZ
$input = count($IDX);
for ($i=0; $i<$input; $i++) {
if ($IDX[$i] != 0 ){
echo $i;
udevice($IDX[$i],0,$I[$i]);
}
}
// Function INVIO DATI
function udevice($idx,$nvalue,$svalue) {
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=$idx&nvalue=$nvalue&svalue=$svalue"));
}
?>
Codice: Seleziona tutto
#!/usr/bin/php
<?php
// API Interface script between 123solar from Jean-Marc Louviaux and Domoticz
//
// /var/www/comapps/meternDOMO.php
//
//
// scrip per lettura valori in metern
//
// Autor:
//
// create symlink:
// ln -s /var/www/comapps/meternDOMO.php /usr/local/bin/meternDOMO
//
// put this in the crontab on the Domoticz host:
// */5 * * * * /usr/local/bin/meternDOMO >/dev/null 2>&1
/*
* Imposta IDX Domoticz
*
* Impostare di seguito l'IDX delle varie misure che si intendono inviare a DOMOTICZ
* l'IDX viene assegnato da Domoticz con la creazione del Virtual Sensor
* Inserire quindi l'IDX assegnato da Domoticz al relativo dispositivo
* o lasciare 0 se non si intende utilizzare la misura
* Nei commenti seguenti trovate anche il tipo e subtipo di sensore da utilizzare in Domotic$
*/
// NOME JSON IDX Value Type Subtype $
$IDX[0] = 2; // produzion Produzione1 IDX[2] I[2] Usage Eletric $
$IDX[1] = 3; // consumi Consumi2 IDX[3] I[3] Usage Electric$
$IDX[2] = 4; // prelievi Prelievi3 IDX[4] I[4] Usage Electric$
$IDX[3] = 5; // immissioni Immissioni4 IDX[5] I[5] Usage Electric$
$IDX[4] = 6; // autoconsumo Autoconsumo5 IDX[6] I[6] Usage Electric
/*
*
* DA QUI IN POI NON SONO NECESSARIE MODIFICHE
*
*/
// IMPOSTAZIONI LETTURA JSON
$url_inv = '/dev/shm/mN_LIVEMEMORY.json';
$url_inv1 = '/dev/shm/mN_MEMORY.json';
if (file_exists($url_inv)) {
$json_inv = json_decode((file_get_contents($url_inv)), true);
} else { // meter ain't running
die("Abording: Empty SHM\n");
}
if (file_exists($url_inv1)) {
$json_inv1 = json_decode((file_get_contents($url_inv1)), true);
} else { // meter ain't running
die("Abording: Empty SHM\n");
}
// LETTURA DATI
$I[0] = number_format($json_inv['Produzione1'], 2);
$I[1] = number_format($json_inv['Consumi2'], 2);
$I[2] = number_format($json_inv['Prelievi3'], 2);
$I[3] = number_format($json_inv['Immissioni4'], 2);
$I[4] = number_format($json_inv['Autoconsumo5'], 2);
// VERIFICA LETTURE
if (empty($I[4]) || $I[4] == 0) { // meter ain't running at night retrieve the value in csv
$dir = '/var/www/metern/data/invt1/csv';
$output = glob($dir . '/*.csv');
sort($output);
$xdays = count($output);
if ($xdays > 0) {
$lastlog = $output[$xdays - 1];
$lines = file($lastlog);
$contalines = count($lines);
$array_last = preg_split('/,/', $lines[$contalines - 1]);
$I[4] = round(($array_last[5] * 1000), 0); //in Wh
} else {
$I[4] = null;
}
}
// INVIO DATI A DOMOTICZ
$input = count($IDX);
for ($i=0; $i<$input; $i++) {
if ($IDX[$i] != 0 ){
echo $i;
udevice($IDX[$i],0,$I[$i]);
}
}
// Function INVIO DATI
function udevice($idx,$nvalue,$svalue) {
curl_exec(curl_init("http://192.168.178.1:8080/json.htm?type=command¶m=udevice&idx=$idx$
}
?>
Codice: Seleziona tutto
{"msgflag1":true,"First1":52393024,"Last1":52397957,"msgflag2":false,"First2":23602432,"Last2":23613530,"msgflag3":true,"First3":4755692,"Last3":4764166,"msgflag4":false,"First4":5549113,"Last4":5551398,"msgflag5":false,"First5":1981161,"Last5":1983818,"msgflag6":false,"First6":9431765,"Last6":9436657,"msgflag7":false,"First7":18619186,"Last7":18625492,"5minflag":false}
Codice: Seleziona tutto
//
// T O T A L I Z Z A T O R I
// Memory (/dev/shm/mN_MEMORY.json)
//
// Totalcounter1 produzione T1
// Totalcounter2 consumi T2
// Totalcounter3 prelievi T3
// Totalcounter4 immissioni T4
// Totalcounter5 autoconsumo T5
// Totalcounter6 pompa di calore T6
//
// IMPOSTAZIONI LETTURA JSON
$url_tot = '/dev/shm/mN_MEMORY.json';
$json_tot = json_decode((file_get_contents($url_tot)), true);
// LETTURA DATI
$T1 = $json_tot['Totalcounter1'];
$T2 = $json_tot['Totalcounter2'];
$T3 = $json_tot['Totalcounter3'];
$T4 = $json_tot['Totalcounter4'];
$T5 = $json_tot['Totalcounter5'];
$T6 = $json_tot['Totalcounter6'];
// ARROTONDA A 2 CIFRE DECIMALI
//$T1 = number_format($T1, 1, ',', '.'); // con 1 arrotonda a 1 cifra decimale
// INVIO DATI A DOMOTICZ
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=50&svalue=$T1"));
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=51&svalue=$T2"));
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=52&svalue=$T3"));
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=53&svalue=$T4"));
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=54&svalue=$T5"));
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=55&svalue=$T6"));