Pagina 2 di 5

Re: SHELLY EM

Inviato: 26/04/2020, 14:41
da rinoronie
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...

Re: SHELLY EM

Inviato: 26/04/2020, 23:11
da rinoronie
La struttura del csv è così:

Date/time UTC,Active energy Wh,Returned energy Wh,Min V,Max V
2020-01-23 00:00,85.2,0.0,227.5,233.5
2020-01-23 00:05,83.5,0.0,229.0,233.5
2020-01-23 00:10,66.6,0.0,229.0,233.5
2020-01-23 00:15,91.8,0.0,229.0,233.5
2020-01-23 00:20,63.8,0.0,232.0,233.5
2020-01-23 00:25,75.2,0.0,227.5,235.0
2020-01-23 00:30,63.9,0.0,230.5,235.0

Credo sia meglio optare per leggere la pagina /status come mi avevi suggerito...

Re: SHELLY EM

Inviato: 27/04/2020, 0:11
da rinoronie
Ecco invece un esempio della pagina status dello Shelly EM
► Mostra testo

Re: SHELLY EM

Inviato: 27/04/2020, 11:00
da Flane
Qui puoi prendere spunto da alcune indicazioni date da Jeanmarc su come estrarre informazioni da json:
extract value from json reponse's espeasy
E c'è anche un esempio nelle comapps di JM per estrarre le info dal Json di ESP_Easy

Re: SHELLY EM

Inviato: 27/04/2020, 11:01
da rinoronie
Grazie

Re: SHELLY EM

Inviato: 27/04/2020, 18:12
da rinoronie
Sono riuscito a fare uno script in PHP che legge la pagina status degli shelly

Allego lo script nel caso servisse a qualcuno:

//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)

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);

?>


Alcuni esempi:
nome script: shelly_metern
ip: 192.168.1.72
id metern: 14
canale Shelly: 0

Per SHELLY 2.5:
shelly_metern 192.168.1.72 14 meters 0 total -> 14(4864*Wh)
shelly_metern 192.168.1.72 14 meters 0 power -> 14(10.2*W)

Per SHELLY EM:
shelly_metern 192.168.1.72 14 ConsumoPositivo 0 (per escludere i valori negativi nel caso vogliamo monitorare i consumi ma in quel momenti ci sono delle immissioni)
shelly_metern 192.168.1.72 14 emeters 0 total
shelly_metern 192.168.1.72 14 ConsumoNegativo 0 (il contrario di ConsumoPositivo)
shelly_metern 192.168.1.72 14 emeters 0 total_returned

Re: SHELLY EM

Inviato: 29/04/2020, 17:37
da Flane
Grazie rinoronie,
questa sera se riesco faccio qualche prova con i miei shelly ;)

Re: SHELLY EM

Inviato: 29/04/2020, 18:29
da rinoronie
fammi sapere se devo fare qualche modifica...
Oggi è arrivato anche il mio SHELLY EM, da una stima velocissima, misura un po' meno dello SDM230.
Un volta installato in parallelo vi dico la percentuale (magari poi modifico lo script in modo da poter inserire anche una percentuale nella lettura)

Re: SHELLY EM

Inviato: 29/04/2020, 20:45
da Flane
Questa della misura non l'ho capita.
Come fai a confrontare un dispositivo da barra din con uno fatto per inserire ad incasso?

L'SDM230 è da barra din e di formato standard : 2 moduli din (2 x 17,5mm)

Re: SHELLY EM

Inviato: 29/04/2020, 23:14
da Flane
Ho fatto qualche test, ma sinceramente non ho capito perchè hai fatto tutto così complicato.

Io avrei fatto in questo modo per estrarre energia e potenza dei due misuratori integrati in Shelly 2.5 e shelly 1PM (non ho shelly EM):

Script /var/comapps/reqshelly.php

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";
?>


Per lo Shelly EM si deve sostituire a "meters" il termine "emeters"