meterN 0.7

Talks about metering
Locked
jeanmarc
Posts: 1945
Joined: Thu Aug 29, 2013 7:16 am

meterN 0.7

Post by jeanmarc » Mon Oct 20, 2014 8:18 am

Hello,

meterN 0.7 is out, here's the change log :

- Core clean-up
- Bug if it was in skipmode for too long
- Redesign detail page
- New infos page
- Some fixes things that i couldn't even remember ;)

To update you need to save the main configuration for new options plus the configuration for -each- meters.
The 'eflow' example have also change.

Happy monday

tassheloff
Posts: 19
Joined: Tue Apr 22, 2014 6:37 pm

Re: meterN 0.7

Post by tassheloff » Wed Oct 22, 2014 5:39 pm

Does it happens to you that every morning system give you a spike in production at 00:00 if you delete the row 00:00 all goes right.

jeanmarc
Posts: 1945
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.7

Post by jeanmarc » Wed Oct 22, 2014 7:01 pm

No, using pool123solar ? But there is a bug on "eflow", i'am working on it...

tassheloff
Posts: 19
Joined: Tue Apr 22, 2014 6:37 pm

Re: meterN 0.7

Post by tassheloff » Wed Oct 22, 2014 10:24 pm

Yes, i'm using 123solar and command curl http://localhost/metern/comapps/pool123solar.php?cmd=2

jeanmarc
Posts: 1945
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.7

Post by jeanmarc » Thu Oct 23, 2014 8:01 am

I don't have such problem. Could you past the first lines of the day and the last of the previous day ?
You use the lastest version ?

For those interested, here's the eflow corrected, i hope it'll be ok.

Code: Select all

#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
// This script will output --virtuals and estimated-- Wh in/out and self-consumption counters into a meterN compatible format
// It is simply based on your household's production and consumption real meters. The values will be averaged during a 5 min period and will lag from 5 min.
// ln -s /srv/http/metern/comapps/eflow.php /usr/bin/eflow

// Setup your virtual meters numbers :
$whinmet  = 5; // Wh in
$whoutmet = 6; // Wh out 
$selfcmet = 7; // selfconsumption

