Pagina 3 di 7

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 16/05/2018, 11:42
da Flane

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 19/05/2018, 17:55
da Flane
Ho integrato un pò lo script per importare i dati di 123Solar in Domoticz, cercando di generalizzarlo per importare le misure che si desiderano fra quelle presenti ed inserendo alcuni minimali controlli.

Questo è lo script /var/www/comapps/123todomoticz.php

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&param=udevice&idx=$idx&nvalue=$nvalue&svalue=$svalue"));
}

?>


Ho cercato di commentarlo per renderlo più comprensibile, inserendo anche una tabellina con tipo e sottotipo dei virtual sensor da utilizzare in Domoticz.
Mi rimane solo il dubbio di che virtual sensor si devono utilizzare in domoticz per importare frequenza, riso e ileak.

Nella parte iniziale dello script è necessario inserire l'IDX assegnato da Domoticz per le varie grandezze che si intendono importare.
Lasciando IDX=0 quella grandezza non verrà inviata a Domoticz

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 22/05/2018, 20:48
da s_p
io per l'isolamento e frequenza ho usato un custom sensor e inserito il teso dell'unità di misura, per la ileak ho messo Ampere

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 23/05/2018, 10:19
da Albertol
Correggo quanto ho detto qualche post fa.

Per leggere correttamente i valori di potenza e produzione ho capito che non si deve formattare il dato, altrimenti la lettura non risulta corretta (ho provato in tutti i modi, ma non c'è nulla da fare).

Per legere correttamente importo i dati in questo modo:
G1P1 non formatto il dato e in domoticz vedo ad esempio: 827,296 Watt (mi sarebbe piaciuto non vedere i decimali, ma non ce l'ho fatta)
KWHT1 non formatto il dato, ma lo moltiplico x 1000, e leggo: 1.33 KWh

I dati li visualizzo con "Genegal, KWh" inviandoli così:
curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=40&nvalue=0&svalue=$I6; $I11"));

In questo modo i dati dei grafici di domoticz sono corretti.

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 23/05/2018, 11:16
da Flane
se vuoi tagliare i decimali utilizza il comando round

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 30/05/2018, 19:04
da s_p
@flane

ho notato che il picco giornaliero rilevato da peakotd1 non è lo stesso rilevato dalla massima potenza istantanea rilevata da 123solar.
Nello specifico, controllando 123_MEMORY.json è la seconda variabile pmotdl a riportare la massima potenza instantanea.
Che differenza c'è tra peakotd1 e pmotdl?

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 30/05/2018, 22:54
da Flane
Sinceramente non ho mai avuto ne l'interesse ne la necessità di approfondire questo aspetto, ma credo che uno sia il picco massimo giornaliero mentre l'altro il picco massimo assoluto.

Ma qui siamo OFF TOPIC

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 14/01/2019, 0:29
da manuel
Ciao,vorrei leggere i dati di produzione e consumo in domoticz ma trovo esempi che non riesco a mettere in pratica.Qualche consiglio o guida comprensibile a un neofita?
grazie

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 19/01/2019, 19:25
da manuel
ho provato a modificare lo script di Flane per leggere i valori in METERN ma molto probabilmente ho commesso errori visto che domoticz non legge nessun valore nei meter.
I passaggi che ho fatto sono quelli descritti nello script,ho controllato proprietatio (www-data) e permessi (chmod 755) e dovrebbero essere in ordine.
Bisogna dare dei comandi particolari per far partire lo script o basta inserirlo in crontab e fare il reboot ?

Sapete dirmi con quali comandi posso controllare se sta funzionando e magari si blocca in qualche passaggio?
grazie


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&param=udevice&idx=$idx$
}

?>



Immagine

Re: import dati 123solar e metern in domoticz [GUIDA]

Inviato: 27/11/2019, 10:57
da s_p
buongiorno

ho notato che in domoticz non venivano più riportati i dati del file mN_MEMORY.json, allora aprendolo ho visto che è cambiato qualcosa

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}


mentre prima c'era Totalconter1, Totalconter2, etc etc

i dati li importavo con queste righe

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&param=udevice&idx=50&svalue=$T1"));
    curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=51&svalue=$T2"));
    curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=52&svalue=$T3"));
    curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=53&svalue=$T4"));
    curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=54&svalue=$T5"));
    curl_exec(curl_init("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=55&svalue=$T6"));



ma ora come li riconosco i valori da prendere e gli altri in mN_MEMORY.json cosa sono?


EDIT

ho risolto per le letture modificando Totalconter con First, ma continuo a non capire cosa significhi Last e msgflag