IPS_CreateVariableProfile

Hallo zusammen,
hab in der Doku folgendes gefunden um Variablen zu kopieren: Wie kann ich ? ganz unten.
Folgende Probleme hab ich bei der Umsetzung:

  1. Der 2. Eintrag -2 wird komplett verschluckt. (nicht wichtig für mich)
  2. Wenn ich die ermittelten Zeilen in ein neues Script kopiere im dann die neue Variable anlegen zu lassen bekomm ich Fehler.
    Die Doku hat mich nicht weiter gebracht. Hoffe dass mit jemand kurz helfen kann.

Script:

<?

IPS_CreateVariableProfile("HC_Zeitr_a-r", 1);
IPS_SetVariableProfileText("HC_Zeitr_a-r", "", "");
IPS_SetVariableProfileValues("HC_Zeitr_a-r", 0, 0, 0);
IPS_SetVariableProfileDigits("HC_Zeitr_a-r", 0);
IPS_SetVariableProfileIcon("HC_Zeitr_a-r", "");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", -3, "<", "", "-1");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", -2, ">", "", "-1");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", -1, "Jetzt", "", "-1");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", 7, "Woche", "", "-1");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", 30, "Monat", "", "-1");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", 90, "Quartal", "", "-1");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", 180, "Halbjahr", "", "-1");
IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", 366, "Jahr", "", "-1");

?>

Scriptausgabe:

IPS-Err-PHP                  2014-01-11 13:20:43.261  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 8    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler      8 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 8
IPS-Err-PHP                  2014-01-11 13:20:43.266  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 9    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler      9 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 9
IPS-Err-PHP                  2014-01-11 13:20:43.270  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 10    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler     10 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 10
IPS-Err-PHP                  2014-01-11 13:20:43.274  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 11    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler     11 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 11
IPS-Err-PHP                  2014-01-11 13:20:43.279  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 12    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler     12 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 12
IPS-Err-PHP                  2014-01-11 13:20:43.284  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 13    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler     13 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 13
IPS-Err-PHP                  2014-01-11 13:20:43.288  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 14    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler     14 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 14
IPS-Err-PHP                  2014-01-11 13:20:43.293  Warning: Wrong parameter type for IPS_SetVariableProfileAssociation()     Error in Script D:\IPS\scripts\23379.ips.php on Line 15    133 in IPSLibrary\app\core\IPSLogger\IPSLogger.inc.php (call IPSLogger_Out)     37 in IPSLibrary\app\core\IPSLogger\IPSLogger_PhpErrorHandler.inc.php (call IPSLogger_Err)        in IPSLogger_PhpErrorHandler     15 in 23379.ips.php (call IPS_SetVariableProfileAssociation)

Warning:  Wrong parameter type for IPS_SetVariableProfileAssociation() in D:\IPS\scripts\23379.ips.php on line 15


Jetzt hab ich Stunden mit lesen und Fehlersuche zugebracht. Auch die Werte hatte ich schon in Hochkomma, aber die Hochkomma für die Farbe hatte ich noch nicht entfernt. Wurde so vom Script ermittelt und nicht hinterfragt. In der Doku ists richtig ohne Hochkomma. Kaum hatte ich den Fred erstellt hab ichs bemerkt, getestet und funktioniert.

falsch:

IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", -3, "<", "", "-1");

richtig

IPS_SetVariableProfileAssociation("HC_Zeitr_a-r", -3, "<", "", -1);

erledigt

Bin auch zufälligerweise heute darauf reingefallen:rolleyes:

Für alle:

Das Beispiel in der Doku muss in einer Zeile korrigiert werden:


   echo 'IPS_SetVariableProfileAssociation("'.$profileName.'", '.$association['Value'].', "'.$association['Name'].'", "'.$association['Icon'].'", '.$association['Color'].');'."
";


Gruß

Burkhard

Hallo bumaas,
danke für die Korrektur. Damit fehlen mir jetzt der 2. und 3. Eintrag in der Assoziation.

Script:

<?

$Profile = IPS_GetVariableProfileList();
//print_r($Profile);

$profileName    = "HC_Zeitraum_wo-mo-qu-hj-ja";

        // erster Funktionsparameter: Profilname, zweiter Parameter (optional): neuer Profilname
        function getVariableProfileCreationCode ($profileName, $newProfileName = "")
        {
            $profile = IPS_GetVariableProfile($profileName);
            if ($profile !== false)
            {
                $profileName = (strlen($newProfileName) > 0) ? $newProfileName : $profileName;
                echo 'IPS_CreateVariableProfile("'.$profileName.'", '.$profile['ProfileType'].');'."
";
                echo 'IPS_SetVariableProfileText("'.$profileName.'", "'.$profile['Prefix'].'", "'.$profile['Suffix'].'");'."
";
                echo 'IPS_SetVariableProfileValues("'.$profileName.'", '.$profile['MinValue'].', '.$profile['MaxValue'].', '.$profile['StepSize'].');'."
";
                echo 'IPS_SetVariableProfileDigits("'.$profileName.'", '.$profile['Digits'].');'."
";
                echo 'IPS_SetVariableProfileIcon("'.$profileName.'", "'.$profile['Icon'].'");'."
";
                foreach ($profile['Associations'] as $association)
                {
                       echo 'IPS_SetVariableProfileAssociation("'.$profileName.'", '.$association['Value'].', "'.$association['Name'].'", "'.$association['Icon'].'", '.$association['Color'].');'."
";
                }
                echo "
";
            }
        }

