IPS Status LCD-Display

Der Link in der Doku führt zu 404, hat jemand das Magic Script für das LCD-Display?

Habe noch eines von einem ehemaligen IPS’sler aufgetrieben.

Gruß Helmut

Einmal wieder hier verfügbar: IPS-FD-868 Funkdisplay ansteuern

paresy

Vielen Dank,
allerdings werden den „Schlüsselwerten 1,2,3“ (bei mir Key 1, Key 2, Key 3) die richtigen ID’s zugeordnet, aber die Variablen werden nicht im Display weitergescrollt.

Kann den Fehler nicht finden, dazu reicht mein PHP-Brain nicht…

Gruß Helmut

 <?

if (IPS_SemaphoreEnter($_IPS['SELF']."Handler", 1000))
{
    $instanceID = IPS_GetParent($_IPS['SELF']);
    $keyUpID = IPS_GetObjectIDByName("Key 1",$instanceID);
    //echo $keyUpID;
    $keyDownID = IPS_GetObjectIDByName("Key 2",$instanceID);
    //echo $keyDownID;
    $keyEnterID = IPS_GetObjectIDByName("Key 3",$instanceID);
    //echo $keyEnterID;
    IPS_SetHidden($_IPS['SELF'], true);

    $categoryID = @IPS_GetCategoryIDByName("Objects", $_IPS['SELF']);
    if ($categoryID === false)
    {
        $categoryID = IPS_CreateCategory();
        IPS_SetName($categoryID, "Objects");
        IPS_SetParent($categoryID, $_IPS['SELF']);
    }

    $variableEventID = @IPS_GetEventIDByName("Variable Event", $_IPS['SELF']);
    if ($variableEventID === false)
    {
        $variableEventID = IPS_CreateEvent(0);
        IPS_SetName($variableEventID, "Variable Event");
        IPS_SetParent($variableEventID, $_IPS['SELF']);
        IPS_SetEventActive($variableEventID, true);
    }

    if (@IPS_GetEventIDByName("Key Up Event", $_IPS['SELF']) === false)
    {
        $eventID = IPS_CreateEvent(0);
        IPS_SetName($eventID, "Key Up Event");
        IPS_SetParent($eventID, $_IPS['SELF']);
        IPS_SetEventTrigger($eventID, 0, $keyUpID);
        IPS_SetEventActive($eventID, true);
    }

    if (@IPS_GetEventIDByName("Key Down Event", $_IPS['SELF']) === false)
    {
        $eventID = IPS_CreateEvent(0);
        IPS_SetName($eventID, "Key Down Event");
        IPS_SetParent($eventID, $_IPS['SELF']);
        IPS_SetEventTrigger($eventID, 0, $keyDownID);
        IPS_SetEventActive($eventID, true);
    }

    if (@IPS_GetEventIDByName("Key Enter Event", $_IPS['SELF']) === false)
    {
        $eventID = IPS_CreateEvent(0);
        IPS_SetName($eventID, "Key Enter Event");
        IPS_SetParent($eventID, $_IPS['SELF']);
        IPS_SetEventTrigger($eventID, 0, $keyEnterID);
        IPS_SetEventActive($eventID, true);
     }

    $objectNumberID = CreateVariableByName($_IPS['SELF'], "Object Number", 1, "");
    $activeRowID = CreateVariableByName($_IPS['SELF'], "Row Number", 1, "");
    $tempValueID = CreateVariableByName($_IPS['SELF'], "Temporary Value", 2, "");

    $objectIDs = IPS_GetChildrenIDs($categoryID);

    if (count($objectIDs) == 0)
    {
        PJ_LCDText($instanceID, 1, "Objektkategorie");
        PJ_LCDText($instanceID, 2, "ist leer!");
    }
    else
    {
        $objects = array();
        foreach ($objectIDs as $id)
        {
            $obj = getObject($id);
            if ($obj['ObjectType'] == 2 || $obj['ObjectType'] == 3)
            {
                $objects[] = $obj;
            }
        }
        usort($objects, "compareObjects");

        $activeRow = GetValueInteger($activeRowID);
        switchObject(max(0, min(count($objectIDs) - 1, GetValueInteger($objectNumberID))));

        if ($_IPS['SENDER'] == "Variable")
        {
            if ($_IPS['VARIABLE'] == $keyUpID)
                        {
            echo "ip";
                if ($activeRow == 0 && $objectNumber > 0)
                {
                    switchObject($objectNumber - 1);
                }
                else if ($activeRow == 1)
                {
                    if ($variable["VariableType"] == 0)
                    {
                        $tempValue = 0;
                    }
                    else if ($variable["VariableType"] == 1 || $variable["VariableType"] == 2)
                    {
                        if (count($variable["VariableProfile"]["Associations"]) > 0)
                        {
                            for ($i = count($variable["VariableProfile"]["Associations"]) - 1; $i >= 0; $i--)
                            {
                                $association = $variable["VariableProfile"]["Associations"][$i];
                                if ($tempValue > $association["Value"])
                                {
                                    $tempValue = $association["Value"];
                                    break;
                                }
                            }
                        }
                        else
                        {
                            $tempValue = max($variable["VariableProfile"]["MinValue"], $tempValue - $variable["VariableProfile"]["StepSize"]);
                        }
                    }
                    $variable["VariableValue"] = $tempValue;
                }
            }
            else if ($_IPS['VARIABLE'] == $keyDownID)
            {
                if ($activeRow == 0 && $objectNumber + 1 < count($objectIDs))
                {
                    switchObject($objectNumber + 1);
                }
                else if ($activeRow == 1)
                {
                    if ($variable["VariableType"] == 0)
                    {
                        $tempValue = 1;
                    }
                    else if ($variable["VariableType"] == 1 || $variable["VariableType"] == 2)
                    {
                        if (count($variable["VariableProfile"]["Associations"]) > 0)
                        {
                            for ($i = 0; $i < count($variable["VariableProfile"]["Associations"]); $i++)
                            {
                                $association = $variable["VariableProfile"]["Associations"][$i];
                                if ($tempValue < $association["Value"])
                                {
                                    $tempValue = $association["Value"];
                                    break;
                                }
                            }
                        }
                        else
                        {
                            $tempValue = min($variable["VariableProfile"]["MaxValue"], $tempValue + $variable["VariableProfile"]["StepSize"]);
                        }
                    }
                    $variable["VariableValue"] = $tempValue;
                }
            }
            else if ($_IPS['VARIABLE'] == $keyEnterID)
            {
                    if ($variable != null)
                {
                    if ($activeRow == 0 && $hasAction)
                    {
                        $activeRow = 1;
                    }
                    else if ($activeRow == 1)
                    {
                        if ($tempValue != $variable['VariableValue'])
                        {
                            if ($variable["VariableCustomAction"] > 0)
                            {
                                $vars = array();
                                $vars['IPS_SENDER'] = "ViewJet";
                                $vars['IPS_VARIABLE'] = $object['RealObjectID'];
                                $vars['IPS_VALUE'] = (double)$tempValue;
                                $vars['IPS_INSTANCE'] = $instanceID;
                                if ($object['RealObjectID'] != $object['ObjectID']) { $vars['IPS_LINK'] = $object['ObjectID']; }

                                IPS_RunScriptEx(getLinkedID($variable["VariableCustomAction"]), $vars);
                            }
                            else
                            {
                                IPS_RequestAction(IPS_GetParent($object['RealObjectID']), $variable["VariableIdent"], (double)$tempValue);
                            }

                            PJ_SwitchLED($instanceID, 3, true);
                            IPS_Sleep(250);
                            PJ_SwitchLED($instanceID, 3, false);
                        }
                        $activeRow = 0;
                    }
                }
                else
                {
                    $vars = array();
                    $vars['IPS_SENDER'] = "ViewJet";
                    $vars['IPS_INSTANCE'] = $instanceID;
                    if ($object['RealObjectID'] != $object['ObjectID']) { $vars['IPS_LINK'] = $object['ObjectID']; }

                   IPS_RunScriptEx($object['RealObjectID'], $vars);
                      PJ_SwitchLED($instanceID, 3, true);
                   IPS_Sleep(550);
                   PJ_SwitchLED($instanceID, 3, false);
                }
            }
        }

        $hasPreviousValue = ($tempValue > $variable['VariableProfile']['MinValue']);
        $hasNextValue = ($tempValue < $variable['VariableProfile']['MaxValue']);

        if (count($variable['VariableProfile']['Associations']) > 0)
        {
            $hasPreviousValue = $tempValue > $variable['VariableProfile']['Associations'][0]['Value'];
            $hasNextValue = $tempValue < $variable['VariableProfile']['Associations'][count($variable['VariableProfile']['Associations']) - 1]['Value'];
        }

        $titleLeft = ($objectNumber < 1) ? " " : (($activeRow == 0) ? chr(127) : "<");
        $titleRight = ($objectNumber + 1 >= count($objectIDs)) ? " " : (($activeRow == 0) ? chr(126) : ">");
        $title = $titleLeft.formatText($object["ObjectName"]).$titleRight;

        $text = "";
        if ($object['ObjectType'] == 2)
        {
            $text = getAssociatedValue($variable, $tempValue);
            $textLeft = (!$hasAction || !$hasPreviousValue) ? " " : (($activeRow == 1) ? chr(127) : "<");
            $textRight = (!$hasAction || !$hasNextValue) ? " " : (($activeRow == 1) ? chr(126) : ">");
            $text = $textLeft.formatText($text).$textRight;
        }
        else
        {
            $text = ">".formatText("ausführen")."<";
        }

        PJ_LCDText($instanceID, 1, $title);
        PJ_LCDText($instanceID, 2, $text);

        SetValueInteger($activeRowID, $activeRow);
        SetValueInteger($objectNumberID, $objectNumber);
        SetValueFloat($tempValueID, (float)$tempValue);
    }

    IPS_SemaphoreLeave($_IPS['SELF']."Handler");
}

