Janitza UMG 605 Poweranalysator per SNMP auslesen

Frohes Neues Zusammen,

wollte mal aus meinen „zusammengefunden“ Scripten was zurück in die Runden geben (Die Fundstellen sind im Script vermerkt).

Hiermit wird eine Poweranalysator (hier Janitza UMG 605) ausgelesen, im ersten Step die momentane Wirkleistung von L1-L3 und der Zähler.
ModBus ist mir zur Zeit noch zu hoch, als Netzwerkklempner kenne ich mit mit SNMP besser aus :D.

Viele Spaß und schöne Grüße

Udo

Edit 2017-12-15 Erweitertes Script eingestellt (Frequenz, Spannung und Leistung pro Aussenleiter).

<?
/*
Script zum Auslesen eines Janitza UMG 605 Poweranalysator per SNMP
Weitere Werte werden später noch erweitert.


Die Variablen und deren Profile werden beim ersten Start des Scriptes automatisch generiert sofern sie nicht schon existieren.
Das Script setzt sich selbst auf "hidden", damit ein Link auf die Instanz im Webfront/iFront das Script nicht anzeigt.

Installation:
1. Eine neue Instanz anlegen (Dummy-Module)
2. Script unter dieser Instanz anlegen und den Inhalt dieser Datei dort einfügen
3. Script speichern und einmal ausführen
4. Fertig ;-)

Viel Spaß!

Autor: kea
Grundlage1: Das Script von "sanman" aus dem Thread "SNMP Geräte auslesen am Beispiel einer APC USV"
Grundlage2: Das Script von "konfu"	aus dem Thread "Auslesen einer APC SmartUPS USV mit ssnmp"
Vielen Dank an alle Vorposter

*/


set_time_limit(80); //Timeout auf 80s setzen
$host           = "172.26.59.94";
$community      = "public";
$binary = "C:\ip-symcon\ssnmpq\ssnmpq2.exe";
$minutes = 1;

// Variablen-Namen definieren
$pwmoml123	      	= "Wirkleistung L1-L3";
$pwl123				= "Zählerstand";
$lastread       = "Datum letzte SNMP Abfrage";
$ul1			= "Spannung L1";
$ul2			= "Spannung L2";
$ul3			= "Spannung L3";
$f				= "Frequenz";
$pwl1			= "Wirkleistung L1";
$pwl2			= "Wirkleistung L2";
$pwl3			= "Wirkleistung L3";

// ID des Archive Handlers auslesen
$archive = IPS_GetInstanceIDByName ( "Archive Handler", 0 ); 

//Debug Ausgabe aktivieren?
$debug          = false;   // false true
$zaehlerstand	=201087.8;

$pwmoml123_OID	     	= ".1.3.6.1.4.1.34278.2.1.0";  	// momentane Wirkleistung Summe L1-L3 3.1.0 -> L1-L4
$pwl123_OID				= ".1.3.6.1.4.1.34278.5.1.0";	// bezogene Wirkleistung L1-L3 in 0,1kWh
$ul1_OID				= ".1.3.6.1.4.1.34278.1.1.0"; 	// U L1 in 100mV
$ul2_OID				= ".1.3.6.1.4.1.34278.1.2.0"; 	// U L2 in 100mV
$ul3_OID				= ".1.3.6.1.4.1.34278.1.3.0"; 	// U L2 in 100mV
$f_OID					= ".1.3.6.1.4.1.34278.8.1.0"; 	// Frequenz in 0,01HZ
$pwl1_OID				= ".1.3.6.1.4.1.34278.1.12";	// P L1 in W
$pwl2_OID				= ".1.3.6.1.4.1.34278.1.13";	// P L1 in W
$pwl3_OID				= ".1.3.6.1.4.1.34278.1.14";	// P L1 in W


//SNMP Query Funktion
function snmpget2($oid)
{
    global $host, $community, $binary;

    $oid = ltrim($oid,".");
    $value = IPS_Execute($binary, "/h:$host /c:$community /o:$oid /v", false, true);
    $value = trim($value);
    return $value;
}
$zaehler = 1;
$parentID = IPS_GetObject($IPS_SELF);
$parentID = $parentID['ParentID'];
IPS_SetHidden($IPS_SELF, true);

