{"id":496,"date":"2015-04-12T19:01:37","date_gmt":"2015-04-12T18:01:37","guid":{"rendered":"http:\/\/ipsview.brownson.at\/?p=496"},"modified":"2015-04-13T19:45:26","modified_gmt":"2015-04-13T18:45:26","slug":"toggle-switch-fuer-rgb","status":"publish","type":"post","link":"https:\/\/ipsview.brownson.at\/?p=496","title":{"rendered":"Toggle Switch f\u00fcr RGB"},"content":{"rendered":"<p>Analog zu dem Beitrag <a title=\"Toggle Switch f\u00fcr Dimmer\" href=\"http:\/\/ipsview.brownson.at\/?p=494\">\u201eToggle Switch f\u00fcr Dimmer\u201c<\/a> gibt es auch bei RGB Instanzen die M\u00f6glichkeit einen Toggle Switch zu realisieren.<\/p>\n<p>Auch hier hat man dadurch den Vorteil, dass der letzte gew\u00e4hlte RGB Wert erhalten.<\/p>\n<p>Realisieren kann man so einen Switch mit dem folgenden Skript:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-title=\"RGB Switch\">&lt;?\r\n\t\/**\r\n\t * @file          IPSView_RGBSwitch.ips.php\r\n\t * @author        brownson\r\n\t * @version\r\n\t *   Version 1.0, 2015-04-12 brownson: Initiale Version&lt;br\/&gt;\r\n\t *\r\n\t * Skript um eine Switch Variable f\u00fcr einen RGB zu realisieren\r\n\t *\r\n\t * Konfiguration Einstellungen:\r\n\t *   DEVICE_RGB_ID        ... ID der Variable zum Setzen des RGB Wertes\r\n\t *\r\n\t *\/\r\n\r\n\t\/*\r\n\t * Konfiguration:\r\n\t * -------------------------------------------------------------------------\r\n\t *\/\r\n\r\n\tdefine (&#039;DEVICE_RGB_ID&#039;, 12345);\r\n\r\n\t\/*\r\n\t * Programmlogik:\r\n\t * -------------------------------------------------------------------------\r\n\t *\/\r\n\t$scriptID     = $_IPS[&#039;SELF&#039;];\r\n\t$sender       = $_IPS[&#039;SENDER&#039;];\r\n\t$parentID     = IPS_GetParent($scriptID);\r\n\r\n\t$variableIDSwitch  = CreateVariable(&#039;IPSView_Switch&#039;,  0, $parentID, 10,\r\n\t                                    &#039;~Switch&#039;,   $scriptID);\r\n\t$variableIDRGB     = CreateVariable(&#039;IPSView_RGB&#039;,     1, $parentID, 20,\r\n\t                                    &#039;~HexColor&#039;, $scriptID);\r\n\r\n\tif ($sender==&#039;Execute&#039;) {\r\n\t   \/\/ Only create Variables in manuell Mode\r\n\t} else {\r\n\t\t$variableId   = $_IPS[&#039;VARIABLE&#039;];\r\n\t\t$value        = $_IPS[&#039;VALUE&#039;];\r\n\t\tswitch ($variableId) {\r\n\t\t\tcase $variableIDRGB:\r\n\t\t\t   RGB_SetDeviceValue($value);\r\n\t\t\t   SetValue($variableIDSwitch, ($value &gt; 0));\r\n\t\t\t   SetValue($variableIDRGB, $value);\r\n\t\t      break;\r\n\t\t\tcase $variableIDSwitch:\r\n\t\t\t   if ($value)\r\n\t\t\t   \tRGB_SetDeviceValue(GetValue($variableIDRGB));\r\n\t\t\t\telse\r\n\t\t\t   \tRGB_SetDeviceValue(0);\r\n\t\t\t   SetValue($variableId, $value);\r\n\t\t      break;\r\n\t\t\tdefault:\r\n\t\t      break;\r\n\t\t}\r\n\t}\r\n\t\r\n\t\/*\r\n\t * Funktionen:\r\n\t * -------------------------------------------------------------------------\r\n\t *\/\r\n\r\n\tfunction RGB_SetDeviceValue($value) {\r\n\t\t$instanceID = IPS_GetParent(DEVICE_RGB_ID);\r\n\t\t$ident      = IPS_GetObject(DEVICE_RGB_ID)[&#039;ObjectIdent&#039;];\r\n\t\tIPS_RequestAction($instanceID, $ident, $value);\r\n\t}\r\n\r\n\tfunction CreateVariable ($name, $type, $parentId, $position=0, $profile=&quot;&quot;,\r\n\t                         $action=null, $referenceID=null) {\r\n\t\t$variableId = @IPS_GetObjectIDByIdent($name, $parentId);\r\n\t\tif ($variableId === false) {\r\n \t\t\t$variableId = IPS_CreateVariable($type);\r\n\t\t\tIPS_SetParent($variableId, $parentId);\r\n\t\t\tIPS_SetName($variableId, $name);\r\n\t\t\tIPS_SetIdent($variableId, $name);\r\n\t\t\tIPS_SetPosition($variableId, $position);\r\n  \t\t\tif ($referenceID != null) {\r\n  \t\t\t   $variable = IPS_GetVariable($referenceID);\r\n  \t\t\t   $profile  = $variable[&#039;VariableProfile&#039;];\r\n\t\t\t}\r\n  \t\t\tIPS_SetVariableCustomProfile($variableId, $profile);\r\n \t\t\tIPS_SetVariableCustomAction($variableId, $action);\r\n\t\t}\r\n\t\treturn $variableId;\r\n\t}\r\n\r\n?&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Nach dem erstmaligen Ausf\u00fchren werden 2 neue Variablen angelegt \u2013 eine boolean Variable f\u00fcr den Schalter und eine Integer Variable f\u00fcr die Speicherung des RGB Wertes.<\/p>\n<p>Bei der Kategorisierung der Variablen in IPSView werden diese beiden Variablen als Schalter bzw. RGB Wert kategorisiert.<\/p>\n<p>Probleme und Anregungen zu dem Skriptbeispiel k\u00f6nnen gerne im IP-Symcon Forum gepostet werden.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Analog zu dem Beitrag \u201eToggle Switch f\u00fcr Dimmer\u201c gibt es  [&#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":[35,33],"class_list":["post-496","post","type-post","status-publish","format-standard","hentry","category-howto","category-skripte","tag-rgb","tag-switch"],"_links":{"self":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/496","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=496"}],"version-history":[{"count":4,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/496\/revisions"}],"predecessor-version":[{"id":532,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=\/wp\/v2\/posts\/496\/revisions\/532"}],"wp:attachment":[{"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ipsview.brownson.at\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}