function formatText ($text)
{
    $text = str_replace("ß", chr(226), $text);
    $text = str_replace("°", chr(223), $text);
    $text = str_replace("ä", chr(225), $text);
    $text = str_replace("ö", chr(239), $text);
    $text = str_replace("ü", chr(245), $text);
    return sprintf("%-14.14s", sprintf("%".(7 + floor(strlen($text) / 2))."s", $text));
}

function getIPSVariable ($id)
{
    $variableID = $id;
    $linkedVariableID = getLinkedID($variableID);
    $variable = IPS_GetVariable($linkedVariableID);
    $variable['VariableType'] = $variable['VariableValue']['ValueType'];
    $variable['VariableValue'] = GetValue($linkedVariableID);
    $variable['ObjectName'] = IPS_GetName($variableID);
    $variable['VariableHasAction'] = false;
    $variable['IsStatusVariable'] = false;
    $variable['VariableInstanceID'] = 0;
    $variable['VariableIdent'] = "";

    $profileName = IPS_VariableProfileExists($variable['VariableProfile']) ? $variable['VariableProfile'] : "";
    if (strlen($variable['VariableCustomProfile']) > 0 && IPS_VariableProfileExists($variable['VariableCustomProfile']))
    {
        $profileName = $variable['VariableCustomProfile'];
    }

    $variable['VariableProfile'] = array();

    if (strlen($profileName) > 0)
    {
        $variableProfile = IPS_GetVariableProfile($profileName);
        $variable['VariableProfile'] = $variableProfile;
        if ($variable['VariableType'] == 0) { $variable['VariableProfile']['MaxValue'] = 1; }
        $variable['VariableHasAction'] = $variable['VariableCustomAction'] > 0;

        $variableParentID = IPS_GetParent($linkedVariableID);
        $variableParent = IPS_GetObject($variableParentID);
        if ($variableParent["ObjectType"] == 1)
        {
            $statusVariableIdents = IPS_GetChildrenIDs($variableParentID);
            foreach ($statusVariableIdents as $id)
            {
                     $o = IPS_GetObject($id);
                     if($o['ObjectIdent'] != "") {
                    $linkedVariableID = $id;
                     $variable['IsStatusVariable'] = true;
                     $variable['VariableInstanceID'] = $variableParentID;
                     $variable['VariableIdent'] = $o['ObjectIdent'];
                     $statusVariable = IPS_GetVariable($id);
                     $variable['VariableHasAction'] = $variable['VariableAction'] > 0 || $variable['VariableCustomAction'] > 0;
                     break;
                }
            }
        }
    }

    return $variable;
}

