Toggle Button

So jetzt läuft alles. Musste die Case Reihenfolge ändern, so wie es auch in der Siemens Logo abläuft. Nutze es für die Pool Dosiersteuerung mit einer Siemens Logo.

image

<?php
/**********************************************************
 *
 * Toggle-Button für Lampen
 * 1. Integer-Variable anlegen unterhalb des Devices (z.B. Lampe)
 * 2. Variablen-Profil anlegen (Integer mit Range 0-1, Schrittweite 1)
 * 3. Skript an Integer-Variable verknüpfen (Eigene Aktion)
 *
 **********************************************************/

 // Variablen-ID der Integer-Variable aus 1.
 $myIntValID = 10169;
 // Names des Variablen-Profils aus 2.
 $myVariableProfile = "PhToogleAutomatik";
 // ID eines Homematic-Devices, falls dies gleich geschalten werden soll
 $myDevice = 21788;


if($_IPS['SENDER'] == "Execute")
{
    $value = IPS_GetVariableProfile($myVariableProfile);
    switch($value['Associations'][0]['Value'])
    {
         case 0:
          toggleOff($myIntValID, $myVariableProfile, $myDevice);
          break;
         case 1:
          toggleOn($myIntValID, $myVariableProfile, $myDevice);
          break;
        case 2:
          toggleAuto($myIntValID, $myVariableProfile, $myDevice);
          break;
    }
}

if($_IPS['SENDER'] == "WebFront")
{
   switch($_IPS['VALUE'])
    {
        case 0:
          toggleOff($myIntValID, $myVariableProfile, $myDevice);
          break;
        case 1:
          toggleOn($myIntValID, $myVariableProfile, $myDevice);
          break;
        
        case 2:
          toggleAuto($myIntValID, $myVariableProfile, $myDevice);
          break;
       
    }
}
function toggleOff($myIntValID, $myVariableProfile, $myDevice)
{
    // Delete VariableProfileAssociation
    IPS_SetVariableProfileAssociation($myVariableProfile, 0, "", "", -1);
    // Set new VariableProfileAssociation
    IPS_SetVariableProfileAssociation($myVariableProfile, 1, "Ph Dosierung An", "", 0x00FF00);
       // Switch Relais
    S7_WriteBit(21788 ,FALSE); 
	S7_WriteBit(21788 ,TRUE);  
    // Set Value Integer
    SetValueInteger($myIntValID , 1); 
}

function toggleOn($myIntValID, $myVariableProfile, $myDevice)
{
    // Delete VariableProfileAssociation
    IPS_SetVariableProfileAssociation($myVariableProfile, 1, "", "", -1);
    // Set new VariableProfileAssociation
    
    IPS_SetVariableProfileAssociation($myVariableProfile, 2, "Ph Dosierung Auto", "", 0x0080ff);
    // Switch Relais
    S7_WriteBit(21788 ,FALSE); 
	S7_WriteBit(21788 ,TRUE);  
    // Set Value Integer
     SetValueInteger($myIntValID , 2); 
}


function toggleAuto($myIntValID, $myVariableProfile, $myDevice)
{
    // Delete VariableProfileAssociation
    IPS_SetVariableProfileAssociation($myVariableProfile, 2, "", "", -1);
    // Set new VariableProfileAssociation
    IPS_SetVariableProfileAssociation($myVariableProfile, 0, "Ph Dosierung Aus", "", 0xFF0000);
    // Switch Relais
 S7_WriteBit(21788 ,FALSE); 
 S7_WriteBit(21788 ,TRUE);  
    // Set Value Integer
    SetValueInteger($myIntValID ,0); 
}

Danke
richimaint

Ich brauchte auch sowas ähnliches… Also hatte ich mich mal auch ran gemacht. Könnte auch hilfreich sein und fand es recht nett. klopf auf die eigene Schulter :wink:

Bei mir ist es der Briefkasten. Eine IntegerVariable hat die Werte für Leer, Post und Zeitung. Die Anzeige war erstmal einfach aber ich wollte auf einen Klick den Status zurück setzen.

Hier mal meine Version und so kann man es nutzen:
Also Integer Anlegen und ein Script wie im Baum angezeigt.

!
Das Event drunter legen welche Variable „Überwacht“ wird. Bei Änderung, ändert sich auch die Anzeige. Also wenn man was per Script ändert, ändert man immer die Original Variable. Dies ist nur ein Darstellungsklon

Profil anlegen wie gezeigt.

!

Und der Variable dann auch das Script zur Aktion auswählen.
Bildschirmfoto 2021-05-30 um 20.15.15 !

Ich löse es indem ich die Optik der Assoziation in eine übergeordnete Interner Variable kopiere.

Und das Script. An dem muss man eigentlich nichts machen nur im Else Teil den Code ändern der ausgeführt werden soll beim Klick. Bei mir setze ich die Briefkasten Variable auf „leer“.
Hier könnte man aber auch durch die Assoziationen laufen und und und.

<?php

// Event bei Status änderung
if ($_IPS['SENDER'] =="Variable")
{
    $ID = $_IPS['VARIABLE'];

    $value = GetValue($ID);
    $profilname = IPS_GetVariable($ID)["VariableCustomProfile"];
    $zuordnungen = IPS_GetVariableProfile($profilname)["Associations"];
    $selected = $zuordnungen[$value];

    // Kopieren der Ansicht aber nicht den Wert.  [Value], [Name], [Icon], [Color] 
    $selfprofile =  IPS_GetVariable(IPS_GetParent($_IPS['SELF']))["VariableCustomProfile"];

    IPS_SetVariableProfileAssociation($selfprofile, 0, $selected["Name"], $selected["Icon"], $selected["Color"]);
    return;
}
else
{
    // script code bei klick
   SetValue(35569,0);
}


Das Webfront ist unspektakulär und simpel. Ein Knopf der Beschriftung, icon und Farbe ändern kann und eine Schaltfläche ist.

Mein Ziel war das das Script nicht wirklich was von den Assoziazonen kennt.

3 „Gefällt mir“

@mac Danke für den prima Tip, Deine Umsetzung gefällt mir sehr!
Cheers Seppm