Tabelle aller Temperaturen

Hi,
ich habe gerne übersichtliche Tabellen von allen Messwerten. Bisher hatte ich alle Variablen mit dem WebFront einzeln verlinkt, so wie es ein Anfänger (<2 Jahre dabei) halt macht. Meine smarten Anfänge liegen aber schon relativ weit zurück und es gibt ein Sammelsurium an Sensorwerten von Dect, Z-Wave, Wetter-Station, Feinstaubsensor und nicht zuletzt Zigbee.

Vor einigen Wochen wollte ich die Instanzen rekursiv nach Temperaturen absuchen aber paresy hat mich abgehalten und mir einen besseren Weg gezeigt:-) IPS_GetVariableList war meine Rettung.

Vielleicht hilft das Ergebnis ja auch anderen Benutzern.

Dieses Script durchsucht alle Variablen nach den (Custom)Profilen ‚~Temperature‘ und merkt sich Parent (Sensornamen), GParent (bei mir Zimmername), Wert und letzte Aktualisierung bzw. Änderung. Sortiert wird die Tabelle zuerst nach Zimmer und dann nach Sensor. Bei der ersten Ausführung des Scriptes wird ein zyklisches 15 Minuten Ereignis und eine HTML-Variable erzeugt die man jetzt nur noch mit dem Web-Front verlinken muss.

Dank HTML kann man auch Zusatzinformationen in die Werte einbauen. In diesem Beispiel ist es so das Temperaturen < 0 und > 40 Grad in Rot und < 10 Grad in Gelb dargestellt werden. Bei den Aktualisierungen wird Gelb dargestellt wenn eine Variable > 1 Tag nicht aktualisiert wurde und Rot bei > 7 Tagen. So kann man leicht sehen welche Sensoren Probleme haben könnten und in welchen Zimmern es Temperaturprobleme gibt.

<?php
$UpdateList = array();
$VariableIDsList = IPS_GetVariableList();

foreach ($VariableIDsList as $VariableID) {
    $Variable = IPS_GetVariable($VariableID);
    if (($Variable['VariableProfile'] == '~Temperature') || ($Variable['VariableCustomProfile'] == '~Temperature')){
        $Parent = IPS_GetParent($VariableID);
        $GParent = IPS_GetParent($Parent);
        $Index = count($UpdateList);
        $UpdateList[$Index]['VariableID'] = $VariableID;
        $UpdateList[$Index]['Name'] = IPS_GetName($VariableID);
        $UpdateList[$Index]['ParentName'] = IPS_GetName($Parent);
        $UpdateList[$Index]['GParentName'] = IPS_GetName($GParent);
        $UpdateList[$Index]['LastChanged'] = $Variable['VariableChanged'];
        $UpdateList[$Index]['LastUpdated'] = $Variable['VariableUpdated'];
        $UpdateList[$Index]['Value'] = $Variable['VariableValue'];
    }
}

$Zimmer  = array_column($UpdateList, 'GParentName');
$Name = array_column($UpdateList, 'Name');
array_multisort($Zimmer, SORT_ASC, $Name, SORT_ASC, $UpdateList);

// HTML ereugen
$HintergrundFarbcode = '000000';
$TextFarbcode = 'FFFFFF';
$TextFarbcodeOK = '00FF00';
$TextFarbcodeNOK = 'FF0000';
$TextFarbcodeACHTUNG = 'FFFF00';
$TextSize = 14;
$TextSizeTitle = $TextSize + 2;
$TextWeight = 'normal';
$Textausrichtung = 'text-align:left;';

