{"id":305,"date":"2014-12-08T13:14:01","date_gmt":"2014-12-08T12:14:01","guid":{"rendered":"http:\/\/ipsview.brownson.at\/?p=305"},"modified":"2025-04-06T08:39:31","modified_gmt":"2025-04-06T07:39:31","slug":"alarmanlage-mit-code-ein-und-ausschalten","status":"publish","type":"post","link":"https:\/\/ipsview.brownson.at\/?p=305","title":{"rendered":"Alarmanlage mit Code Ein- und Ausschalten"},"content":{"rendered":"<p>Hier ist einmal ein Beispiel, wie man eine Alarmanalage oder eine andere Funktion mit einer Code Eingabe sch\u00fctzen kann.<\/p>\n<p><span style=\"text-decoration: underline;\">Folgende Objekte werden in IP-Symcon ben\u00f6tigt:<\/span><\/p>\n<ul>\n<li>Script (Script zur Steuerung)<\/li>\n<li>Status, Variable vom Type Boolean (aktueller Status der Alarmanlage)<\/li>\n<li>Code, Variable vom Type String (aktuelle Code Eingabe in Klartext)<\/li>\n<li>Display, Variable vom Type String(zur Anzeige der aktuelle Eingabe)<\/li>\n<\/ul>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_Console1.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-317\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_Console1-300x34.png\" alt=\"IPSView_AlarmProtection_Console1\" width=\"300\" height=\"34\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_Console1-300x34.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_Console1.png 801w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Wichtig ist hierbei, dass die Statusvariable das Skript als ActionScript zugewiesen hat, um eine Code Kontrolle beim Ein- und Ausschalten zu gew\u00e4hrleisten.<\/p>\n<p>Folgendes Skript beinhaltet die komplette Programmlogik und erzeugt nach dem erstmaligen Ausf\u00fchren auch alle ben\u00f6tigten Variablen:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?\r\n    \/**\r\n     * @file          IPSView_AlarmSystemProtection.ips.php\r\n     * @author        brownson\r\n     * @version\r\n     *   Version 1.0, 2014-11-19 brownson: Initiale Version&lt;br\/&gt;\r\n     *\r\n     * Skript zum Ein-\/Ausschalten einer Alarmanlage mit Code Schutz.\r\n     *\r\n     * Konfiguration Einstellungen:\r\n     *   ALARMSYSTEM_CODE         ... Code der eingegeben werden muss um die \r\n     *                                Alarmanlage auszuschalten.\r\n     *   ALARMSYSTEM_SHOWLASTCHAR ... Spezifiziert ob das letzt eingegebene Zeichen\r\n     *                                im Klartext angezeigt werden soll.\r\n     *   ALARMSYSTEM_MESSAGEERROR ... Spezifiziert die Fehlermeldung die im Falle\r\n     *                                einer ung\u00fcltigen Eingabe angezeigt werden soll.\r\n     *   ALARMSYSTEM_MESSAGEOFF   ... Spezifiziert die Anzeige im Status Off.\r\n     *   ALARMSYSTEM_MESSAGEON    ... Spezifiziert die Anzeige im Status ON.\r\n     *\r\n     *   AlarmSystem_SetOn        ... Hier k\u00f6nnen Befehle platziert werden, die beim\r\n     *                                Einschalten der Alarmanlage ausgef\u00fchrt werden\r\n     *                                sollen.\r\n     *   AlarmSystem_SetOff       ... Hier k\u00f6nnen Befehle platziert werden, die beim\r\n     *                                Ausschalten der Alarmanlage ausgef\u00fchrt werden\r\n     *                                sollen.\r\n     *\r\n     *\/\r\n\r\n    \/*\r\n     * Konfiguration:\r\n     * -------------------------------------------------------------------------\r\n     *\/\r\n    \r\n    define ('ALARMSYSTEM_CODE',\t\t\t\t'1234');\r\n    define ('ALARMSYSTEM_SHOWLASTCHAR',\t\ttrue);\r\n    define ('ALARMSYSTEM_MESSAGEERROR',\t\t'Code Eingabe ist NICHT korrekt!');\r\n    define ('ALARMSYSTEM_MESSAGEOFF',      'Alarmanlage Aus');\r\n    define ('ALARMSYSTEM_MESSAGEON',       'Alarmanlage Ein');\r\n\r\n    function AlarmSystem_SetOn() {\r\n    }\r\n\r\n    function AlarmSystem_SetOff() {\r\n    }\r\n\r\n    \/*\r\n     * Programmlogik:\r\n     * -------------------------------------------------------------------------\r\n     *\/\r\n    $scriptID     = $_IPS['SELF'];\r\n    $sender       = $_IPS['SENDER'];\r\n    $parentID     = IPS_GetParent($scriptID);\r\n\r\n    $variableIDStatus  = CreateVariable('Status',  0, $parentID, 10, '~Switch', $scriptID);\r\n    $variableIDDisplay = CreateVariable('Display', 3, $parentID, 20, '~String', null);\r\n    $variableIDCode    = CreateVariable('Code',    3, $parentID, 30, '~String', null);\r\n\r\n    if ($sender=='Execute') {\r\n       \/\/ Only create Variables in manuell Mode\r\n    } else {\r\n        $variableId   = array_key_exists('VARIABLE', $_IPS) ? $_IPS['VARIABLE'] : 0;\r\n        $value        = $_IPS['VALUE'];\r\n        if ($variableId == $variableIDStatus) {\r\n           if ($value==true and !GetValue($variableIDStatus)) {\r\n              AlarmSystem_SetOn();\r\n              SetValue($variableIDStatus, true);\r\n                SetValue($variableIDDisplay, ALARMSYSTEM_MESSAGEON);\r\n            } else if ($value==false and GetValue($variableIDStatus) and AlarmSystem_CodeMatches($variableIDCode)) {\r\n              AlarmSystem_SetOff();\r\n              AlarmSystem_ClearCode($variableIDCode, $variableIDDisplay);\r\n              SetValue($variableIDStatus, false);\r\n                SetValue($variableIDDisplay, ALARMSYSTEM_MESSAGEOFF);\r\n            } else if ($value==false and GetValue($variableIDStatus) and !AlarmSystem_CodeMatches($variableIDCode)) {\r\n                SetValue($variableIDDisplay, ALARMSYSTEM_MESSAGEERROR);\r\n            } else {\r\n                \/\/ Nothing to do\r\n            }\r\n        } else if ($variableId == $variableIDDisplay) {\r\n           \/\/ no Update allowed\r\n        } else if ($variableId == $variableIDCode) {\r\n           \/\/ no Update allowed\r\n        } else {\r\n            switch ($value) {\r\n                case '0':\r\n                case '1':\r\n                case '2':\r\n                case '3':\r\n                case '4':\r\n                case '5':\r\n                case '6':\r\n                case '7':\r\n                case '8':\r\n                case '9':\r\n                    AlarmSystem_AddDigitToCode($variableIDCode, $variableIDDisplay, $value);\r\n                    break;\r\n                case 'B':\r\n                    AlarmSystem_ClearDigitFromCode($variableIDCode, $variableIDDisplay);\r\n                    break;\r\n                case 'C':\r\n                    AlarmSystem_ClearCode($variableIDCode, $variableIDDisplay);\r\n                    break;\r\n                default:\r\n                   \/\/ do nothing\r\n                   break;\r\n            }\r\n        }\r\n    }\r\n    \/*\r\n     * Funktionen:\r\n     * -------------------------------------------------------------------------\r\n     *\/\r\n    function AlarmSystem_CodeMatches($variableIDCode) {\r\n       return GetValue($variableIDCode)==ALARMSYSTEM_CODE;\r\n    }\r\n     \r\n    function AlarmSystem_ClearCode($variableIDCode, $variableIDDisplay) {\r\n       SetValue($variableIDCode, '');\r\n       SetValue($variableIDDisplay, '');\r\n    }\r\n\r\n    function AlarmSystem_BuildDisplayString($variableIDCode, $variableIDDisplay) {\r\n       $display = '';\r\n       $code    = GetValue($variableIDCode);\r\n       $len     = strlen($code);\r\n       for ($pos=0; $pos&lt;$len ; $pos++) {\r\n          if ($pos+1==$len and ALARMSYSTEM_SHOWLASTCHAR) {\r\n              $display = $display.substr($code, -1);\r\n          } else {\r\n              $display = $display.'*';\r\n          }\r\n       }\r\n       SetValue($variableIDDisplay, $display);\r\n    }\r\n\r\n    function AlarmSystem_AddDigitToCode($variableIDCode, $variableIDDisplay, $value) {\r\n       SetValue($variableIDCode, GetValue($variableIDCode).$value);\r\n       AlarmSystem_BuildDisplayString($variableIDCode, $variableIDDisplay);\r\n    }\r\n\r\n    function AlarmSystem_ClearDigitFromCode($variableIDCode, $variableIDDisplay) {\r\n       if (strlen(GetValue($variableIDCode)) &gt; 0) {\r\n       \tSetValue($variableIDCode, substr(GetValue($variableIDCode), 0, -1));\r\n           AlarmSystem_BuildDisplayString($variableIDCode, $variableIDDisplay);\r\n       }\r\n    }\r\n\r\n    function CreateVariable ($name, $type, $parentId, $position=0, $profile=\"\", $action=null) {\r\n        $variableId = @IPS_GetObjectIDByIdent($name, $parentId);\r\n        if ($variableId === false) {\r\n \t\t\t$variableId = IPS_CreateVariable($type);\r\n            IPS_SetParent($variableId, $parentId);\r\n            IPS_SetName($variableId, $name);\r\n            IPS_SetIdent($variableId, $name);\r\n            IPS_SetPosition($variableId, $position);\r\n  \t\t\tIPS_SetVariableCustomProfile($variableId, $profile);\r\n \t\t\tIPS_SetVariableCustomAction($variableId, $action);\r\n        }\r\n        return $variableId;\r\n    }\r\n\r\n?&gt;\r\n<\/pre>\n<p><span style=\"text-decoration: underline;\">Was macht der Code:<\/span><\/p>\n<p>Im oberen Teil des Skriptes befindet sich der Konfigurationsteil, hier kann man die eigentlichen Schaltbefehle und den Code eintragen.<\/p>\n<p>Darunter die Programm Logik, die den Aufruf entsprechende der Variable analysiert:<\/p>\n<ul>\n<li>Statusvariable auf true (Einschalten der Alarmanlage) \u2013 kann jederzeit gemacht werden, es erfolgt keine \u00dcberpr\u00fcfung des Codes<\/li>\n<li>Statusvariable auf false (Ausschalten der Alarmanlage) \u2013 es wird die aktuelle Code Eingabe \u00fcberpr\u00fcft, nur wenn OK wird ausgeschaltet. Ansonsten wird eine Fehlermeldung in die Display Variable geschrieben<\/li>\n<li>Code Tasten 0-9, schreibt das jeweilige Zeichen in die Code Variable in Klartext und setzen die Display Variable entsprechend der Codeeingabe (letztes Zeichen in Klartext, alle anderen als *)<\/li>\n<li>Taste \u201eBack\u201c l\u00f6scht das letzte Zeichen aus der Codeeingabe<\/li>\n<\/ul>\n<p>Im untersten Teil des Skriptes ist noch der Teil f\u00fcr die Installation, der alle ben\u00f6tigten Variablen anlegt.<\/p>\n<p><span style=\"text-decoration: underline;\">Integration in IPSView:<\/span><\/p>\n<p>In IPSView erstellt man nun folgende Steuerungselemente:<\/p>\n<ul>\n<li>VarLabel, Anzeige der aktuellen Code Eingabe, als ID wird die Display Variable spezifiziert<\/li>\n<\/ul>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerLabel.png\"><img decoding=\"async\" class=\"alignnone wp-image-309 size-medium\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerLabel-300x204.png\" alt=\"IPSView_AlarmProtection_DesignerLabel\" width=\"300\" height=\"204\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerLabel-300x204.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerLabel.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<span style=\"color: #000000; font-family: sans-serif;\"><span style=\"line-height: normal;\"><br \/>\n<\/span><\/span><\/p>\n<ul>\n<li>Button, Ziffernfeld 0-9, als ID wird das Skript spezifiziert, als Wert die jeweilige Code Ziffer angegeben<\/li>\n<\/ul>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButton1.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-307\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButton1-300x204.png\" alt=\"IPSView_AlarmProtection_DesignerButton1\" width=\"300\" height=\"204\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButton1-300x204.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButton1.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>Button, Taste Back, als ID wird das Skript spezifiziert, als Wert der Buchstabe \u201eB\u201c<\/li>\n<\/ul>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButtonB.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-308\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButtonB-300x204.png\" alt=\"IPSView_AlarmProtection_DesignerButtonB\" width=\"300\" height=\"204\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButtonB-300x204.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerButtonB.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>ToggleButton, zum eigentlichen Ein-\/Ausschalten der Alarmanlage, als ID wird die Status Variable angegeben, Text und Farben entsprechend den pers\u00f6nlichen Vorstellungen<\/li>\n<\/ul>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerOnOff.png\"><img decoding=\"async\" class=\"alignnone wp-image-310 size-medium\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerOnOff-300x204.png\" alt=\"\" width=\"300\" height=\"204\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerOnOff-300x204.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_DesignerOnOff.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Im Client kann die Alarmanlage nun nur mehr ausgeschaltet werden, wenn eine richtige Codeeingabe erfolgt ist:<\/p>\n<p><a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOn.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-312\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOn-300x225.png\" alt=\"IPSView_AlarmProtection_ExampleOn\" width=\"300\" height=\"225\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOn-300x225.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOn.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOff.png\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-311\" src=\"http:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOff-300x225.png\" alt=\"IPSView_AlarmProtection_ExampleOff\" width=\"300\" height=\"225\" srcset=\"https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOff-300x225.png 300w, https:\/\/ipsview.brownson.at\/wp-content\/uploads\/IPSView_AlarmProtection_ExampleOff.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Alternativ kann mit diesem Script auch ein spezieller Bereich in der View auf visible gesetzt werden:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hier ist einmal ein Beispiel, wie man eine Alarmanalage oder  [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,6],"tags":[15,14,16,7],"class_list":["post-305","post","type-post","status-publish","format-standard","hentry","category-howto","category-skripte","tag-alarmanlage","tag-code","tag-schuetzen","tag-skript"],"_links":{"self":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/305","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=305"}],"version-history":[{"count":10,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/305\/revisions"}],"predecessor-version":[{"id":2681,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/305\/revisions\/2681"}],"wp:attachment":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=305"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}