$ereignisse = 0;
$children = IPS_GetChildrenIDs($IPS_SELF);
$amount = count($children);
if ($amount > 0)
{
    foreach ($children as $id)
    {
       $array = IPS_GetObject($id);
        $type = $array["ObjectType"];
        if ($type == 4)
        {
           $event = IPS_GetEvent ( $id );
            if ($event["EventType"]== 1)
            {
               $ereignisse++;
            }
        }
    }

}

if ($ereignisse == 0)
{
    $eid = IPS_CreateEvent(1);
    IPS_SetEventCyclic($eid, 0, 0, 0, 2, 2 ,$minutes); //Alle 2 Minuten
    IPS_SetParent($eid, $_IPS['SELF']);
    IPS_SetEventActive($eid, true);
}

//-------------------------------------------------------------
//  Variablenbeschreibung für Wirkleistung anlegen

if (!IPS_VariableProfileExists("UMG-P-Wirk"))
{
        IPS_CreateVariableProfile("UMG-P-Wirk", 2);
        IPS_SetVariableProfileText("UMG-P-Wirk", "", " W");
        IPS_SetVariableProfileValues("UMG-P-Wirk", 0, 75000, 1);         // max 75kW für einen 63A/3P Hausanschluss 
        IPS_SetVariableProfileDigits("UMG-P-Wirk", 0);
          IPS_SetVariableProfileIcon("UMG-P-Wirk",  "Electricity");
          if ($debug) { echo "Profil UMG-P-Wirk wurde angelegt.
"; }
}

if (!IPS_VariableProfileExists("UMG-P-Lx"))
{
        IPS_CreateVariableProfile("UMG-P-Lx", 2);
        IPS_SetVariableProfileText("UMG-P-Lx", "", " W");
        IPS_SetVariableProfileValues("UMG-P-Lx", 0, 15000, 1);         // max 15kW pro Außenleiter
        IPS_SetVariableProfileDigits("UMG-P-Lx", 0);
          IPS_SetVariableProfileIcon("UMG-P-Lx",  "Electricity");
          if ($debug) { echo "Profil UMG-P-Lx wurde angelegt.
"; }
}

//  Variablenbeschreibung für kWh anlegen

if (!IPS_VariableProfileExists("UMG-P"))
{
        IPS_CreateVariableProfile("UMG-P", 2);
        IPS_SetVariableProfileText("UMG-P", "", " kWh");
        IPS_SetVariableProfileDigits("UMG-P", 1);
          IPS_SetVariableProfileIcon("UMG-P",  "Electricity");
          if ($debug) { echo "Profil UMG-P wurde angelegt.
"; }
}

//  Variablenbeschreibung für f anlegen

if (!IPS_VariableProfileExists("UMG-F"))
{
        IPS_CreateVariableProfile("UMG-F", 2);
        IPS_SetVariableProfileText("UMG-F", "", " Hz");
        IPS_SetVariableProfileDigits("UMG-F", 2);
		IPS_SetVariableProfileValues("UMG-F", 49, 51, 0);         // 48 - 52 Hz
          IPS_SetVariableProfileIcon("UMG-F",  "Electricity");
          if ($debug) { echo "Profil UMG-F wurde angelegt.
"; }
}

//  Variablenbeschreibung für u anlegen

if (!IPS_VariableProfileExists("UMG-U"))
{
        IPS_CreateVariableProfile("UMG-U", 2);
        IPS_SetVariableProfileText("UMG-U", "", " V");
        IPS_SetVariableProfileDigits("UMG-U", 1);
		IPS_SetVariableProfileValues("UMG-U", 0, 270, 0);         
          IPS_SetVariableProfileIcon("UMG-U",  "Electricity");
          if ($debug) { echo "Profil UMG-U wurde angelegt.
"; }
}

//  Variable für momentane Wirkleistung anlegen
$Var = @IPS_GetVariableIDByName($pwmoml123, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $pwmoml123ID = IPS_CreateVariable(2);
        IPS_SetName($pwmoml123ID, $pwmoml123);
        IPS_SetParent($pwmoml123ID, $parentID);
        IPS_SetVariableCustomProfile($pwmoml123ID, "UMG-P-Wirk");
        IPS_SetPosition($pwmoml123ID, $zaehler);
        AC_SetLoggingStatus($archive, $pwmoml123ID, true);
        if ($debug) { echo "Variable $pwmoml123ID ($pwmoml123) wurde angelegt.
"; }
}
else { $pwmoml123ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für momentane Wirkleistung L1 anlegen             
$Var = @IPS_GetVariableIDByName($pwl1, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $pwl1ID = IPS_CreateVariable(2);
        IPS_SetName($pwl1ID, $pwl1);
        IPS_SetParent($pwl1ID, $parentID);
        IPS_SetVariableCustomProfile($pwl1ID, "UMG-P-Lx");
        IPS_SetPosition($pwl1ID, $zaehler);
        AC_SetLoggingStatus($archive, $pwl1ID, true);
        if ($debug) { echo "Variable $pwl1ID ($pwl1) wurde angelegt.
"; }
}
else { $pwl1ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für momentane Wirkleistung L2 anlegen      
$Var = @IPS_GetVariableIDByName($pwl2, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $pwl2ID = IPS_CreateVariable(2);
        IPS_SetName($pwl2ID, $pwl2);
        IPS_SetParent($pwl2ID, $parentID);
        IPS_SetVariableCustomProfile($pwl2ID, "UMG-P-Lx");
        IPS_SetPosition($pwl2ID, $zaehler);
        AC_SetLoggingStatus($archive, $pwl2ID, true);
        if ($debug) { echo "Variable $pwl2ID ($pwl2) wurde angelegt.
"; }
}
else { $pwl2ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für momentane Wirkleistung L3 anlegen      
$Var = @IPS_GetVariableIDByName($pwl3, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $pwl3ID = IPS_CreateVariable(2);
        IPS_SetName($pwl3ID, $pwl3);
        IPS_SetParent($pwl3ID, $parentID);
        IPS_SetVariableCustomProfile($pwl3ID, "UMG-P-Lx");
        IPS_SetPosition($pwl3ID, $zaehler);
        AC_SetLoggingStatus($archive, $pwl3ID, true);
        if ($debug) { echo "Variable $pwl3ID ($pwl3) wurde angelegt.
"; }
}
else { $pwl3ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für Zählerstand anlegen
$Var = @IPS_GetVariableIDByName($pwl123, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $pwl123ID = IPS_CreateVariable(2);
        IPS_SetName($pwl123ID, $pwl123);
        IPS_SetParent($pwl123ID, $parentID);
        IPS_SetVariableCustomProfile($pwl123ID, "UMG-P");
        IPS_SetPosition($pwl123ID, $zaehler);
        AC_SetLoggingStatus($archive, $pwl123ID, true);
        if ($debug) { echo "Variable $pwl123ID ($pwmoml123) wurde angelegt.
"; }
}
else { $pwl123ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für Frequenzanlegen
$Var = @IPS_GetVariableIDByName($f, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $fID = IPS_CreateVariable(2);
        IPS_SetName($fID, $f);
        IPS_SetParent($fID, $parentID);
        IPS_SetVariableCustomProfile($fID, "UMG-F");
        IPS_SetPosition($fID, $zaehler);
        AC_SetLoggingStatus($archive, $fID, true);
        if ($debug) { echo "Variable $fID ($f) wurde angelegt.
"; }
}
else { $fID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für U L1 anlegen
$Var = @IPS_GetVariableIDByName($ul1, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $ul1ID = IPS_CreateVariable(2);
        IPS_SetName($ul1ID, $ul1);
        IPS_SetParent($ul1ID, $parentID);
        IPS_SetVariableCustomProfile($ul1ID, "UMG-U");
        IPS_SetPosition($ul1ID, $zaehler);
        AC_SetLoggingStatus($archive, $ul1ID, true);
		if ($debug) { echo "Variable $ul1ID ($ul1) wurde angelegt.
"; }
}
else { $ul1ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für U L2 anlegen
$Var = @IPS_GetVariableIDByName($ul2, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $ul2ID = IPS_CreateVariable(2);
        IPS_SetName($ul2ID, $ul2);
        IPS_SetParent($ul2ID, $parentID);
        IPS_SetVariableCustomProfile($ul2ID, "UMG-U");
        IPS_SetPosition($ul2ID, $zaehler);
        AC_SetLoggingStatus($archive, $ul2ID, true);
		if ($debug) { echo "Variable $ul2ID ($ul2) wurde angelegt.
"; }
}
else { $ul2ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;

//  Variable für U L3 anlegen
$Var = @IPS_GetVariableIDByName($ul3, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $ul3ID = IPS_CreateVariable(2);
        IPS_SetName($ul3ID, $ul3);
        IPS_SetParent($ul3ID, $parentID);
        IPS_SetVariableCustomProfile($ul3ID, "UMG-U");
        IPS_SetPosition($ul3ID, $zaehler);
        AC_SetLoggingStatus($archive, $ul3ID, true);
		if ($debug) { echo "Variable $ul2ID ($ul3) wurde angelegt.
"; }
}
else { $ul3ID = $Var;       }
$Var = false; //Sicher is sicher ...
$zaehler++;


//-------------------------------------------------------------
// Datum letzte Abfrage
$Var = @IPS_GetVariableIDByName($lastread, $parentID);
if ($Var === false) //Wenn es die Variable nicht gibt, wird sie angelegt ...
{
        $lastreadID = IPS_CreateVariable(3);
        IPS_SetName($lastreadID, $lastread);
        IPS_SetParent($lastreadID, $parentID);
        IPS_SetVariableCustomProfile($lastreadID, "UPS_Date");
        IPS_SetPosition($lastreadID, $zaehler);
        if ($debug) { echo "Variable $lastreadID ($lastread) wurde angelegt.
"; }
}
else { $lastreadID = $Var; }
$Var = false; //Sicher is sicher ...
$zaehler++;

//--------------SNMP auslesen

$value = snmpget2 ($pwmoml123_OID);
SetValue($pwmoml123ID, $value); 
	if ($debug) { echo "$pwmoml123 : $value
"; }

$value = snmpget2 ($pwl123_OID);
SetValue($pwl123ID, $value/10+$zaehlerstand);    // Aufrechnen auf kWh (siehe Zeile 49) und Addition Korrekturfaktor 
	if ($debug) { echo "$pwl123 : $value
"; }
	
$value = snmpget2 ($f_OID);
SetValue($fID, $value/100); 
	if ($debug) { echo "$f : $value
"; }

$value = snmpget2 ($ul1_OID);
SetValue($ul1ID, $value/10); 
	if ($debug) { echo "$ul1 : $value
"; }

$value = snmpget2 ($ul2_OID);
SetValue($ul2ID, $value/10); 
	if ($debug) { echo "$ul2 : $value
"; }

$value = snmpget2 ($ul3_OID);
SetValue($ul3ID, $value/10); 
	if ($debug) { echo "$ul3 : $value
"; }

$value = snmpget2 ($pwl1_OID);
SetValue($pwl1ID, $value); 
	if ($debug) { echo "$pwl1 : $value
"; }

$value = snmpget2 ($pwl2_OID);
SetValue($pwl2ID, $value); 
	if ($debug) { echo "$pwl2 : $value
"; }

$value = snmpget2 ($pwl3_OID);
SetValue($pwl3ID, $value); 
	if ($debug) { echo "$pwl3 : $value
"; }


$date = date("d.m.Y H:i:s");
SetValueString($lastreadID, $date);
if ($debug) { echo "$lastreadID : $date
"; }



?>

N’abend Zusammen,

nach dem Umstieg auf Windows Server 2016 funktionierte ssnmpq.exe nicht mehr.
Habe das Script jetzt auf snmpget.exe umgestellt.
SnmpGet (Shell Tool) | SNMP Software

Folgendes muss getauscht werden:

ssnmpget.ex ins Stammverzeichniss von IPS kopieren und das Script anpassen:


// alt
// $binary = "C:\ip-symcon\ssnmpq\ssnmpq2.exe";
// neu
$binary = "C:\ip-symcon\SnmpGet.exe";

und


// alt
// $value = IPS_Execute($binary, "/h:$host /c:$community /o:$oid /v", false, true);
// neu
$value = IPS_Execute($binary, "-q -r:$host -c:$community -o:$oid", false, true);

Viele Grüße aus OBC

kea