meterN with Multinverter

Talks about metering
Post Reply
ninodifr
Posts: 67
Joined: Wed May 07, 2014 11:03 pm

meterN with Multinverter

Post by ninodifr » Fri Jan 09, 2015 10:21 pm

Hello jeanmarc
I need your help,
these days I tried to install "Metern" but unfortunately I had problems
My system has two inverters and so I tried to set it up this way:
1* Consumption
2* Withdrawals
3* Exports
4* Internal consumption
5* Inverter 1
6* Inverters 2
to import values from 123solar I used two "pool123solar.php"
- "Pool123solar.php" for Inverter 1
- "Pool123solar2.php" for Inverters 2
from here everything went well.
But when making the calculation of withdrawals, exports and consumption, something went wrong,
"eflow.php" takes no account of the two inverters and calculates the exports compared to the production of a single inverter,
it would take a change to "eflow.php" to calculate the production of the two inverters and I'm not able to do it.
Another solution would be to change "pool123solar.php" allowing him to read the total production from "123solar", but in this case I could not more ulizzare history recovered from individual inverters "123solar".
Please find a solution to my problem.

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

Re: meterN with Multinverter

Post by jeanmarc » Sat Jan 10, 2015 8:40 am

Hi,

Well actually the eflow is written for a single inverter. Mind that it is an example, i don't have the time/will to write com. app. for every system :roll:

If you wish to also show "Wh in/out" estimation you have to be sure your inverters are on a same single phase. Is it the case ?

I have to rewrite eflow for those case. But it won't be soon, i am playing with my new Odroid C1 ;)
Meanwhile, you can use two different "eflow"? It is not neat though...

ninodifr
Posts: 67
Joined: Wed May 07, 2014 11:03 pm

Re: meterN with Multinverter

Post by ninodifr » Sat Jan 10, 2015 3:10 pm

how you could use two "eflow"?
and then you should do some changes otherwise the two "eflow" would do the same job.
Maybe you could set
"eflow.1" and inverter.1 of phase 1
"eflow.2" and inverter.2 of phase 2
in this way, however, the consumption should be only on phase 1 (or 2).

EDIT: you can not choose the phase of "eflow". :?:

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

Re: meterN with Multinverter

Post by jeanmarc » Sat Jan 10, 2015 5:00 pm

eflow is written for single inverter on a single phase system (mine)

You can simply make eflow1.php eflow2.php and adjust the production/consumption meter (remove the // detect the production/consumption meter part)

Also, if you have different phase, you have to carefully choose the production/consumption meters.

ninodifr
Posts: 67
Joined: Wed May 07, 2014 11:03 pm

Re: meterN with Multinverter

Post by ninodifr » Sat Jan 10, 2015 6:09 pm

I modified eflow in this way:

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  = 2; // Wh in
$whoutmet = 3; // Wh out 
$selfcmet = 4; // 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 (${'PRODMULTI' . $i} == 1) { // modifica multi inverter
            $prodmet1 = $i;
        }
        if (${'PRODMULTI' . $i} == 2) { // modifica multi inverter
            $prodmet2 = $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[$prodmet1]) + trim($prevarray[$prodmet2]); // modifica multi inverter
            $prod_val_last  = trim($lastarray[$prodmet1]) + trim($lastarray[$prodmet2]); // modifica multi inverter
            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' . ($prodmet1 + $prodmet2)} - $prod_val_first; // modifica multi inverter
            }
            $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");
}
?>
I modified "admin_meter.php" and "admin_meter2.php" to add the variable $PRODMULTI
then:
- Inverter 1 > $PRODMULTI=1 > $prodmet1
- Inverter 2 > $PRODMULTI=2 > $prodmet2

It seems to work :D, see for yourself tomorrow.
For security controls eflow I have attached and let me know if it is okay. :ugeek:

EDIT: you can avoid changing "admin_meter.php" and "admin_meter2.php" using the variable Meter $ID,
then:
- Inverter 1 (Meter ID 5) > $ID=5 > $prodmet1
- Inverter 2 (Meter ID 6) > $ID=6 > $prodmet2

ninodifr
Posts: 67
Joined: Wed May 07, 2014 11:03 pm

Re: meterN with Multinverter

Post by ninodifr » Sun Jan 11, 2015 2:50 pm

Last edited by eFLOW,
multi inverter system (max 3 inv):

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  = 2; // Wh in
$whoutmet = 3; // Wh out 
$selfcmet = 4; // selfconsumption

// No edit is needed below
if (isset($argv[1])) {
    define('checkaccess', TRUE);
    include('/var/www/metern/config/config_main.php');
    date_default_timezone_set($DTZ);
    
    for ($i = 1; $i <= $NUMMETER; $i++) { // detect the production/consumption meter
        include("/var/www/metern/config/config_met$i.php");
        if (${'ID' . $i} == 0) { // (inserire quì il Meter ID assegnato al I° inverter)
            $prodmet1 = $i;
        }
        if (${'ID' . $i} == 0) { // (inserire quì il Meter ID assegnato al II° inverter)
            $prodmet2 = $i;
        }
        if (${'ID' . $i} == 0) { // (inserire quì il Meter ID assegnato al III° inverter)
            $prodmet3 = $i;
        }
		if (${'PROD' . $i} == 2) {
            $consmet = $i;
        }
    }
    
    $dir    = '/var/www/metern/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[$prodmet1]) + trim($prevarray[$prodmet2]) + trim($prevarray[$prodmet3]); // modifica multi inverter
            $prod_val_last  = trim($lastarray[$prodmet1]) + trim($lastarray[$prodmet2]) + trim($lastarray[$prodmet3]); // modifica multi inverter
            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' . $prodmet1} - $prod_val_first; // modifica multi inverter
            }
            $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') {
                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");
}
?>
For now I think I've reached my goal. :P

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

Re: meterN with Multinverter

Post by jeanmarc » Fri Jan 23, 2015 6:21 pm

Hi, the eflow now allow several devices (but on the same phase for the self-consumption estimation).
cheers

nickyts
Posts: 1
Joined: Tue Jul 07, 2015 10:02 am

Re: meterN with Multinverter

Post by nickyts » Tue Jul 07, 2015 10:03 am

HI Jeanmarc , where i can find a how-to configure eflow for multinverter? thank you

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

Re: meterN with Multinverter

Post by jeanmarc » Thu Jul 09, 2015 4:58 pm

Hi,
Eflow is not maintained since i don't use it sorry.. It was write for one inverter.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest