Batteriestatuskontrollskript mit WebFront-Ausgabe

Batteriestatuskontrollskript für IP-Symcon 2.1:

<?php
    /*****
    *
    * Überprüfung aller Geräte auf Batterieprobleme
    *
    * Dieses Skript richtet beim Aufruf eine automatische Batterieprüfung ein.
    * Wird es über das WebFront aufgerufen erscheint eine Liste der problematischen
    * Geräte.
    *
    * Alle Geräte, deren Batteriestatus bereits ein Variablenprofil besitzet, werden
    * automatisch erkannt. Für alle anderen Variablen ist dies manuell nachzuholen.
    *
    * Anleitung:
    * - Intervall nach belieben anpassen.
    * - Bei entsprechender Kenntnis eventuell die Profilliste erweitern.
    * - Skript zur Ausführung bringen, um Timer und Warnungs-Variable zu erstellen.
    *
    *****/

    /***** Konfiguration *****/

    $Interval = 5;    // Kontrollintervall in Minuten

    // Variablenprofile mit Werten, bei deren Erreichen oder Unterschreitung gewarnt wird
    $Profiles = array("~Battery" => true, "~Battery.Reversed" => false, "~Battery.100" => 25);


    /***** Programmcode (ab hier nichts mehr verändern) *****/

    $VariableWarningID = CreateVariableByName($IPS_SELF, "Warnung", 0, "~Battery");

    if ($IPS_SENDER == "WebFront")
    {
        $result = "";

        $VariableIDs = IPS_GetVariableList();
        foreach($VariableIDs as $VariableID)
        {
           if ($VariableID != $VariableWarningID)
           {
                $variableData = IPS_GetVariable($VariableID);
                $value = GetValue($VariableID);
                $profileName = IPS_VariableProfileExists($variableData['VariableProfile']) ? $variableData['VariableProfile'] : "";
                $profileName = (strlen($variableData['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variableData['VariableCustomProfile'])) ? $variableData['VariableCustomProfile'] : $profileName;

                $warning = false;
                if (strlen($profileName) > 0)
                {
                    foreach ($Profiles as $pName => $pValue)
                    {
                        if ($profileName == $pName)
                        {
                            if (is_bool($pValue))
                            {
                                if ($value == $pValue) { $warning = true; }
                            }
                            else
                            {
                                if ($value <= $pValue) { $warning = true; }
                            }
                            break;
                        }
                    }
                }

                if ($warning)
                {
                    $result .= "<em>".IPS_GetLocation($VariableID)."</em>: ".GetValueFormatted($VariableID)."<br />";
                }
            }
        }

        if ($result == "")
        {
            echo "Keine Probleme bekannt.";
            SetValueBoolean($VariableWarningID, false);
        }
        else
        {
            echo "Geräte mit Batterieproblemen:<br /><br />".$result;
            SetValueBoolean($VariableWarningID, true);
        }
        IPS_SetScriptTimer($IPS_SELF, $Interval * 60);
    }
    else
    {
        $warning = false;

        $VariableIDs = IPS_GetVariableList();

        foreach ($VariableIDs as $VariableID)
        {
           if ($VariableID != $VariableWarningID)
           {
                $variableData = IPS_GetVariable($VariableID);
                $value = GetValue($VariableID);
                $profileName = IPS_VariableProfileExists($variableData['VariableProfile']) ? $variableData['VariableProfile'] : "";
                $profileName = (strlen($variableData['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variableData['VariableCustomProfile'])) ? $variableData['VariableCustomProfile'] : $profileName;

                $warning = false;
                if (strlen($profileName) > 0)
                {
                    foreach ($Profiles as $pName => $pValue)
                    {
                        if ($profileName == $pName)
                        {
                            if (is_bool($pValue))
                            {
                                if ($value == $pValue) { $warning = true; }
                            }
                            else
                            {
                                if ($value <= $pValue) { $warning = true; }
                            }
                            break;
                        }
                    }
                }
                if ($warning) { break; }
            }
        }

        SetValueBoolean($VariableWarningID, $warning);
        IPS_SetScriptTimer($IPS_SELF, $Interval * 60);
    }

    function CreateVariableByName($id, $name, $type, $profile = "")
    {
        global $IPS_SELF;
        $vid = @IPS_GetVariableIDByName($name, $id);
        if($vid === false)
        {
            $vid = IPS_CreateVariable($type);
            IPS_SetParent($vid, $id);
            IPS_SetName($vid, $name);
            IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
            if($profile !== "") { IPS_SetVariableCustomProfile($vid, $profile); }
        }
        return $vid;
    }
?>

Hallo Horst,

meinst Du, dass Du dieses Script eventuell für die Version 2.1 umbauen können würdest ?

Ich habe dies als sehr nützlich kennengelernt, aber aktuell ist dies leider nicht nutzbar.

Gruss
B71

Warum soll das Skrift bzw. der Notifier dort icht nutzbar sein?
Du meinst bestimmt, weil die config.custom basic.php Funktion abgeschaltet wurde? Dann brauchst du es doch nur (in der neusten 2.1) in die webfront.php hinein zu kopieren. Sollte dann laufen.

Hi,

wegen der ganzen generierten Fehlermeldungen bei Aufruf des Batterie Scriptes.
Im Meldungsfenster steppt dann immer der Punk.

Der Notifier funktioniert bei mir ganz normal mit anderen Widgetkomponenten.
Das ist nicht mein Problem.

Die neueste BETA habe ich aufgrund der nötigen Änderungen meiner custom.php noch nicht angefasst.

Gruss
B71

Oh, ok, gut zu wissen. Da ich die Beta Versionen bisher nur zum Test einsetze und nur ohne angeschlossene FHZ, dachte ich das läge bei mir daran, da (wie bei Dir) der Notifier soweit funktioniert. Jaja, ich weiß schon … wenn man (also ich) keine Ahnung hat … einfach mal …

Warten wir mal ab ob un was Hort dazu meint.

Habe mal eine Version für die 2.1 angepasst. Ich hoffe mal, dass es so fehlerfrei läuft.

DANKE !! Wird heute abend (spät) mal getestet.

Gruss
B71

Hallo Nutzer des Batterieskriptes.

Sollte jemand das Batterieskript mit der neuesten V2.1 (17.08) nutzen und sich wundern warum die Variable „Warnung“ ein benutzerdefiniertes Variablenprofil nicht behält muss im Skript (nur V2.1) die Zeile mit der Zuweisung des Variablenprofiles auf seine eigenes Profil umstellen.

IPS_SetVariableCustomProfile($VariableWarningID, "~Battery");

hier statt „~Battery“ sein eigenes Profil eintragen.

Das hat mich 15 Minuten Zeit gekostet bis ich auf das Problem kam das immer wieder das Profil auf Standard zurückgesetzt wurde.:smiley:

Damit man hinterher unbesorgt das Variablenprofil ändern kann, habe ich das Skript so angepasst, dass nur noch beim ersten Aufruf beim Erstellen der Statusvariable das Profil ~Battery zugewiesen wird.

Seitdem ich meine USV über NUT auswerte, meint das „Batteriestatuskontrollskript“, dass die USV eine schwache Batterie hätte. :smiley:

Der Grund ist wohl, dass der ausgelesene USV-Wert „LoadPct“ das Variablenprofil „~Battery.100“ hat und unter 25% liegt. Das ist aber eigentlich in Ordnung.

Kurz: Das Skript funktioniert zwar wie es soll, aber das Ergebnis ist trotzdem falsch. Lässt sich das irgendwie beheben?

Die Idee, über ein weiteres Skript die Batterie-Meldung wieder zu neutralisieren, wenn sie nur durch die USV ausgelöst wurde, erscheint mir etwas holprig.

Grüße
galleto

Leg dir doch ein eigenes Profil an und trag es im Array ein.

So ähnlich hat es geklappt: Ich habe dem USV-Wert ein anderes Profil (Intensity) zugewiesen, nun wird er vom Batterie-Skript nicht mehr ausgewertet.

Da die USV-Variablen vom USV-Auswerte-Skript überprüft und ggf. automatisch (wieder) angelegt werden, hatte ich die Befürchtung, dass die Umstellung des Profils nicht von Dauer ist. War aber kein Problem, das Profil bleibt.

Dank und Grüße
galleto

Hallo,

ich habe diese Script eigentlich auch schon lange installiert und mich gewundert das es keine neuen variablen anlegt.
Darum habe ich heute mal alle Variablen gelöscht und das Script manuell gestartet.
Aber es werden überhaupt keine Variablen angelegt. :frowning: Muss im Script, für IPS 2.7, irgendwas verändert werden ?

Hallo Horst,

das übliche was bei den alten Scripten angepasst werden muss, ist aber nicht erst seit 2.7 so.

function CreateVariableByName($id, $name, $type)
{
    $vid = @IPS_GetVariableIDByName($name, $id);
    if($vid === false)
    {
        $vid = IPS_CreateVariable($type);
        IPS_SetParent($vid, $id);
        IPS_SetName($vid, $name);
        IPS_SetInfo($vid, "This Variable was created by Script #".$_IPS['SELF']);
    }
    return $vid;
}

Danke rainer,

hab es mal angepasst und in den anderen Scripten die da noch so waren auch :o

Hallo zusammen!

Wäre es möglich das Skript so anzupassen, dass in einem Alarmfall das jeweilige Gerät in eine separate Variable geschrieben wird?
So könnte ich auch im iFront sofort erkennen um welches Gerät es sich handelt.

Hab schon mal durchgeguckt, aber ich bekomme das leider nicht hin :frowning:

—edit—

Okay, jetzt bin ich doch selber drauf gekommen :wink:

Falls es noch jemand gebrauchen kann, hier das geänderte Skript mit zusätzlicher Standort Variable:


<?
    /*****
    *
    * Überprüfung aller Geräte auf Batterieprobleme
    *
    * Dieses Skript richtet beim Aufruf eine automatische Batterieprüfung ein.
    * Wird es über das WebFront aufgerufen erscheint eine Liste der problematischen
    * Geräte.
    *
    * Alle Geräte, deren Batteriestatus bereits ein Variablenprofil besitzet, werden
    * automatisch erkannt. Für alle anderen Variablen ist dies manuell nachzuholen.
    *
    * Anleitung:
    * - Intervall nach belieben anpassen.
    * - Bei entsprechender Kenntnis eventuell die Profilliste erweitern.
    * - Skript zur Ausführung bringen, um Timer und Warnungs-Variable zu erstellen.
    *
    *****/

    /***** Konfiguration *****/

    $Interval = 360;    // Kontrollintervall in Minuten
    
    // Variablenprofile mit Werten, bei deren Erreichen oder Unterschreitung gewarnt wird
    $Profiles = array("~Battery" => true, "~Battery.Reversed" => false, "~Battery.100" => 25);


    /***** Programmcode (ab hier nichts mehr verändern) *****/

    $VariableWarningID = CreateVariableByName($IPS_SELF, "Warnung", 0, "~Battery");
    $VariableLoctionID = CreateVariableByName($IPS_SELF, "Standort", 3, "~String");

    if ($IPS_SENDER == "WebFront")
    {
        $result = "";

        $VariableIDs = IPS_GetVariableList();
        foreach($VariableIDs as $VariableID)
        {
           if ($VariableID != $VariableWarningID)
           {
                $variableData = IPS_GetVariable($VariableID);
                $value = GetValue($VariableID);
                $profileName = IPS_VariableProfileExists($variableData['VariableProfile']) ? $variableData['VariableProfile'] : "";
                $profileName = (strlen($variableData['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variableData['VariableCustomProfile'])) ? $variableData['VariableCustomProfile'] : $profileName;

                $warning = false;
                if (strlen($profileName) > 0)
                {
                    foreach ($Profiles as $pName => $pValue)
                    {
                        if ($profileName == $pName)
                        {
                            if (is_bool($pValue))
                            {
                                if ($value == $pValue) { $warning = true; }
                            }
                            else
                            {
                                if ($value <= $pValue) { $warning = true; }
                            }
                            break;
                        }
                    }
                }

                if ($warning)
                {
                    $result .= "<em>".IPS_GetLocation($VariableID)."</em>: ".GetValueFormatted($VariableID)."<br />";
                }
            }
        }

        if ($result == "")
        {
            echo "Keine Probleme bekannt.";
            SetValueBoolean($VariableWarningID, false);
        }
        else
        {
            echo "Geräte mit Batterieproblemen:<br /><br />".$result;
            SetValueBoolean($VariableWarningID, true);
        }
        IPS_SetScriptTimer($IPS_SELF, $Interval * 60);
    }
    else
    {
        $warning = false;

        $VariableIDs = IPS_GetVariableList();

        foreach ($VariableIDs as $VariableID)
        {
           if ($VariableID != $VariableWarningID)
           {
                $variableData = IPS_GetVariable($VariableID);
                $value = GetValue($VariableID);
                $profileName = IPS_VariableProfileExists($variableData['VariableProfile']) ? $variableData['VariableProfile'] : "";
                $profileName = (strlen($variableData['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variableData['VariableCustomProfile'])) ? $variableData['VariableCustomProfile'] : $profileName;

                $warning = false;
                if (strlen($profileName) > 0)
                {
                    foreach ($Profiles as $pName => $pValue)
                    {
                        if ($profileName == $pName)
                        {
                            if (is_bool($pValue))
                            {
                                if ($value == $pValue) { $warning = true; }
                            }
                            else
                            {
                                if ($value <= $pValue) { $warning = true; }
                            }
                            break;
                        }
                    }
                }
                if ($warning) { break; }
            }
        }
			if ($warning == false)
			{
			SetValueString($VariableLoctionID, "");
			}
			else
			{
			SetValueString($VariableLoctionID, IPS_GetLocation($VariableID));
			}
			
        SetValueBoolean($VariableWarningID, $warning);
        IPS_SetScriptTimer($IPS_SELF, $Interval * 60);
    }

    	function CreateVariableByName($id, $name, $type)
	{
    	$vid = @IPS_GetVariableIDByName($name, $id);
    	if($vid === false)
    	{
        $vid = IPS_CreateVariable($type);
        IPS_SetParent($vid, $id);
        IPS_SetName($vid, $name);
        IPS_SetInfo($vid, "This Variable was created by Script #".$_IPS['SELF']);
    	}
    	return $vid;
	}
?>

Hi,

hab mal das Script ausgegraben, anscheinend hat es irgendwo einen Fehler, da immer bei
Ausführung ein Fehler kreiert wird, d.h. es wird immer der Standort des Scripts als Fehler
angezeigt und auf True gesetzt, wenn keine Batterie low ist.

Vielleicht kann mir da jemand helfen.

Gruß
My

Evtl. für jemanden von Interesse … ich habe das Skript mal auf Stand gebracht


<?php

/*****
    * STAND 18-07-2020
    * Überprüfung aller Geräte auf Batterieprobleme
    *
    * Dieses Skript richtet beim Aufruf eine automatische Batterieprüfung ein.
    * Wird es über das WebFront aufgerufen erscheint eine Liste der problematischen
    * Geräte.
    *
    * Alle Geräte, deren Batteriestatus bereits ein Variablenprofil besitzet, werden
    * automatisch erkannt. Für alle anderen Variablen ist dies manuell nachzuholen.
    *
    * Anleitung:
    * - Intervall nach belieben anpassen.
    * - Bei entsprechender Kenntnis eventuell die Profilliste erweitern.
    * - Skript zur Ausführung bringen, um Timer und Warnungs-Variable zu erstellen.
    *
    *****/

    /***** Konfiguration *****/

    $Interval = 360;    // Kontrollintervall in Minuten
    
    // Variablenprofile mit Werten, bei deren Erreichen oder Unterschreitung gewarnt wird
    $Profiles = array("~Battery" => true, "~Battery.Reversed" => false, "~Battery.100" => 25);


    /***** Programmcode (ab hier nichts mehr verändern) *****/

    $VariableWarningID = CreateVariableByName($_IPS['SELF'], "Warnung", 0, "~Battery");
    $VariableLoctionID = CreateVariableByName($_IPS['SELF'], "Standort", 3, "~String");

    if ($_IPS['SENDER'] == "WebFront")
    {
        $result = "";

        $VariableIDs = IPS_GetVariableList();
        foreach($VariableIDs as $VariableID)
        {
           if ($VariableID != $VariableWarningID)
           {
                $variableData = IPS_GetVariable($VariableID);
                $value = GetValue($VariableID);
                $profileName = IPS_VariableProfileExists($variableData['VariableProfile']) ? $variableData['VariableProfile'] : "";
                $profileName = (strlen($variableData['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variableData['VariableCustomProfile'])) ? $variableData['VariableCustomProfile'] : $profileName;

                $warning = false;
                if (strlen($profileName) > 0)
                {
                    foreach ($Profiles as $pName => $pValue)
                    {
                        if ($profileName == $pName)
                        {
                            if (is_bool($pValue))
                            {
                                if ($value == $pValue) { $warning = true; }
                            }
                            else
                            {
                                if ($value <= $pValue) { $warning = true; }
                            }
                            break;
                        }
                    }
                }

                if ($warning)
                {
                    $result .= "<em>".IPS_GetLocation($VariableID)."</em>: ".GetValueFormatted($VariableID)."<br />";
                }
            }
        }

        if ($result == "")
        {
            echo "Keine Probleme bekannt.";
            SetValueBoolean($VariableWarningID, false);
        }
        else
        {
            echo "Geräte mit Batterieproblemen:<br /><br />".$result;
            SetValueBoolean($VariableWarningID, true);
        }
        IPS_SetScriptTimer($_IPS['SELF'], $Interval * 60);
    }
    else
    {
        $warning = false;

        $VariableIDs = IPS_GetVariableList();

        foreach ($VariableIDs as $VariableID)
        {
           if ($VariableID != $VariableWarningID)
           {
                $variableData = IPS_GetVariable($VariableID);
                $value = GetValue($VariableID);
                $profileName = IPS_VariableProfileExists($variableData['VariableProfile']) ? $variableData['VariableProfile'] : "";
                $profileName = (strlen($variableData['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variableData['VariableCustomProfile'])) ? $variableData['VariableCustomProfile'] : $profileName;

                $warning = false;
                if (strlen($profileName) > 0)
                {
                    foreach ($Profiles as $pName => $pValue)
                    {
                        if ($profileName == $pName)
                        {
                            if (is_bool($pValue))
                            {
                                if ($value == $pValue) { $warning = true; }
                            }
                            else
                            {
                                if ($value <= $pValue) { $warning = true; }
                            }
                            break;
                        }
                    }
                }
                if ($warning) { break; }
            }
        }
            if ($warning == false)
            {
            SetValueString($VariableLoctionID, "");
            }
            else
            {
            SetValueString($VariableLoctionID, IPS_GetLocation($VariableID));
            }
            
        SetValueBoolean($VariableWarningID, $warning);
        IPS_SetScriptTimer($_IPS['SELF'], $Interval * 60);
    }

        function CreateVariableByName($id, $name, $type)
    {
        $vid = @IPS_GetVariableIDByName($name, $id);
        if($vid === false)
        {
        $vid = IPS_CreateVariable($type);
        IPS_SetParent($vid, $id);
        IPS_SetName($vid, $name);
        IPS_SetInfo($vid, "This Variable was created by Script #".$_IPS['SELF']);
        }
        return $vid;
    }


1 „Gefällt mir“

Hallo,

ich habe homematic Heizkörperthermostate, da ist unter maintenance eine Boolean Variable für die Batterie mit Profil „~Battery“ Status = TRUE, aber die wird im Webfront nicht mit angezeigt. Woran kann das liegen?

Gruß

Oliver

Mach mal ein Bild von deinem Baum. Evtl. ist im WebFront die Verschachtelung nicht aktiv und du hast die Instanzen sehr tief geschachtelt?

paresy