$HTML_CSS_Style = '<style type="text/css">
.bt {border-collapse: separate;border-spacing: 2px;}
.bt td {font-family:Arial, sans-serif;font-size:' . $TextSize . 'px;color:#' . $TextFarbcode . ';' . $Textausrichtung . 'padding:1px 10px;border-style:solid;border-width:1px;overfNOK:hidden;word-break:normal;}
.bt th {font-family:Arial, sans-serif;font-size:' . $TextSize . 'px;color:#' . $TextFarbcode . ';' . $Textausrichtung . 'padding:1px 10px;border-style:solid;border-width:1px;overfNOK:hidden;word-break:normal;}
.bt .tb-title {font-size:' . $TextSizeTitle . 'px;padding:2mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcode . '}
.bt .tb-contentNORMAL {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;text-align:left;background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcode . '}
.bt .tb-content {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcode . '}
.bt .tb-contentOK {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeOK . '}
.bt .tb-contentNOK {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeNOK . '}
.bt .tb-contentACHTUNG {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeACHTUNG . '}
</style>';

$HTML = '<html>' . $HTML_CSS_Style;
$HTML .= '<table class="bt"';

$Titel = array();
$Titel = array('Instanz-ID');
$Titel[] = 'Sensor';
$Titel[] = 'Zimmer';
$Titel[] = 'Name';
$Titel[] = 'Letzte Var-Änderung';
$Titel[] = 'Letzte Var-Aktualisierung';
$Titel[] = 'Temperatur';

$HTML .= '<tr>';

$colspan = 1;
foreach ($Titel as $TitelEntry) {
    $HTML .= '<th class="tb-title"><b>' . $TitelEntry . '</b></th>';
    $colspan++;
}
$HTML .= '</tr><tr>';

foreach ($UpdateList as $Update) {
    $HTML .= '<th class="tb-content">' . $Update['VariableID'] . '</th>';
    $HTML .= '<th class="tb-contentNORMAL">' . $Update['ParentName'] . '</th>';
    $HTML .= '<th class="tb-contentNORMAL">' . $Update['GParentName'] . '</th>';
    $HTML .= '<th class="tb-contentNORMAL">' . $Update['Name'] . '</th>';
    $HTML .= '<th class="tb-content">' . date('d.m.Y H:i', $Update['LastChanged']) . '</th>';
    if ($Update['LastUpdated'] > 0){
        if ((time() - $Update['LastUpdated']) > 7*86400){
            $HTML .= '<th class="tb-contentNOK">' . date('d.m.Y H:i', $Update['LastUpdated']) . '</th>';
        }
        else if ((time() - $Update['LastUpdated']) > 1*86400){
            $HTML .= '<th class="tb-contentACHTUNG">' . date('d.m.Y H:i', $Update['LastUpdated']) . '</th>';
        }
        else $HTML .= '<th class="tb-content">' . date('d.m.Y H:i', $Update['LastUpdated']) . '</th>';
    }
    if (($Update['Value'] < 0) || ($Update['Value'] > 40)){
        $HTML .= '<th class="tb-contentNOK">' . number_format($Update['Value'], 1) . 'C°</th>';
    }
    else if ($Update['Value'] < 10){
        $HTML .= '<th class="tb-contentACHTUNG">' . number_format($Update['Value'], 1) . 'C°</th>';
    }
    else{
        $HTML .= '<th class="tb-content">' . number_format($Update['Value'], 1) . 'C°</th>';
    }

    $HTML .= '</tr>';
}
$HTML .= '</table></html>';
$vid = @IPS_GetVariableIDByName("Temperatur-Tabelle", $_IPS['SELF']);

if ($vid == false){
    $vid = IPS_CreateVariable(3);
    IPS_SetParent($vid, $_IPS['SELF']);             //Variable zuordnen
    IPS_SetName($vid, "Temperatur-Tabelle");
    IPS_SetVariableCustomProfile($vid, "~HTMLBox");
}

SetValue( $vid, $HTML);

if (@IPS_GetEventIDByName("CheckTemperatur", $_IPS['SELF']) == false){
    $eid = IPS_CreateEvent(1);                      //Zyklisches Ereignis
    IPS_SetEventCyclic($eid, 2, 1, 0, 0, 2, 15);    //Jeden Tag alle 15 Minuten
    IPS_SetParent($eid, $_IPS['SELF']);             //Ereignis zuordnen
    IPS_SetEventActive($eid, true);                 //Ereignis aktivieren    
    IPS_SetName($eid, "CheckTemperatur");
}

/*
foreach ($UpdateList as $Update){
    var_dump($Update);
}
*/
?>

Nach dem selben Prinzip habe ich auch Tabellen für Luftdruck, Luftfeuchtigkeit, Stromverbrauch und Zigbee-Geräte erstellt.

Anbei noch ein Bild wie die Tabelle bei mir aussieht:

Ach ja die Mittelwerte in der Tabelle stammen von Scripten die bei einigen Zimmern den Mittelwert der Sensoren berechnen.

Viel Spaß Ralf

3 „Gefällt mir“


Vielen Dank für diese Vorlage!!
Mit kleinen Änderungen und mit Hilfe von AC_GetAggregatedValues konnte ich meine WunschTabelle mit allen Stromverbrauchern basteln. Dein Script war die perfekte Vorlage dazu !!!
Gruß
Fritz

Ja, das Script ist eine hervorragende Vorlage um gezielt eine HTML-Vorlage auch in IPSVIEW zu erstellen.
Und @Fritzvd Dein Script mit den geloggten Daten ist sicher auch interessant.

Ich bin allerdings kein Programmierer … eher Tüftler:

.das fängt schon damit an, dass ich nicht weiß, wie man Script-code vernünftig posted …

Hi,
ich poste Code immer indem ich auf das </> klicke dann kommt auch ein Text wo Du den Code einfügen sollst.

Ralf

Danke! :slight_smile:
Hier ist der erweiterte Code mit der Liste und den AC_GetAggregatedValues Berechnungen.

<?php

$UpdateList = array();
$VariableIDsList = IPS_GetVariableList();
$ergebnis=0;
$Archiv=32798; //ID vom Archiv 


foreach ($VariableIDsList as $VariableID) {
    $Variable = IPS_GetVariable($VariableID);
    $sumd = 0;
    $sumw = 0;
    $summ = 0;
    if (($Variable['VariableProfile'] == '~Electricity') || ($Variable['VariableCustomProfile'] == '~Electricity')){
        $Parent = IPS_GetParent($VariableID);
        $GParent = IPS_GetParent($Parent);
        $GGParent = IPS_GetParent($GParent);
        $Index = count($UpdateList);
        $UpdateList[$Index]['VariableID'] = $VariableID;
        $UpdateList[$Index]['Name'] = IPS_GetName($VariableID);
        $UpdateList[$Index]['ParentName'] = IPS_GetName($Parent);
        $UpdateList[$Index]['GParentName'] = IPS_GetName($GParent);
        $UpdateList[$Index]['GGParentName'] = IPS_GetName($GGParent);     
        $UpdateList[$Index]['Value'] = $Variable['VariableValue'];

            $werte = AC_GetAggregatedValues($Archiv, $VariableID, 1 /* Stündlich */, strtotime("yesterday 00:00"), strtotime("yesterday 23:59")-1, 0);
            foreach($werte as $wertd) {
            $sumd+= $wertd['Avg'];
            }  
        $UpdateList[$Index]['kwhyesterday'] = $sumd;
        
            $werte = AC_GetAggregatedValues($Archiv, $VariableID, 2 /* Wöchentlich */, strtotime("monday last week 00:00"), strtotime("sunday last week 23:59")-1, 0);
           foreach($werte as $wertw) {
            $sumw+= $wertw['Avg'];
            }  
        $UpdateList[$Index]['kwhyesterweek'] = $sumw;

           $werte = AC_GetAggregatedValues($Archiv, $VariableID, 2 /* Wöchentlich */, strtotime("first day of last month 00:00"), strtotime("last day of last month 23:59")-1, 0);
           foreach($werte as $wertm) {
            $summ+= $wertm['Avg'];
            }  
        $UpdateList[$Index]['kwhyestermon'] = $summ;

  }
}

$Zimmer  = array_column($UpdateList, 'GParentName');
$Name = array_column($UpdateList, 'Name');
$Wert = array_column($UpdateList, 'Value');
$Wertd = array_column($UpdateList, 'kwhyesterday');
$Wertw = array_column($UpdateList, 'kwhyesterweek');
$Wertm = array_column($UpdateList, 'kwhyestermon');
array_multisort($Wert, SORT_DESC, $Name, SORT_ASC, $UpdateList);

// HTML erzeugen
$HintergrundFarbcode = '000000';
$TextFarbcode = 'FFFFFF';
$TextFarbcodeOK = '00FF00';
$TextFarbcodeNOK = 'FF0000';
$TextFarbcodeACHTUNG = 'FFFF00';
$TextSize = 15;
$TextSizeTitle = $TextSize + 2;
$TextWeight = 'normal';
$Textausrichtung = 'text-align:left;';
$Textausrichtungvalue = 'text-align:right;';

$HTML_CSS_Style = '<style type="text/css">
.bt {border-collapse: collapse;border-spacing: 0;}
.bt td {font-family:Arial, sans-serif;font-size:' . $TextSize . 'px;color:#' . $TextFarbcode . ';' . $Textausrichtung . 'padding:1px 10px;border-style:none;border-bottom:solid;border-bottom-color:white;border-width:1px;overfNOK:hidden;word-break:normal;}
.bt th {font-family:Arial, sans-serif;font-size:' . $TextSize . 'px;color:#' . $TextFarbcode . ';' . $Textausrichtung . 'padding:1px 10px;border-style:none;border-bottom:solid;border-bottom-color:white;border-width:1px;overfNOK:hidden;word-break:normal;}
.bt .tb-title {font-size:' . $TextSizeTitle . 'px;padding:2mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcode . '}
.bt .tb-contentNORMAL {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;text-align:left;background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcode . '}
.bt .tb-content {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcode . '}
.bt .tb-contentOK {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeOK . '}
.bt .tb-contentNOK {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeNOK . '}
.bt .tb-contentACHTUNG {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtung . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeACHTUNG . '}
.bt .tb-val-content {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtungvalue . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcode . '}
.bt .tb-val-contentOK {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtungvalue . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeOK . '}
.bt .tb-val-contentNOK {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtungvalue . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeNOK . '}
.bt .tb-val-contentACHTUNG {font-size:' . $TextSize . 'px;font-weight: ' . $TextWeight . ';padding:1mm;' . $Textausrichtungvalue . 'background-color:#' . $HintergrundFarbcode . ';color:#' . $TextFarbcodeACHTUNG . '}
</style>';

$HTML = '<html>' . $HTML_CSS_Style;
$HTML .= '<table class="bt"';

$Titel = array();
$Titel = array('Platz');
//                      Ausblenden Sensor
//  $Titel[] = 'Sensor';
$Titel[] = 'Instanz-ID';
$Titel[] = 'Bereich';
$Titel[] = 'Name';
$Titel[] = 'Gestern';
$Titel[] = 'Vorwoche';
$Titel[] = 'Vormonat';
$Titel[] = 'Zähler';

$HTML .= '<tr>';

$colspan = 1;
foreach ($Titel as $TitelEntry) {
    $HTML .= '<th class="tb-title"><b>' . $TitelEntry . '</b></th>';
    $colspan++;
}
$HTML .= '</tr><tr>';

    $Anzahl = 0;

foreach ($UpdateList as $Update) {
    // Zeilen ausfiltern
     If ($Update['GParentName'] == 'Solar' ) {
    continue;}
  if (strpos($Update['Name'], 'LP2') !== false) {
    continue;}
  if (strpos($Update['Name'], 'LP3') !== false) {
    continue;}
// Zeilen ausfiltern ENDE
    $Anzahl = $Anzahl +1;
    $HTML .= '<th class="tb-content">' . $Anzahl . '</th>'; 
// echo "Variable " . $VariableID .  " Nummer " . $Anzahl . " " .PHP_EOL;
    $HTML .= '<th class="tb-content">' . $Update['VariableID'] . '</th>';
// Ausblenden Sensor und Bereich
//  $HTML .= '<th class="tb-contentNORMAL">' . $Update['ParentName'] . '</th>';
//    $HTML .= '<th class="tb-contentNORMAL">' . $Update['GParentName'] . '</th>';
    $HTML .= '<th class="tb-contentNORMAL">' . $Update['GGParentName'] . '</th>';
    $HTML .= '<th class="tb-contentNORMAL">' . $Update['Name'] . '</th>';
// kwh gestern formatieren
    if (($Update['kwhyesterday'] < 0) || ($Update['kwhyesterday'] > 1)){
        $HTML .= '<th class="tb-val-contentNOK">' . number_format($Update['kwhyesterday'], 1) . ' </th>';
    }
    else if ($Update['kwhyesterday'] < 1){
        $HTML .= '<th class="tb-val-contentACHTUNG">' . number_format($Update['kwhyesterday'], 1) . ' </th>';
    }
    else{
        $HTML .= '<th class="tb-val-content">' . number_format($Update['kwhyesterday'], 1) . ' </th>';
    }
// kwh letzte Woche formatieren
        if (($Update['kwhyesterweek'] < 0) || ($Update['kwhyesterweek'] > 10)){
        $HTML .= '<th class="tb-val-contentNOK">' . number_format($Update['kwhyesterweek'], 1) . ' </th>';
    }
    else if ($Update['kwhyesterweek'] < 1){
        $HTML .= '<th class="tb-val-contentACHTUNG">' . number_format($Update['kwhyesterweek'], 1) . ' </th>';
    }
    else{
        $HTML .= '<th class="tb-val-content">' . number_format($Update['kwhyesterweek'], 1) . ' </th>';
    }
// kwh letzter Monat formatieren
        if (($Update['kwhyestermon'] < 0) || ($Update['kwhyestermon'] > 100)){
        $HTML .= '<th class="tb-val-contentNOK">' . number_format($Update['kwhyestermon'], 1) . ' </th>';
    }
    else if ($Update['kwhyestermon'] < 1){
        $HTML .= '<th class="tb-val-contentACHTUNG">' . number_format($Update['kwhyestermon'], 1) . ' </th>';
    }
    else{
        $HTML .= '<th class="tb-val-content">' . number_format($Update['kwhyestermon'], 1) . ' </th>';
    }
// kwh aktueller Zähler formatieren
    if (($Update['Value'] < 0) || ($Update['Value'] > 40)){
        $HTML .= '<th class="tb-val-contentNOK">' . number_format($Update['Value'], 0) . ' </th>';
    }
    else if ($Update['Value'] < 1){
        $HTML .= '<th class="tb-val-contentACHTUNG">' . number_format($Update['Value'], 0) . ' </th>';
    }
    else{
        $HTML .= '<th class="tb-val-content">' . number_format($Update['Value'], 0) . ' </th>';
    }

    $HTML .= '</tr>';
}
$HTML .= '</table></html>';
$vid = @IPS_GetVariableIDByName("kwh-Tabelle", $_IPS['SELF']);

if ($vid == false){
    $vid = IPS_CreateVariable(3);
    IPS_SetParent($vid, $_IPS['SELF']);             //Variable zuordnen
    IPS_SetName($vid, "kwh-Tabelle");
    IPS_SetVariableCustomProfile($vid, "~HTMLBox");
}
SetValue (27692,$Anzahl);
SetValue( $vid, $HTML);

if (@IPS_GetEventIDByName("Checkkwh", $_IPS['SELF']) == false){
    $eid = IPS_CreateEvent(1);                      //Zyklisches Ereignis
    IPS_SetEventCyclic($eid, 2, 1, 0, 0, 2, 15);    //Jeden Tag alle 15 Minuten
    IPS_SetParent($eid, $_IPS['SELF']);             //Ereignis zuordnen
    IPS_SetEventActive($eid, true);                 //Ereignis aktivieren    
    IPS_SetName($eid, "Checkkwh");
}

/*
foreach ($UpdateList as $Update){
    var_dump($Update);
}
*/
?>

die andere Werte und die Überschrift sind dann in IPSView dazugekommen.

Gefällt mir sehr gut!
Danke auch an die Vorarbeit von @HarmonyFan !

@Fritzvd wie hast Du die Sortierung der Energiewerte erreicht?
Hab ich schon mal versucht und nicht hinbekommen. Ist das im Skript enthalten oder hast Du das schon vorab sortiert vorliegen?

Merci
Seppm

Hi,
bei mir ist es das schweizer Taschenmesser der Sortierung von Arrays.

Ralf