function getLinkedID ($ObjectID)
{
    if (IPS_ObjectExists($ObjectID))
    {
        $obj = IPS_GetObject($ObjectID);
        if ($obj['ObjectType'] === 6)
        {
            $link = IPS_GetLink($ObjectID);
            $ObjectID = $link['TargetID'];
        }
    }

    return $ObjectID;
}

function getAssociatedValue ($object, $value, $useAssociations = true, $printValue = null)
{
    if ($object["VariableProfile"]["ProfileName"] == "~UnixTimestamp") { return date("d.m.y H:i:s", $value); }

    $printValue = ($printValue === null) ? $value : $printValue;
    $last = null;

    if ($useAssociations)
    {
        foreach ($object["VariableProfile"]["Associations"] as $i)
        {
            if ($value >= $i["Value"])
            {
                if ($i["Name"] !== "")
                {
                    $last = $i;
                }
                else
                {
                    $last = null;
                }
            }
            else
            {
                break;
            }
        }
    }

    if ($last !== null)
    {
        $value = sprintf($last["Name"], $printValue);
    }
    else if (!is_string($value))
    {
        if (trim($object["VariableProfile"]["Suffix"]) == "%")
        {
            $value = ($value / ($object["VariableProfile"]["MaxValue"] - $object["VariableProfile"]["MinValue"])) * 100;
        }
        $value = sprintf("%.".$object["VariableProfile"]["Digits"]."f", $value);
    }
    $result = $object["VariableProfile"]["Prefix"].$value.$object["VariableProfile"]["Suffix"];

    return $result;
}