// No edit is needed below
if (isset($argv[1])) {
    define('checkaccess', TRUE);
    include('../config/config_main.php');
    date_default_timezone_set($DTZ);
    
    for ($i = 1; $i <= $NUMMETER; $i++) { // detect the production/consumption meter
        include("../config/config_met$i.php");
        if (${'PROD' . $i} == 1) {
            $prodmet = $i;
        }
        if (${'PROD' . $i} == 2) {
            $consmet = $i;
        }
    }
    
    $dir    = '../data/csv';
    $output = array();
    $output = glob($dir . '/*.csv');
    sort($output);
    $cnt = count($output);
    
    if (file_exists($output[$cnt - 1])) {
        $file       = file($output[$cnt - 1]); // today
        $contalines = count($file);

        if ($contalines > 2) {
            $lastarray = preg_split("/,/", $file[$contalines - 1]);
            $prevarray = preg_split("/,/", $file[$contalines - 2]);
            
            $year  = substr($output[$cnt - 1], -12, 4);
            $month = substr($output[$cnt - 1], -8, 2);
            $day   = substr($output[$cnt - 1], -6, 2);
        } elseif ($contalines == 1 && file_exists($output[$cnt - 2])) { // yesterday, only header
            $file       = file($output[$cnt - 2]);
            $contalines = count($file);
            
            $lastarray = preg_split("/,/", $file[$contalines - 1]);
            $prevarray = preg_split("/,/", $file[$contalines - 2]);
            
            $year  = substr($output[$cnt - 2], -12, 4);
            $month = substr($output[$cnt - 2], -8, 2);
            $day   = substr($output[$cnt - 2], -6, 2);
        } elseif ($contalines == 2 && file_exists($output[$cnt - 2])) { // yesterday, header + only one data line	
            $lastarray = preg_split("/,/", $file[$contalines - 1]);
            
            $file       = file($output[$cnt - 2]);
            $contalines = count($file);
            $prevarray  = preg_split("/,/", $file[$contalines - 2]);
            
            $year  = substr($output[$cnt - 1], -12, 4);
            $month = substr($output[$cnt - 1], -8, 2);
            $day   = substr($output[$cnt - 1], -6, 2);
        } else {
            $year  = 0;
            $month = 0;
            $day   = 0;
        }
        
        $hour    = substr($lastarray[0], 0, 2);
        $min     = substr($lastarray[0], 3, 2);
        $UTCdate = strtotime($year . '-' . $month . '-' . $day . ' ' . $hour . ':' . $min);
        
        $nowutc = strtotime(date('Ymd H:i:s'));
        
        if ($nowutc - $UTCdate < 330) {
            $prod_val_first = trim($prevarray[$prodmet]);
            $prod_val_last  = trim($lastarray[$prodmet]);
            settype($prod_val_first, 'float');
            settype($prod_val_last, 'float');
            
            if ($prod_val_first <= $prod_val_last) {
                $prod_val_last -= $prod_val_first;
            } else { // counter pass over
                $prod_val_last += ${'PASSO' . $prodmet} - $prod_val_first;
            }
            $housep = $prod_val_last;
            
            $cons_val_first = trim($prevarray[$consmet]);
            $cons_val_last  = trim($lastarray[$consmet]);
            settype($cons_val_first, 'float');
            settype($cons_val_last, 'float');
            
            if ($cons_val_first <= $cons_val_last) {
                $cons_val_last -= $cons_val_first;
            } else { // counter pass over
                $cons_val_last += ${'PASSO' . $consmet} - $cons_val_first;
            }
            $housec = $cons_val_last;
            
            if ($argv[1] == 'whout') {
                $val = $housep - $housec;
                if ($val < 0) {
                    $val = 0;
                }
                $val += $lastarray[$whoutmet];
                if ($val > ${'PASSO' . $whoutmet}) {
                    $val -= ${'PASSO' . $whoutmet};
                }
                $id = ${'ID' . $whoutmet};
            }
            
            if ($argv[1] == 'whin') {
                $val = $housec - $housep;
                if ($val < 0) {
                    $val = 0;
                }
                $val += $lastarray[$whinmet];
                if ($val > ${'PASSO' . $whinmet}) {
                    $val -= ${'PASSO' . $whinmet};
                }
                $id = ${'ID' . $whinmet};
            }
            
            if ($argv[1] == 'selfc') {
                $val = $housep - $housec;
                if ($housep > $housec) {
                    $val = $housec;
                } else {
                    $val = $housep;
                }
                $val += $lastarray[$selfcmet];
                if ($val > ${'PASSO' . $selfcmet}) {
                    $val -= ${'PASSO' . $selfcmet};
                }
                $id = ${'ID' . $selfcmet};
            }
            settype($val, 'float');
        } else {
            if ($argv[1] == 'whout') {
                $id = ${'ID' . $whoutmet};
            }
            if ($argv[1] == 'whin') {
                $id = ${'ID' . $whinmet};
            }
            if ($argv[1] == 'selfc') {
                $id = ${'ID' . $selfcmet};
            }
            $val = null;
        }
    } else {
        $val = null;
    }
    
    $str = utf8_decode("$id($val*Wh)\n");
    echo "$str";
} else {
    die("Usage: eflow { whout | whin | selfc }\n");
}
?>

tassheloff
Posts: 19
Joined: Tue Apr 22, 2014 6:37 pm

Re: meterN 0.7

Post by tassheloff » Thu Oct 23, 2014 6:32 pm

