oder besser: des Ferengie Masters neues Wecker Webfront Interface.
Nicht, dass es hier großartig was zum Verbessern gebe, aber ich habe die GUI des Weckers etwas meinen Bedürfnissen angepasst. Zum einen brauche ich keine unterschiedlichen Einstellungen für jeden Tag (Weckzeit, Schlummermodus, …) und zum anderen passte die vorhandene GUI nicht ganz auf meinen 10“ Touchscreen. Das File mit den Wecker Daten bildet hier natürlich die ideale Kommunikations Schnittstelle.
Das Script legt bei der manuellen Ausführung alle benötigten Variablen an, Webfront muss man noch manuell einrichten, ein iPhone Interface habe ich bei der Gelegenheit auch gleich wieder angelegt (wenn der Pfad gesetzt ist).
Vorraussetzung ist für dieses Script ist mein IPSInstaller (einfach im scripts Verzeichnis ablegen) und natürlich der Ferengi Wecker
Installation
[ul]
[li]FerengiWecker nach Anleitung installieren und die benötigten Wecker einrichten.
[/li][li]Script AlaramClock anlegen, Pfade anpassen, Weckerliste anpassen (Wecker müssen bereits vorhanden sein) und Scirpt ausführen
[/li][li]Webfront Installation:
[/li][LIST]
[li]Container anlegen, ElementID=AlarmClock, horizontal, 440 Pixel, Name und Icon nach Wahl
[/li][li]Container anlegen, ElementID=AlarmClock_Top, Übergeordnet=AlarmClock, vertical, 400 Pixel, Position=10
[/li][li]Kategorie anlagen, Übergeordnet=AlarmClock_Top, Root=WebFront.Wecker, Position=10
[/li][li]Kategorie anlagen, Übergeordnet=AlarmClock_Top, Root=WebFront.Wecker.Top2, Position=20
[/li][li]Container anlegen, ElementID=AlarmClock_Bottom, Übergeordnet=AlarmClock, vertical, 50%, Position=20
[/li][li]Kategorie anlagen, Übergeordnet=AlarmClock_Bottom, Root=WebFront.Wecker.Bottom1, Position=10
[/li][li]Kategorie anlagen, Übergeordnet=AlarmClock_Bottom, Root=WebFront.Wecker.Bottom2, Position=20
[/li][/ul]
[/LIST]
<?
//Script IPSInstaller.ips.php muss zur Installation im scipts Ordner vorhanden sein !
define ("c_WeckerFileName", IPS_GetKernelDir()."automatic/wecker.txt"); // Ablageort für für wecker.txt (siehe Ferengi Wecker)
define ("c_WeckerPath", 'Program.AlarmClock.Wecker'); // Pfad, wo der Ferengi Wecker liegt
define ("c_ProgramPath", 'Program.AlarmClock'); // Pfad für Programm Daten
define ("c_WebfrontPath", 'Webfront.Wecker'); // Pfad für Webfront Installation
define ("c_iPhonePath", 'iPhone.Wecker'); // Pfad für iPhone Installation
define ("c_AlarmClockPrefix", 'AlarmClock'); // dieser String dient als Prefix für jeden Wecker Namen
// Liste der Wecker
$AlarmClockList = array('Andreas', 'MeinGeliebtesWeib', 'Familie');
// Wecker sollten vor der Installation bereits vorhanden sein.
// Zum Anlegen eines Weckers folgenden Code in das Wecker Script eintragen.
// if ($IPS_SENDER=='Execute') {
// $IPS_SENDER ='WebFront';
// $IPS_VARIABLE = 21857;
// $IPS_VALUE = 'NeuerWeckerName'; // (Prefix+WeckerName)
// }
// ----------------------------------------------------------------------------------------------------------------------------
// Programm Code, ab hier nichts mehr ändern !
// ----------------------------------------------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------------------------------------------
if ($IPS_SENDER=='Execute') {
AlarmClockInstallation($IPS_SELF, $AlarmClockList);
} elseif ($IPS_SENDER=='WebFront') {
$ControlList = array('Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag',
'Sonntag', 'Active', 'SlumberMode', 'Hour', 'Minute', 'HolidayActive');
$ControlName = IPS_GetName($IPS_VARIABLE);
$AlarmClockName = c_AlarmClockPrefix.GetValue(get_ControlId('Name'));
if (array_key_exists($ControlName, array_flip($ControlList))) {
SetValue($IPS_VARIABLE, $IPS_VALUE);
SetAlarmClockData();
} elseif ($ControlName=='Select') {
$AlarmClockName = c_AlarmClockPrefix.$AlarmClockList[$IPS_VALUE];
SetValue($IPS_VARIABLE, $IPS_VALUE);
SetValue(get_ControlId('Name'), $IPS_VALUE);
} else {
die("Unknown Control '$ControlName'");
}
GetAlarmClockData($AlarmClockName);
} else {
// Nothing todo ...
}
// ----------------------------------------------------------------------------------------------------------------------------
function SetAlarmClockDataByDay($AlarmClockData, $DayOfWeek, $Idx) {
$AlarmClockData[$Idx+1] = $DayOfWeek; // Wochentag
$AlarmClockData[$Idx+2] = str_pad(GetValue(get_ControlId('Hour')),2,'0', STR_PAD_LEFT); // Stunde
$AlarmClockData[$Idx+3] = str_pad(GetValue(get_ControlId('Minute')),2,'0', STR_PAD_LEFT); // Minute
$AlarmClockData[$Idx+4] = BooleanToNumber(GetValue(get_ControlId('HolidayActive'))); // Feiertag
$AlarmClockData[$Idx+5] = BooleanToNumber(GetValue(get_ControlId('SlumberMode'))); // Schlummermodus
$AlarmClockData[$Idx+6] = BooleanToNumber(GetValue(get_ControlId($DayOfWeek))); // Tageswecker
$AlarmClockData[$Idx+7] = BooleanToNumber(GetValue(get_ControlId('Active'))); // Wochenwecker
}
// ----------------------------------------------------------------------------------------------------------------------------
function SetAlarmClockData() {
$Name = c_AlarmClockPrefix.GetValue(get_ControlId('Name'));
$AlarmClockData = explode(",", file_get_contents(c_WeckerFileName));
foreach($AlarmClockData as $Idx=>$Value) {
if ($Value == $Name) break;
}
if ($Idx>=count($AlarmClockData)-1) die("AlarmClock '$Name' could NOT be found in File, Check Installation!");
SetAlarmClockDataByDay(&$AlarmClockData, 'Montag', $Idx);
SetAlarmClockDataByDay(&$AlarmClockData, 'Dienstag', $Idx=$Idx+8);
SetAlarmClockDataByDay(&$AlarmClockData, 'Mittwoch', $Idx=$Idx+8);
SetAlarmClockDataByDay(&$AlarmClockData, 'Donnerstag', $Idx=$Idx+8);
SetAlarmClockDataByDay(&$AlarmClockData, 'Freitag', $Idx=$Idx+8);
SetAlarmClockDataByDay(&$AlarmClockData, 'Samstag', $Idx=$Idx+8);
SetAlarmClockDataByDay(&$AlarmClockData, 'Sonntag', $Idx=$Idx+8);
$handle = fopen(c_WeckerFileName, "w");
fwrite($handle, implode(",", $AlarmClockData));
fclose($handle);
}
// ----------------------------------------------------------------------------------------------------------------------------
function GetAlarmClockData($AlarmClockName) {
$FileContent = file_get_contents(c_WeckerFileName);
$AlarmClockData = explode(",", $FileContent);
$Found = false;
foreach($AlarmClockData as $Idx=>$Value) {
if ($Value == $AlarmClockName) {
$Found = true;
$DayOfWeek = $AlarmClockData[$Idx+1];
SetValue(get_ControlId('Name'), str_replace(c_AlarmClockPrefix, '', $AlarmClockData[$Idx])); // Name
SetValue(get_ControlId($DayOfWeek), NumberToBoolean($AlarmClockData[$Idx+6])); // Day OnOff
if ($DayOfWeek == 'Montag') {
SetValue(get_ControlId('Hour'), (int)$AlarmClockData[$Idx+2]); // Stunde
SetValue(get_ControlId('Minute'), (int)$AlarmClockData[$Idx+3]); // Minute
SetValue(get_ControlId('HolidayActive'), NumberToBoolean($AlarmClockData[$Idx+4])); // Feiertag
SetValue(get_ControlId('SlumberMode'), NumberToBoolean($AlarmClockData[$Idx+5])); // Schlummermodus
SetValue(get_ControlId('Active'), NumberToBoolean($AlarmClockData[$Idx+7])); // Wochenwecker
}
}
}
if (!$Found) die("AlarmClock '$AlarmClockName' could NOT be found in File, Check Installation!");
}
// ----------------------------------------------------------------------------------------------------------------------------
function get_ObjIdByPath($Path) {
$CategoryList = explode('.',$Path);
$ObjId = 0;
foreach ($CategoryList as $Idx=>$Category) {
$ObjId = IPS_GetObjectIDByName($Category, $ObjId);
if ($ObjId==null) die("'$Category' could NOT be found !!!");
}
return $ObjId;
}
// ----------------------------------------------------------------------------------------------------------------------------
function get_ControlId ($ControlName) {
$CategoryId = get_ObjIdByPath(c_ProgramPath.".Settings");
return IPS_GetVariableIDByName($ControlName, $CategoryId);
}
// ----------------------------------------------------------------------------------------------------------------------------
function NumberToBoolean($Value) {
if ($Value=='1') {
return true;
} else {
return false;
}
}
// ----------------------------------------------------------------------------------------------------------------------------
function BooleanToNumber($Value) {
if ($Value) {
return '1';
} else {
return '0';
}
}
// ----------------------------------------------------------------------------------------------------------------------------
function AlarmClockInstallation($ScriptIdChange, $AlarmClockList) {
include_once "IPSInstaller.ips.php";
// ----------------------------------------------------------------------------------------------------------------------------
// Program Installation
// ----------------------------------------------------------------------------------------------------------------------------
$CategoryIdProgram = CreateCategoryPath(c_ProgramPath);
$CategoryIdScripts = CreateCategory('Scripts', $CategoryIdProgram, 10);
$CategoryIdSetings = CreateCategory('Settings', $CategoryIdProgram, 20);
IPS_SetHidden($CategoryIdScripts, true);
// Add Scripts
IPS_SetParent($ScriptIdChange, $CategoryIdScripts);
CreateProfile_Count ('AlarmClock_Hour', 0, 1, 23, null, " Uhr", null);
CreateProfile_Count ('AlarmClock_Minute', 0, 1, 59, null, " Min", null);
CreateProfile_Associations ('AlarmClock_Select', $AlarmClockList, "");
$DayList = array("Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag");
$ControlIdMonday = CreateVariable($DayList[0], 0 /*Boolean*/, $CategoryIdSetings, 10, '~Switch', $ScriptIdChange, true);
$ControlIdTuesday = CreateVariable($DayList[1], 0 /*Boolean*/, $CategoryIdSetings, 20, '~Switch', $ScriptIdChange, true);
$ControlIdWednesday = CreateVariable($DayList[2], 0 /*Boolean*/, $CategoryIdSetings, 30, '~Switch', $ScriptIdChange, true);
$ControlIdThursday = CreateVariable($DayList[3], 0 /*Boolean*/, $CategoryIdSetings, 40, '~Switch', $ScriptIdChange, true);
$ControlIdFriday = CreateVariable($DayList[4], 0 /*Boolean*/, $CategoryIdSetings, 50, '~Switch', $ScriptIdChange, true);
$ControlIdSaturday = CreateVariable($DayList[5], 0 /*Boolean*/, $CategoryIdSetings, 60, '~Switch', $ScriptIdChange, false);
$ControlIdSunday = CreateVariable($DayList[6], 0 /*Boolean*/, $CategoryIdSetings, 70, '~Switch', $ScriptIdChange, false);
$ControlIdName = CreateVariable('Name', 3 /*String*/, $CategoryIdSetings, 100, '~String', null, '');
$ControlIdActive = CreateVariable('Active', 0 /*Boolean*/, $CategoryIdSetings, 120, '~Switch', $ScriptIdChange, false);
$ControlIdSlumber = CreateVariable('SlumberMode', 0 /*Boolean*/, $CategoryIdSetings, 120, '~Switch', $ScriptIdChange, false);
$ControlIdHoliday = CreateVariable('HolidayActive',0 /*Boolean*/, $CategoryIdSetings, 130, '~Switch', $ScriptIdChange, false);
$ControlIdHour = CreateVariable('Hour', 1 /*Integer*/, $CategoryIdSetings, 140, 'AlarmClock_Hour', $ScriptIdChange,
0, 'Clock');
$ControlIdMinute = CreateVariable('Minute', 1 /*Integer*/, $CategoryIdSetings, 150, 'AlarmClock_Minute',$ScriptIdChange,
0, 'Clock');
$ControlIdSelect = CreateVariable('Select', 1 /*Integer*/, $CategoryIdSetings, 200, 'AlarmClock_Select',$ScriptIdChange,0);
// ----------------------------------------------------------------------------------------------------------------------------
// Webfront Definition
// ----------------------------------------------------------------------------------------------------------------------------
$WebFrontOverviewId = CreateCategoryPath(c_WebfrontPath);
$WebFrontOverviewTop2 = CreateCategory('Top2', $WebFrontOverviewId, 10);
$WebFrontOverviewBottom1 = CreateCategory('Bottom1', $WebFrontOverviewId, 20);
$WebFrontOverviewBottom2 = CreateCategory('Bottom2', $WebFrontOverviewId, 30);
IPS_SetHidden($WebFrontOverviewTop2, true);
IPS_SetHidden($WebFrontOverviewBottom1, true);
IPS_SetHidden($WebFrontOverviewBottom2, true);
// Overview Data
CreateLink('Montag', $ControlIdMonday, $WebFrontOverviewId, 10);
CreateLink('Dienstag', $ControlIdTuesday, $WebFrontOverviewId, 20);
CreateLink('Mittwoch', $ControlIdWednesday, $WebFrontOverviewId, 30);
CreateLink('Donnerstag', $ControlIdThursday, $WebFrontOverviewId, 40);
CreateLink('Freitag', $ControlIdFriday, $WebFrontOverviewId, 50);
CreateLink('Samstag', $ControlIdSaturday, $WebFrontOverviewId, 60);
CreateLink('Sonntag', $ControlIdSunday, $WebFrontOverviewId, 70);
CreateLink('Wecker Name', $ControlIdName, $WebFrontOverviewTop2, 10);
CreateLink('Wecker Aktiv', $ControlIdActive, $WebFrontOverviewTop2, 20);
CreateLink('Schlummer Modus', $ControlIdSlumber, $WebFrontOverviewTop2, 30);
CreateLink('Feiertage', $ControlIdHoliday, $WebFrontOverviewTop2, 40);
CreateLink('Stunde', $ControlIdHour, $WebFrontOverviewTop2, 50);
CreateLink('Minuten', $ControlIdMinute, $WebFrontOverviewTop2, 60);
CreateLink('Wecker Auswahl', $ControlIdSelect, $WebFrontOverviewBottom1, 10);
$MsgId = get_ObjectIDByPath(c_WeckerPath.'.wecker_meldung');
CreateLink('Wecker Meldungen', $MsgId, $WebFrontOverviewBottom2, 10);
// ----------------------------------------------------------------------------------------------------------------------------
// iPhone Definition
// ----------------------------------------------------------------------------------------------------------------------------
$iPhoneOverviewId = CreateCategoryPath(c_iPhonePath, 30, 'Clock');
$iPhoneSelect = CreateDummyInstance("Wecker Auswahl", $iPhoneOverviewId, 10);
CreateLink('Wecker Auswahl', $ControlIdSelect, $iPhoneSelect, 10);
$MsgId = get_ObjectIDByPath(c_WeckerPath.'.wecker_meldung');
CreateLink('Wecker Meldungen', $MsgId, $iPhoneSelect, 20);
$iPhoneClock = CreateDummyInstance("Wecker", $iPhoneOverviewId, 20);
CreateLink('Wecker Name', $ControlIdName, $iPhoneClock, 10);
CreateLink('Wecker Aktiv', $ControlIdActive, $iPhoneClock, 20);
CreateLink('Schlummer Modus', $ControlIdSlumber, $iPhoneClock, 30);
CreateLink('Feiertage', $ControlIdHoliday, $iPhoneClock, 40);
CreateLink('Stunde', $ControlIdHour, $iPhoneClock, 50);
CreateLink('Minuten', $ControlIdMinute, $iPhoneClock, 60);
$iPhoneDays = CreateDummyInstance("Tage", $iPhoneOverviewId, 30);
CreateLink('Montag', $ControlIdMonday, $iPhoneDays, 10);
CreateLink('Dienstag', $ControlIdTuesday, $iPhoneDays, 20);
CreateLink('Mittwoch', $ControlIdWednesday, $iPhoneDays, 30);
CreateLink('Donnerstag', $ControlIdThursday, $iPhoneDays, 40);
CreateLink('Freitag', $ControlIdFriday, $iPhoneDays, 50);
CreateLink('Samstag', $ControlIdSaturday, $iPhoneDays, 60);
CreateLink('Sonntag', $ControlIdSunday, $iPhoneDays, 70);
}
?>
lg
Andreas