function getObject ($ObjectID)
{
    if (!IPS_ObjectExists($ObjectID)) { return false; }

    $object = IPS_GetObject($ObjectID);

    if ($object['ObjectType'] == 6)
    {
        $link = IPS_GetLink($ObjectID);
        if (!IPS_ObjectExists($link['TargetID'])) { return false; }

        $linkObject = $object;
        $object = IPS_GetObject($link['TargetID']);
        $object['RealObjectID'] = $object['ObjectID'];
        $object['ObjectIcon'] = ($linkObject['ObjectIcon'] != "") ? $linkObject['ObjectIcon'] : $object['ObjectIcon'];
        $object['ObjectID'] = $ObjectID;
        $object['ObjectInfo'] = $linkObject['ObjectInfo'];
        $object['ObjectIsHidden'] = $linkObject['ObjectIsHidden'];
        $object['ObjectName'] = $linkObject['ObjectName'];
        $object['ObjectPosition'] = $linkObject['ObjectPosition'];
        $object['ParentID'] = $linkObject['ParentID'];
    }
    else
    {
        $object['RealObjectID'] = $ObjectID;
    }

    return $object;
}

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;
}

function compareObjects ($a, $b)
{
    $comp = ($a['ObjectPosition'] < $b['ObjectPosition']) ? -1 : (($a['ObjectPosition'] == $b['ObjectPosition']) ? 0 : 1);
    if ($comp == 0)
    {
        if (isset($a['ObjectType']))
        {
            $comp = ($a['ObjectType'] < $b['ObjectType']) ? -1 : (($a['ObjectType'] == $b['ObjectType']) ? 0 : 1);
        }
        if ($comp == 0)
        {
            $comp = strcmp($a['ObjectName'], $b['ObjectName']);
            if ($comp == 0)
            {
                $comp = $a['ObjectID'] > $b['ObjectID'];
            }
        }
    }
    return $comp;
}

function switchObject ($num)
{
    global $objectNumber, $objects, $object, $variable, $hasAction, $tempValue, $tempValueID, $variableEventID, $activeRow;

    $objectNumber = $num;
    $object = $objects[$objectNumber];

    if ($object['ObjectType'] == 2)
    {
        $variable = getIPSVariable($object['ObjectID']);
        $hasAction = ($variable['VariableType'] < 3) && $variable['VariableHasAction'];
        $tempValue = ($activeRow == 0) ? $variable["VariableValue"] : GetValue($tempValueID);
        IPS_SetEventTrigger($variableEventID, 1, getLinkedID($object['ObjectID']));
        IPS_SetEventActive($variableEventID, true);
    }
    else
    {
        $variable = null;
        $hasAction = true;
        $tempValue = 0;
        IPS_SetEventActive($variableEventID, false);
    }
}

?>
 

Edit Fehler gefunden: die letzten 4 Events, selbst hinzugefügt haben gestört, gelöscht und schon geht’s :wink:
@Mods kann auch gelöscht werden.