Yesterday
Time,Consumi(Wh),Produzione(Wh),Prelievi(Wh),Immissioni(Wh),Autoconsumo(Wh)
23:20,7527,27545100,15710,55065479,5173
23:25,7675,27545100,15886,55065479,5173
23:30,7729,27545100,16034,55065479,5173
23:35,7786,27545100,16088,55065479,5173
23:40,7838,27545100,16145,55065479,5173
23:45,7888,27545100,16197,55065479,5173
23:50,7934,27545100,16247,55065479,5173
23:55,7960,27545100,16293,55065479,5173
Today
Time,Consumi(Wh),Produzione(Wh),Prelievi(Wh),Immissioni(Wh),Autoconsumo(Wh)
00:00,20,27545100,16319,55065479,5173
00:05,38,27545100,16319,82610559,5193
00:10,57,27545100,16337,82610559,5193
00:15,85,27545100,16356,82610559,5193
00:20,114,27545100,16384,82610559,5193
00:25,142,27545100,16413,82610559,5193
00:30,170,27545100,16441,82610559,5193

jeanmarc
Posts: 1945
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.7

Post by jeanmarc » Thu Oct 23, 2014 8:37 pm

It's rather "Consumi" that isn't correct.. 7960 pass to 20 at midnight. meterN certainly think it has passover.
"Produzione" on the other hand keep the 27545100 value.

tassheloff
Posts: 19
Joined: Tue Apr 22, 2014 6:37 pm

Re: meterN 0.7

Post by tassheloff » Thu Oct 23, 2014 9:22 pm

Can you suggest me where i have to change?

Image

jeanmarc
Posts: 1945
Joined: Thu Aug 29, 2013 7:16 am

Re: meterN 0.7

Post by jeanmarc » Fri Oct 24, 2014 6:56 am

It's rather "pooler" that have to be adjusted. I'll repack the example later on.

tassheloff
Posts: 19
Joined: Tue Apr 22, 2014 6:37 pm

Re: meterN 0.7

Post by tassheloff » Fri Oct 24, 2014 7:44 am

ok just for clarity, my pooler works so:

Code: Select all

#!/usr/bin/php
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
    die('Direct access not permitted');
}
// This script will output a meterN compatible format for the main command
// You'll need to setup the path to meterN ($pathtomn). Put the meters numbers (                                                      $metnum) and the corresponding command ($cmd) :

$pathtomn = '/disco/metern';
$output = shell_exec('pkill -f pv.PoolClient > /dev/null 2>&1 &'); // Kill temporary the "live values fetching"
        $metnum = 1;
    $cmd = 'java -cp /disco/java/bin pv.PoolClient -c period -um Wh -cn 1';

define('checkaccess', TRUE);
include("$pathtomn/config/config_main.php");
include("$pathtomn/config/config_met$metnum.php");

// Retrieve previous value in the last daily csv
$dir    = "$pathtomn/data/csv";
$output = glob($dir . '/*.csv');
sort($output);
$cnt  = count($output);
$file = file($output[$cnt - 1]);
$cnt  = count($file);

$i = 0;
while (!isset($prevval)) {
    $i++;
    $array = preg_split('/,/', $file[$cnt - $i]);
    if (!empty($array[$metnum])) {
        $prevval = $array[$metnum];
    }
    if ($i == $cnt) {
        $prevval = 0; // didn't find any prev. value
    }
}

// Now retrieve the current value

$datareturn = shell_exec($cmd);
$datareturn = trim($datareturn);
$datareturn = preg_replace("/^${'ID'.$metnum}\(/i", '', $datareturn); // VALUE*UNIT)
$lastval    = preg_replace("/\*[a-z0-9³²]+\)$/i", '', $datareturn); // VALUE
settype($lastval, 'float');
settype($prevval, 'float');
$lastval += $prevval;

if (${'PASSO' . $metnum} > 0 && $lastval > ${'PASSO' . $metnum}) { // counter pass over
    $lastval -= ${'PASSO' . $metnum};
}
$lastval = round($lastval, ${'PRECI' . $metnum});
$str     = utf8_decode("${'ID'.$metnum}($lastval*${'UNIT'.$metnum})\n");
echo "$str";
?>

Locked

Who is online

Users browsing this forum: No registered users and 1 guest