Re: SHELLY EM
Inviato: 26/04/2020, 14:41
ordinato Shelly EM, lo metterò in parallelo SDM e ti farò sapere quanto affidabile è, in cambio magari mi dai una mano a leggere il csv con metern...
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
//versione 1.0 del 27/04/202 by rinoronie
//Parametri avvio:
//1 - Indirizzo ip dello shelly
//2 - ID metern
//4 - ConsumoPositivo oppure ConsumoNegativo oppure PrimoValoreStrutturaJSON (emeters o meters)
//5 - SecondoValoreStrutturaJSON (0 o 1)
//6 - TerzoValoreStrutturaJSON (total o total_returned o power)
$utente = 'admin';
$password = 'VostraPassword';
$url = "http://$argv[1]/status";
//print_r($url);
$ch = curl_init($url);
curl_setopt ($ch,CURLOPT_USERPWD, "$utente:$password");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 3000); // error
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$espjson = array();
if (($espjson = curl_exec($ch)) === false) {
die(curl_error($ch) . "\n");
}
curl_close($ch);
$val = json_decode($espjson, true);
//print_r($val);
$conteggio = 0;
foreach ($argv as $arg) {
$e=explode("=",$arg);
$conteggio = $conteggio + 1;
}
//print_r($conteggio);
switch ($argv[3]) {
case "ConsumoPositivo":
$valore = $val['emeters'][$argv[4]]['power'];
if ($valore < 0)
$valore = 0;
break;
case "ConsumoNegativo":
$valore = $val['emeters'][$argv[4]]['power'];
if ($valore < 0)
$valore = abs($valore);
else
$valore = 0;
break;
default:
{
switch ($conteggio) {
case 4:
$valore = $val[$argv[3]];
break;
case 5:
$valore = $val[$argv[3]][$argv[4]];
break;
case 6:
$valore = $val[$argv[3]][$argv[4]][$argv[5]];
break;
}
}
}
//formatto per metern
if($conteggio>=6)
{
if($argv[5]=='total' or $argv[5]=='power')
print_r("$argv[2](");
print_r($valore);
if($argv[5]=='power')
print_r('*W)');
if($argv[5]=='total')
print_r('*Wh)');
}
else
print_r($valore);
?>
Codice: Seleziona tutto
#!/usr/bin/php
<?php
// This script will output a meterN compatible format for read Shelly 2.5 and Shelly 1PM device
//
// Script reqshelly.php v1.0 by Flanesi
//
// You'll need to setup correct permission chmod +x
// then ln -s /var/www/comapps/reqshelly.php /usr/local/bin/reqshelly
// Request command with 'reqshelly IP power0 IDmetern' or 'reqshelly IP energy0 IDmetern'
if (isset($_SERVER['REMOTE_ADDR'])) {
die('Direct access not permitted');
}
if (!isset($argv[1]) or !isset($argv[2]) or !isset($argv[3])) {
die("Abording: no valid argument given.\nUsage: reqshelly IP (power0|power1|energy0|energy1) IDmetern\n");
} elseif ($argv[2] == 'power0') {
$url = "http://"."$argv[1]"."/status";
$pagina = file_get_contents($url);
$json_output = json_decode($pagina, true);
$val = $json_output['meters'][0]['power'];
$outstr = "$argv[3]($val*W)";
} elseif ($argv[2] == 'power1') {
$url = "http://"."$argv[1]"."/status";
$pagina = file_get_contents($url);
$json_output = json_decode($pagina, true);
$val = $json_output['meters'][1]['power'];
$outstr = "$argv[3]($val*W)";
} elseif ($argv[2] == 'energy0') {
$url = "http://"."$argv[1]"."/status";
$pagina = file_get_contents($url);
$json_output = json_decode($pagina, true);
$val = $json_output['meters'][0]['total'];
$outstr = "$argv[3]($val*W)";
} elseif ($argv[2] == 'energy1') {
$url = "http://"."$argv[1]"."/status";
$pagina = file_get_contents($url);
$json_output = json_decode($pagina, true);
$val = $json_output['meters'][1]['total'];
$outstr = "$argv[3]($val*W)";
// and so on ....
} else {
die("Usage: reqshelly IP (power0|power1|energy0|energy1) IDmetern\n");
}
echo "$outstr";
?>