se volete si può usare anche mqtt per importare i dati da meterN in domoticz:
https://github.com/megamarco833/mqtt-meterN
viewtopic.php?f=23&t=2849
import dati 123solar e metern in domoticz [GUIDA]
-
- Messaggi: 247
- Iscritto il: 22/08/2016, 14:13
Re: import dati 123solar e metern in domoticz [GUIDA]
Zan77 ha scritto:Fatto ma non funziona.
mi fai uno screeenshot della pagina dei dispositivi?
Re: import dati 123solar e metern in domoticz [GUIDA]
forese non ripete ciclicamente la lettura con live.php
fai cosi, dopo <?php vai a capo e inserisci
while(1) {
start();
sleep(10);
}
in moda da leggere
#!/usr/bin/php
<?php
while(1) {
start();
sleep(10);
}
// L I V E
// Live (/dev/shm/mN_LIVEMEMORY.json)
// Produzione1 produzione L1
// Consumi2 consumi L2 e
etc etc..
salva e riavvia
fai cosi, dopo <?php vai a capo e inserisci
while(1) {
start();
sleep(10);
}
in moda da leggere
#!/usr/bin/php
<?php
while(1) {
start();
sleep(10);
}
// L I V E
// Live (/dev/shm/mN_LIVEMEMORY.json)
// Produzione1 produzione L1
// Consumi2 consumi L2 e
etc etc..
salva e riavvia
Re: import dati 123solar e metern in domoticz [GUIDA]
megamarco83 ha scritto:se volete si può usare anche mqtt per importare i dati da meterN in domoticz:
https://github.com/megamarco833/mqtt-meterN
viewtopic.php?f=23&t=2849
Sto cercando di adattare la tua comapps per importare i dati di metern e 123solar su domoticz.
Ti chiedo alcune info. Quando scrivi:
if (isset($_SERVER['REMOTE_ADDR'])) {
al posto di REMOTE_ADDR devo inserire l'indirizzo IP del mio MQTT Client?
es: if (isset($_SERVER['127.0.0.1'])) {
Inoltre su:
// consumi:
$svalue = "$consumiW;$cons_KWH";
$arr = array(
'idx' => $ID_cons, // Da usare un idx per ogni valore
'nvalue' => 0,
'svalue' => $svalue
);
cosa intendi con "Da usare un idx per ogni valore"?
Grazie.
-
- Messaggi: 247
- Iscritto il: 22/08/2016, 14:13
Re: import dati 123solar e metern in domoticz [GUIDA]
Zan77 ha scritto:megamarco83 ha scritto:se volete si può usare anche mqtt per importare i dati da meterN in domoticz:
https://github.com/megamarco833/mqtt-meterN
http://www.flanesi.it/forum/viewtopic.php?f=23&t=2849
Sto cercando di adattare la tua comapps per importare i dati di metern e 123solar su domoticz.
Ti chiedo alcune info. Quando scrivi:
if (isset($_SERVER['REMOTE_ADDR'])) {
al posto di REMOTE_ADDR devo inserire l'indirizzo IP del mio MQTT Client?
es: if (isset($_SERVER['127.0.0.1'])) {
ciao, no non devi toccare nulla in quella in quella parte non occoore modificarla
Zan77 ha scritto:megamarco83 ha scritto:s
Inoltre su:
// consumi:
$svalue = "$consumiW;$cons_KWH";
$arr = array(
'idx' => $ID_cons, // Da usare un idx per ogni valore
'nvalue' => 0,
'svalue' => $svalue
);
cosa intendi con "Da usare un idx per ogni valore"?
Grazie.
dalla riga 29 ci sono tutti gli idx che dovrei cambiare in base a quelli che hai in domoticz
Codice: Seleziona tutto
$ID_prod = 4;
$ID_prel = 5;
$ID_autoc = 6;
$ID_f1 = 7;
$ID_f23 = 8;
$ID_imm = 9;
$ID_cons = 10;
$ID_boiler = 130;
ad esempio questi sono quelli per
produzione
prelievi
autoconsumo
fascia di prelievi f1
fascia di prelievo f2 e f3
immissioni
ecc ecc
con "da usare per ogni valore" intendo che dovrai ricopiarti le celle che chiamano gli idx per ogni parametro che hai in metern: se in più rispetto alla mia configurazione lo aggiungi, se in meno commenti così che lo script php non esegua quella parte
esempio
se non ne hai qualcuno commenti le righe associate sia qui che nel corrispettivo richiamo che c'è sotto, ad esempio se non hai la fascia f1 e f23 farai:
Codice: Seleziona tutto
//$ID_f1 = 7;
//$ID_f23 = 8;
// prelievi f1:
// $svalue = "$f1W;$f1_KWH";
// $arr = array(
// 'idx' => $ID_f1,
// 'nvalue' => 0,
// 'svalue' => $svalue
// );
// $out = mqtt($arr);
//prelivi F23:
// $svalue = "$f23W;$f23_KWH";
// $arr = array(
// 'idx' => $ID_f23,
// 'nvalue' => 0,
// 'svalue' => $svalue
// );
// $out = mqtt($arr);
se invece vuoi passare a domoticz qualche parametro in più devi creadere prima in alto:
$ID_PARAMETRO_NUOVO = numero_del_IDX_dpomoticz;
$paramtero _KWH = $memarray_mN_MEMORY["Last8"]; //esempio per un device energia al meter n°8
$prametroW = $memarray_mN_LIVEM["PrelieviF18"]; //esempio per un device energia in W al metern n°8
// prametro nuovo:
// $svalue = "$prametroW;$paramtero _KWH";
// $arr = array(
// 'idx' => $ID_PARAMETRO_NUOVO,
// 'nvalue' => 0,
// 'svalue' => $svalue
// );
occhio che la struttura sopra dipende da cosa passi a domoticz (nell'esempio è un device energia con valore istantaneo+cumulato) in base a se passi un parametro di: energia, temperatura, temp+humid, ecc ecc
infine devi modificare la parte dei json che scrive metern con le tue configurazioni:
dalla riga 61 alla 91
Codice: Seleziona tutto
if (file_exists('/dev/shm/mN_LIVEMEMORY.json') && file_exists('/dev/shm/mN_ILIVEMEMORY.json') && file_exists('/dev/shm/mN_MEMORY.json')) {
$data_mN_LIVEM = file_get_contents('/dev/shm/mN_LIVEMEMORY.json');
$data_mN_ILIVEM = file_get_contents('/dev/shm/mN_ILIVEMEMORY.json');
$data_mN_MEMORY = file_get_contents('/dev/shm/mN_MEMORY.json');
$memarray_mN_LIVEM = json_decode($data_mN_LIVEM, true);
$memarray_mN_ILIVEM = json_decode($data_mN_ILIVEM, true);
$memarray_mN_MEMORY = json_decode($data_mN_MEMORY, true);
$prod_KWH = $memarray_mN_MEMORY["Last2"]; //Last2 = Produzione Wh
$cons_KWH = $memarray_mN_MEMORY["Last1"]; //Last1 = Consumi Wh
$consumiW = $memarray_mN_LIVEM["Consumi1"]; //Consumi1 = consumi W
$prodW = $memarray_mN_LIVEM["Produzione2"]; //Produzinoe2 = produzione W
$prel_KWH = $memarray_mN_MEMORY["Last3"]; //Last3 = Prelievi Wh
$prelW = $memarray_mN_LIVEM["Prelievi3"]; //Prelievi2 = prelievi W
$imm_KWH = $memarray_mN_MEMORY["Last4"];
$immW = $memarray_mN_LIVEM["Immissioni4"];
$auto_KWH = $memarray_mN_MEMORY["Last5"];
$autoW = $memarray_mN_LIVEM["Autoconsumo5"];
$f1_KWH = $memarray_mN_MEMORY["Last8"];
$f1W = $memarray_mN_LIVEM["PrelieviF18"];
$f23_KWH = $memarray_mN_MEMORY["Last9"];
$f23W = $memarray_mN_LIVEM["PrelieviF239"];
$boiler_KWH = $memarray_mN_MEMORY["Last12"];
$boilerW = $memarray_mN_LIVEM["Boiler12"];
$temp = $memarray_mN_LIVEM["temperatura6"];
$humi = $memarray_mN_LIVEM["Umidità7"];
$V = $memarray_mN_ILIVEM["Voltage1"]; //Voltage1 = Volt
$A = $memarray_mN_ILIVEM["Corrente2"]; //Corrente2 = Ampere
$h2o = $memarray_mN_ILIVEM["ACQUA7"] * 1000; //ACQUA7 = acqua in m3
quello che non hai lo commenti, quello che hai in più lo aggiungi e modifichi le i parametri in base ha come hai configurato metern
Re: import dati 123solar e metern in domoticz [GUIDA]
Ma quindi con un solo IDX ('idx' => $ID_prel) vedi sia i valori "live" ($prelW) che il "totale" ($prel_KWH)?
//prelievi:
$svalue = "$prelW;$prel_KWH";
$arr = array(
'idx' => $ID_prel,
'nvalue' => 0,
'svalue' => $svalue
Il tuo script lo avevo modificato così:
Ma poi ho visto che con un IDX indicavi sia i live che i tot e allora mi sono bloccato
)
//prelievi:
$svalue = "$prelW;$prel_KWH";
$arr = array(
'idx' => $ID_prel,
'nvalue' => 0,
'svalue' => $svalue
Il tuo script lo avevo modificato così:
Codice: Seleziona tutto
#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
die('Direct access not permitted');
}
// sudo chmod +x mqtt_energy.php
// sudo chown www-data\: mqtt_energy.php
// sudo ln -s /var/www/comapps/mqtt_energy.php /usr/bin/mqtt_energy
$frequenza = 10; // seconds for loop
function mqtt($arr)
{
$msg = json_encode($arr);
$CMD = "timeout --kill-after=15s 10s mosquitto_pub -d -h '127.0.0.1' -t 'domoticz/in' -m '$msg'";
exec($CMD, $output);
}
// domoticz device = dummy device type electrical: instanteo + contatore
// device type = dummy device: electrical instanteno + contatore
// device type = dummy device: type = ampere (1fase)
// device type = dummy device: type = voltaggio
$ID_Prod_live = 1; //Produzione1
$ID_Cons_live = 2; //Consumi2
$ID_Prel_live = 3; //Prelievi3
$ID_Immi_live = 4; //Immissioni4
$ID_Autoc_live = 5; //Autoconsumo5
$ID_PdC_live = 6; //Pompa calore6
$ID_Prod_tot = 7; //Last1
$ID_Cons_tot = 8; //Last2
$ID_Prel_tot = 9; //Last3
$ID_Immi_tot = 10;//Last4
$ID_Autoc_tot = 11;//Last5
$ID_PdC_tot = 12;//Last6
$ID_Tens_rete = 13;//Tensione1
$ID_Corr_rete = 14;//Corrente2
$ID_Cosfi_rete = 15;//Cos fi3
$ID_TempCPU_rete= 16;//Temp CPU4
$ID_Tens_FV = 17;//G1V1
$ID_Corr_FV = 18;//G1A1
$ID_Pot_FV = 19;//G1P1
$ID_Prodtot_FV = 20;//KWHT1
$ID_Effic_FV = 21;//EFF1
$ID_Freq_FV = 22;//FRQ1
$ID_MaxPotIst_FV= 23;//pmotd1
while (true) {
if (file_exists('/dev/shm/mN_LIVEMEMORY.json') && file_exists('/dev/shm/mN_ILIVEMEMORY.json') && file_exists('/dev/shm/mN_MEMORY.json') && file_exists('/dev/shm/123s_LIVEMEMORY.json') && file_exists('/dev/shm/123s_MEMORY.json')) {
$data_mN_LIVEM = file_get_contents('/dev/shm/mN_LIVEMEMORY.json');
$data_mN_ILIVEM = file_get_contents('/dev/shm/mN_ILIVEMEMORY.json');
$data_mN_MEMORY = file_get_contents('/dev/shm/mN_MEMORY.json');
$data_123s_LIVEM = file_get_contents('/dev/shm/123s_LIVEMEMORY.json');
$data_123s_MEMORY = file_get_contents('/dev/shm/123s_MEMORY.json');
$memarray_mN_LIVEM = json_decode($data_mN_LIVEM, true);
$memarray_mN_ILIVEM = json_decode($data_mN_ILIVEM, true);
$memarray_mN_MEMORY = json_decode($data_mN_MEMORY, true);
$memarray_123s_LIVEM = json_decode($data_123s_LIVEM, true);
$memarray_123s_MEMORY = json_decode($data_123s_MEMORY, true);
$prod_W = $memarray_mN_LIVEM["Produzione1"]; //Produzione1 = Produzione W
$consumi_W = $memarray_mN_LIVEM["Consumi2"]; //Consumi2 = Consumi W
$prel_W = $memarray_mN_LIVEM["Prelievi3"]; //Prelievi3 = Prelievi W
$imm_W = $memarray_mN_LIVEM["Immissioni4"]; //Immissioni4 = Immissioni W
$auto_W = $memarray_mN_LIVEM["Autoconsumo5"]; //Autoconsumo5 = Autoconsumo W
$pdc_W = $memarray_mN_LIVEM["Pompa calore6"];//Pompa calore6= Pompa calore W
$prod_KWH = $memarray_mN_MEMORY["Last1"]; //Last1 = Consumi Wh
$cons_KWH = $memarray_mN_MEMORY["Last2"]; //Last2 = Produzione Wh
$prel_KWH = $memarray_mN_MEMORY["Last3"]; //Last3 = Prelievi Wh
$imm_KWH = $memarray_mN_MEMORY["Last4"]; //Last4 = Immissioni Wh
$auto_KWH = $memarray_mN_MEMORY["Last5"]; //Last5 = Autoconsumo Wh
$pdc_KWH = $memarray_mN_MEMORY["Last6"]; //Last6 = Pompa calore Wh
$tens_V = $memarray_mN_ILIVEM["Tensione1"]; //Tensione1 = Tensione V
$corr_A = $memarray_mN_ILIVEM["Corrente2"]; //Corrente2 = Corrente A
$cosfi = $memarray_mN_ILIVEM["Cos fi3"]; //Cos fi3 = Cos fi
$tempcpu_C = $memarray_mN_ILIVEM["Temp CPU4"]; //Temp CPU4 = Temp CPU °C
$tensfv_V = $memarray_123s_LIVEM["G1V1"]; //G1V1 = Tensione FV V
$corrfv_A = $memarray_123s_LIVEM["G1A1"]; //G1A1 = Corrente FV A
$potfv_W = $memarray_123s_LIVEM["G1P1"]; //G1P1 = Potenza FV W
$prodtotfv_KWH = $memarray_123s_LIVEM["KWHT1"]; //KWHT1 = Produzione tot FV kWh
$efffv = $memarray_123s_LIVEM["EFF1"]; //EFF1 = Efficienza FV
$freqfv_Hz = $memarray_123s_LIVEM["FRQ1"]; //FRQ1 = Frequenza FV Hz
$maxpotistfv_W = $memarray_123s_LIVEM["pmotd1"]; //pmotd1= Max Potenza Istantanea W
Ma poi ho visto che con un IDX indicavi sia i live che i tot e allora mi sono bloccato

Re: import dati 123solar e metern in domoticz [GUIDA]
s_p ha scritto:forese non ripete ciclicamente la lettura con live.php
fai cosi, dopo <?php vai a capo e inserisci
while(1) {
start();
sleep(10);
}
in moda da leggere
#!/usr/bin/php
<?php
while(1) {
start();
sleep(10);
}
// L I V E
// Live (/dev/shm/mN_LIVEMEMORY.json)
// Produzione1 produzione L1
// Consumi2 consumi L2 e
etc etc..
salva e riavvia
Provato ma non funziona
-
- Messaggi: 247
- Iscritto il: 22/08/2016, 14:13
Re: import dati 123solar e metern in domoticz [GUIDA]
Zan77 ha scritto:Ma quindi con un solo IDX ('idx' => $ID_prel) vedi sia i valori "live" ($prelW) che il "totale" ($prel_KWH)?
//prelievi:
$svalue = "$prelW;$prel_KWH";
$arr = array(
'idx' => $ID_prel,
'nvalue' => 0,
'svalue' => $svalue
Ma poi ho visto che con un IDX indicavi sia i live che i tot e allora mi sono bloccato)
no, hai fatto un pasticcio!
facciamo un esempio facile con solo produzione e consumi:
Codice: Seleziona tutto
#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
die('Direct access not permitted');
}
// sudo chmod +x mqtt_energy.php
// sudo chown www-data\: mqtt_energy.php
// sudo ln -s /var/www/comapps/mqtt_energy.php /usr/bin/mqtt_energy
$frequenza = 10; // seconds for loop
function mqtt($arr)
{
$msg = json_encode($arr);
//$CMD = "mosquitto_pub -d -h '192.168.0.105' -t 'domoticz/in' -m '$msg'";
$CMD = "timeout --kill-after=15s 10s mosquitto_pub -d -h '192.168.0.105' -t 'domoticz/in' -m '$msg'";
exec($CMD, $output);
//$return = implode(PHP_EOL, $output);
//echo $return;
}
// IDX Produzione = 4 ; prelievi = 5 ; autoconsumo = 6 ; fascia f1 = 7 ; fascia f23 = 8 ; immissioni = 9 ; consumi = 10
// domoticz device = dummy device type electrical: instanteo + contatore
//device type = dummy device: electrical instanteno + contatore
//os command:
//sudo mosquitto_pub -d -h 192.168.0.105 -t 'domoticz/in' -m "{"idx": 196, "nvalue": 0, "svalue":"1200.3;12345" }"
// domoticz/in {"idx": 196, "nvalue": 0, "svalue":"1200.3;1" }
$ID_prod = 4; //idx del dummy device: electrical instanteno + contatore = 4
$ID_cons = 10; //idx del dummy device: electrical instanteno + contatore = 10
while (true) {
// qui devi modificare in base alla tua configurazione del file json in /dev/shm che crea meterN
if (file_exists('/dev/shm/mN_LIVEMEMORY.json') && file_exists('/dev/shm/mN_ILIVEMEMORY.json') && file_exists('/dev/shm/mN_MEMORY.json')) {
$data_mN_LIVEM = file_get_contents('/dev/shm/mN_LIVEMEMORY.json');
$data_mN_ILIVEM = file_get_contents('/dev/shm/mN_ILIVEMEMORY.json');
$data_mN_MEMORY = file_get_contents('/dev/shm/mN_MEMORY.json');
$memarray_mN_LIVEM = json_decode($data_mN_LIVEM, true);
$memarray_mN_ILIVEM = json_decode($data_mN_ILIVEM, true);
$memarray_mN_MEMORY = json_decode($data_mN_MEMORY, true);
// qui devi mettere i dati che ci soon nel json MEMORY e LIVEMEMORY, nel mio caso produzione è il meter n°2 e CONSUMI il metern n°1
$prod_KWH = $memarray_mN_MEMORY["Last2"]; //Last2 = Produzione Wh METERN2=produzione quindi LAST2
$cons_KWH = $memarray_mN_MEMORY["Last1"]; //Last1 = Consumi Wh METERN1=consumi quindi LAST1
$consumiW = $memarray_mN_LIVEM["Consumi1"]; //Consumi1 = consumi W questi sono i nomi dei miei meter scritti esattamente così !!!
$prodW = $memarray_mN_LIVEM["Produzione2"]; //Produzinoe2 = produzione W questi sono i nomi dei miei meter scritti esattamente così !!!
// produzione:
$svalue = "$prodW;$prod_KWH";
$arr = array(
'idx' => $ID_prod,
'nvalue' => 0,
'svalue' => $svalue
);
$out = mqtt($arr);
// consumi:
$svalue = "$consumiW;$cons_KWH";
$arr = array(
'idx' => $ID_cons, // Da usare un idx per ogni valore
'nvalue' => 0,
'svalue' => $svalue
);
mqtt($arr);
} else { // ain't running
//die("Aborting: no file \n");
echo "No file\n";
sleep(3);
}
sleep($frequenza);
}
?>
Re: import dati 123solar e metern in domoticz [GUIDA]
Sistemato come hai indicato e funziona!!!
Per testarlo l'ho lanciato con:
[ $(exec /usr/bin/php -f /var/www/comapps/mqtt_energy.php) = 'ERROR' ] && ( stop; exit 1; )
Ma se ora voglio farlo partire in automatico, come creo il systemd service?
Ho provato a guardare quelli creati in /etc/systemd/system, ma sono tutti diversi e non ci capisco molto.
Grazie.
Per testarlo l'ho lanciato con:
[ $(exec /usr/bin/php -f /var/www/comapps/mqtt_energy.php) = 'ERROR' ] && ( stop; exit 1; )
Ma se ora voglio farlo partire in automatico, come creo il systemd service?
Ho provato a guardare quelli creati in /etc/systemd/system, ma sono tutti diversi e non ci capisco molto.
Grazie.
Chi c’è in linea
Visitano il forum: Nessuno e 1 ospite