getVariableProfileCreationCode($profileName);

?>


Ausgabe:

IPS_CreateVariableProfile("HC_Zeitraum_wo-mo-qu-hj-ja", 1);
IPS_SetVariableProfileText("HC_Zeitraum_wo-mo-qu-hj-ja", "", "");
IPS_SetVariableProfileValues("HC_Zeitraum_wo-mo-qu-hj-ja", 0, 0, 0);
IPS_SetVariableProfileDigits("HC_Zeitraum_wo-mo-qu-hj-ja", 0);
IPS_SetVariableProfileIcon("HC_Zeitraum_wo-mo-qu-hj-ja", "");
IPS_SetVariableProfileAssociation("HC_Zeitraum_wo-mo-qu-hj-ja", -3, "", "", -1);
IPS_SetVariableProfileAssociation("HC_Zeitraum_wo-mo-qu-hj-ja", 7, "Woche", "", -1);
IPS_SetVariableProfileAssociation("HC_Zeitraum_wo-mo-qu-hj-ja", 30, "Monat", "", -1);
IPS_SetVariableProfileAssociation("HC_Zeitraum_wo-mo-qu-hj-ja", 91, "Quartal", "", -1);
IPS_SetVariableProfileAssociation("HC_Zeitraum_wo-mo-qu-hj-ja", 182, "Halbjahr", "", -1);
IPS_SetVariableProfileAssociation("HC_Zeitraum_wo-mo-qu-hj-ja", 365, "Jahr", "", -1);


Screenshot des VarProfiles:
Zwischenablage-1.png

PS: In einem anderen VarProfile ists nur der 2. Eintrag.

Das liegt mit Sicherheit an den Sonderzeichen ‚<‘ und ‚>‘. Leider reichen meine PHP/HTML Kenntnisse nicht, um da weiterzuhelfen. Ist bestimmt knifflig.

Sorry

Burkhard

Hi!

Also wenn ich mit Sonderzeichen in Associations Probleme habe gehe ich immer folgenden Weg:

Das Profil inkl. aller Assoc. über die Konsole einmal anlegen.
Danach per Script dass Profil auslesen und die Assoc.-Daten per Ord()-Funktion ausgeben, dann kann man beim Erstellen per Script problematische Zeichen per chr()-Funktion einfügen.

Hier noch das Script welches ich zur Anzeige der Profildaten verwende…


<?
// Profil inkl. Assoc. ausgeben:
$profilname = 'HM_Heizung_KopieAusfuehren';    // <=== Hier den gewünschten Profilnamen eintragen

// ** Ab hier nix mehr ändern **
if (!IPS_VariableProfileExists($profilname)) {
    echo "Profil '$profilname' nicht gefunden!
";
} else {
    // Profil auslesen
    $profil = IPS_GetVariableProfile($profilname);

    // Ergebnis anzeigen:
    foreach(['ProfileName','ProfileType','Prefix','Suffix','MinValue','MaxValue','StepSize','Digits','Icon','IsReadOnly'] as $key)     {
        echo "[$key] => ".valToString($profil[$key]);
    }
    echo "
Associations:
";
    foreach($profil['Associations'] as $nr => $assoc) {
        echo "[$nr]	[Value] => float(".$assoc['Value'].")
";
        echo "	[Name] => string(".strlen($assoc['Name']).") \"".maskString($assoc['Name'])."\"
";
        echo "	[Icon] => string(".strlen($assoc['Icon']).") \"{$assoc['Icon']}\"
";
        echo "	[Color] => int(".$assoc['Color'].")
";
    }
}

function maskString($value) {
    if (strlen($value) == 0) {
        return '';
    } else {
        $result = '';
        for($l = strlen($value), $i = 0; $i < $l; $i++) {
            $ch = ord($value[$i]);
            if ($ch >= 32 && $ch <= 126) {
                $result .= $value[$i];
            } else {
                $result .= sprintf("{%u}", $ch);
            }
        }
    }
    return $result;
}

function valToString($value) {
    $valType = gettype($value);
    if (is_bool($value)) {
         return "bool(".($value ? "true" : "false").")
";
    } elseif (is_string($value)) {
        return "string(".strlen($value).") \"$value\"
";
    } else {
        return $valType."(".$value.")
";
    }
    return "";
}
?>

Das Script maskiert alle Zeichen deren ASCII-Code nicht zwischen 32 und 126 liegt aus und ersetzt sie durch {n}, wobei n der ASCII-Code des maskierten Zeichens ist.

Vorraussetzung ist natürlich, das die per Konsole erstelle Assoc. im Webfront auch richtig angezeigt wird. Ich habe z.B. in der Konsole Pseudo-Leerzeichen eingegeben, um die Button-Breiten anzupassen (ASCII 255). Die Konsole macht daraus intern irgendwie ein ASCII 160, und genau das habe ich dann auch bei der Assoc.-Erzeugung per Script verwendet. Funktioniert bisher einwandfrei.