Re: import dati 123solar e metern in domoticz [GUIDA]
Inviato: 20/04/2020, 13:51
Grazie mille febpro,
con il tuo suggerimento ho risolto e ora funziona anche a me!
con il tuo suggerimento ho risolto e ora funziona anche a me!
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/
Flane ha scritto:Se non si ha la necessità di avere un aggiornamento ogni minuto, questo comporta solo delle inutili scritture sulla scheda SD da parte di Domoticz che porta alla corruzione della Scheda SD .....
Codice: Seleziona tutto
#!/usr/bin/php
<?php
// API Interface script between 123solar from Jean-Marc Louviaux and Domoticz
//
// /var/www/comapps/mNtodomoticz.php
//
// script will provide multiple solar inverters with multiple strings
// see the remarks in the script for adjusting
//
// Autor: 2021-05-05 StepSolar
//
// create symlink:
// ln -s /var/www/comapps/mNtodomoticz.php /usr/local/bin/mNtodomoticz
//
// put this in the crontab on the Domoticz host:
// */5 * * * * root /usr/local/bin/mNtodomoticz >/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 Domoticx 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
$IDX[0] = 32; // produzion Produzione1 IDX[0] I[0] Usage Electric
$IDX[1] = 0; // consumi Consumi2 IDX[1] I[1] Usage Electric
$IDX[2] = 0; // prelievi Prelievi3 IDX[2] I[2] Usage Electric
$IDX[3] = 0; // immissioni Immissioni4 IDX[3] I[3] Usage Electric
$IDX[4] = 0; // autoconsumo Autoconsumo5 IDX[4] I[4] 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/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://127.0.0.1:8080/json.htm?type=command¶m=udevice&idx=$idx&nvalue=$nvalue&svalue=$svalue"));
}
?>
Codice: Seleziona tutto
// 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);
Codice: Seleziona tutto
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
php /var/www/MyScripts/live.php >/dev/null 2>&1
fi
exit 0