Dieses Skript erstellt eine Variable, die dann als Eieruhr genutzt werden kann. Beim Drücken von + wird der Befehl aus der on-Funktion gestartet und zählt so lange runter, bis 0 erreicht wurde. Daraufhin wird die off-Funktion gestartet wird und die Eieruhr wechselt auf Aus. Während die Eieruhr läuft, kann diese per +/- adjustiert werden, ohne dass die on-Funktion erneut gestartet wird. Bei erreichen von 0 oder drücken der Aus-Taste, wird der Timer sofort deaktiviert und die off-Funktion ausgeführt.
Grüße,
paresy
PS: Wurde für die 2.4 entwickelt, sollte aber (ohne Farben) auch mit der 2.3 schon laufen.
PPS: Diese spezielle Darstellung wird im iFront nicht vollständig unterstützt, ist aber trotzdem nutzbar
<?
$max = 25;
$step = 5; //Schrittgröße
function on() {
IPS_LogMessage("Eieruhr", "Aktiviert!");
}
function off() {
IPS_LogMessage("Eieruhr", "Abgelaufen...");
}
//Ab hier nichts mehr verändern
$min = 0;
$suffix = "min";
$vpn = "EggTimer.".$max.".".$step;
if($IPS_SENDER == "Execute")
{
if(IPS_VariableProfileExists($vpn))
IPS_DeleteVariableProfile($vpn);
IPS_CreateVariableProfile($vpn, 1);
IPS_SetVariableProfileValues($vpn, $min, $max, 0);
IPS_SetVariableProfileIcon($vpn, "Clock");
IPS_SetVariableProfileAssociationEx($vpn, $min-2, "Aus", "", 0xFF0000);
IPS_SetVariableProfileAssociationEx($vpn, $min-1, "-", "", -1);
IPS_SetVariableProfileAssociationEx($vpn, $min, "%d ".$suffix, "", 0x00FF00);
IPS_SetVariableProfileAssociationEx($vpn, $max+1, "+", "", -1);
$vid = CreateParentVariable($IPS_SELF, "Timer", 1);
IPS_SetVariableCustomProfile($vid, $vpn);
IPS_SetVariableCustomAction($vid, $IPS_SELF);
SetValue($vid, $min-2);
}
else if($IPS_SENDER == "WebFront")
{
switch($IPS_VALUE)
{
case $min-2:
doOff();
break;
case $min-1:
$IPS_VALUE = GetValue($IPS_VARIABLE) - $step;
if($IPS_VALUE <= 0)
{
$IPS_VALUE = -2;
doOff();
}
break;
case $max+1:
$IPS_VALUE = min($max, max(0, GetValue($IPS_VARIABLE)) + $step);
doOn();
break;
default:
return;
}
SetValue($IPS_VARIABLE, $IPS_VALUE);
}
else if($IPS_SENDER == "TimerEvent")
{
$vid = CreateParentVariable($IPS_SELF, "Timer", 1);
$v = GetValue($vid);
$v--;
if($v <= 0)
{
doOff();
IPS_SetScriptTimer($IPS_SELF, 0);
$v = $min-2;
}
SetValue($vid, $v);
}
function doOn()
{
global $IPS_SELF;
if(IPS_GetScriptTimer($IPS_SELF) == 0)
{
IPS_SetScriptTimer($IPS_SELF, 60);
on();
}
}
function doOff()
{
global $IPS_SELF;
IPS_SetScriptTimer($IPS_SELF, 0);
off();
}
function CreateParentVariable($id, $name, $type)
{
global $IPS_SELF;
$vid = IPS_GetParent($IPS_SELF);
if(!IPS_VariableExists($vid))
{
$vid = false;
}
else
{
$v = IPS_GetVariable($vid);
if($v['VariableValue']['ValueType'] != $type)
$vid = false;
}
if($vid === false)
{
$vid = IPS_CreateVariable($type);
IPS_SetParent($vid, IPS_GetParent($IPS_SELF));
IPS_SetParent($id, $vid);
IPS_SetName($vid, $name);
IPS_SetInfo($vid, "this variable was created by script #$IPS_SELF");
IPS_SetHidden($id, true);
}
return $vid;
}
function IPS_SetVariableProfileAssociationEx($vpn, $av, $an, $ai, $ac)
{
if(floatval(IPS_GetKernelVersion()) <= 2.3)
{
IPS_SetVariableProfileAssociation($vpn, $av, $an, $ai);
} else {
IPS_SetVariableProfileAssociation($vpn, $av, $an, $ai, $ac);
}
}
?>