PHP-Code:
/*Alarmhandlingskript by SCS-Showtec GbR
Jakob-Degen-Straße 64
73614 Schorndorf
Autor :Johannes Holzwarth
Verison 2.1 08.01.2019*/
//die Funktion für das anlegen der Child Variablen
function CreateVariableByName($id, $name, $type, $profile = "", $icon = "", $pos = 0, $hidden=true)
{
global $_IPS;
$vid = @IPS_GetVariableIDByName($name, $id);
if($vid === false)
{
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, $id);
IPS_SetName($vid, $name);
IPS_SetPosition($vid, $pos);
IPS_SetIcon($vid, $icon);
IPS_SetHidden($vid, $hidden);
IPS_SetVariableCustomProfile($vid, $profile);
IPS_SetInfo($vid, "diese Variable wurde von Nerds aus einer weit entfernten Galaxie mit folgender Nummer angelegt #".$_IPS['SELF']);
}
return $vid;
}
//die Funktion fürs Alarmhandling an sich
function SmTrigger($trigid, $smname, $opt, $webfrontid, $wfcnot, $pushnot, $telnot, $mail)
{
switch ($opt) { //verschiedene Arten von Meldungen definieren
case 0:
$art = "Anlagenname | Störung:";
$ico = "Flame";
break;
case 1:
$art = "Anlagenname | Warnung:";
$ico = "Warning";
break;
case 2:
$art = "Anlagenname | Info:";
$ico = "Information";
break;
case 100:
$art = "Anlagenname | Alarm:";
$ico = "Flame";
break;
}
$smid = CreateVariableByName($_IPS['SELF'], $smname, 0, $profile = "", $icon = "", $pos = 0, $hidden=true);
if ($trigid && GetValueBoolean($smid)) {
SetValueBoolean($smid, false);
//Hier einmalig (bei High-Flanke) auszuführende Aktion eintragen!!!
$datum = date("d.m.Y");
$uhrzeit = date("H:i");
$filename = 'c:\\AlarmsAndNotifications.txt'; //Pfad zur Speicherung als Textdatei
$wert = ($datum ."-".$uhrzeit ." --> ". $art ." ". $smname ."\r\n");
$datei = fopen($filename, "a+");
fwrite($datei, $wert);
fclose($datei);
if ($telnot) { //als Telegrammessage versenden
//Telegram_SendText(, "".$art." ".$smname, /*deine Telegram ID*/);
};
if ($wfcnot){ //Ans Webfront senden // Wer mehrere Webfronts hat einfach die nachfolgende Zeile kopieren
WFC_SendNotification($webfrontid, $art, $smname, $ico, 0);
}
if ($pushnot){ //Pushnotification
WFC_PushNotification($webfrontid, $art, $smname, "", 0);
}
if ($mail){ //Als Mail versenden
//SMTP_SendMail(12345, $art, $smname);
}
}
elseif ($trigid == false) {
SetValueBoolean($smid, true);
}
}
/// Die ID des zu benachrichtigenden Webfronts
$WebfrontId = 123456;
$ids = IPS_GetChildrenIDs($_IPS['SELF']);
//Alle Childobjekte abholen
foreach($ids as $id) { //Alle Childs durchgehen
$names[$id] = IPS_GetName($id);
$werte[$id] =! GetValue($id);
$both[$id]['Value'] = $werte[$id];
$both[$id]['Name'] = $names[$id];
}
foreach($both as $bot) {
if ($bot['Value'] == 1) { // Farbe und Text der Html Tabelle erstellen
$color = 'red';
$bot['Value'] = 'Störung';
}
else
{// Farbe und Text fürOK
$color = 'lightgreen';
$bot['Value'] = 'OK';
}
$tdhtml .= '<tr><td>'.$bot['Name'].'</td><td bgcolor='.$color.'>'.$bot['Value'].'</td></tr>'; //Werte in Tabelle schreiben
}
$html = '<table width=100%><tr><th>Name</th><th>Status</th></tr>'.$tdhtml.'</table>'; //html Tabelle erstellen
SetValueString(123456, $html); // in Html Box schreiben
SmTrigger (GetValueBoolean(), "", 0, $WebfrontId, true, true, true, false); //Pro Störung einmal anlegen