Nachdem ich bis eben dran gesessen habe, habe ich den Fehler hoffentlich gefunden. Das Script reagiert nun auch auf Änderung der Variablen „imhome“, „imaway“ und „party“ indem es die Temperatur nicht nur in die „vcs1_soll_temp“ reinschreibt, sondern auch an das FHT80B sendet.
Irgendwo bei Zeile 376 hieß es:
if ($IPS_SENDER == "Variable")
if ($IPS_VARIABLE == "__imhome" || $IPS_VARIABLE == "__imaway" || $IPS_VARIABLE == "__party"){
Geändert in
if ($IPS_VARIABLE == $V_IMHOME || $IPS_VARIABLE == $V_IMAWAY || $IPS_VARIABLE == $V_PARTY){
und schon läufts. Die Variablen $V_IMHOME etc. definiere ich ganz oben im Script. Sie enthalten die IDs ver Variablen.
Wenn ich das richtig beobachte, habe ich nun „nur noch“ folgendes Problem:
Bisher hatte ich nur ein einziges Profil, nämlich DW. Da nun der manuelle Eingriff am FHT80B funktioniert, habe ich angefangen, Profile zu erstellen.
Wenn imaway TRUE ist, wird merkwürgerweise die Temperatur aus dem Profil „DW“ übernommen. Wenn imahome TRUE ist, wird die Temperatur aus aus „IW“ übernommen, was ja auch korrekt ist.
Wenn aber imaway und imhome beide FALSE sind, greift bei mir automatisch die „IW“ Einstellung obwohl - wenn ich es richtig verstanden habe - die „DW“ Einstellung aktiv werden müsste. Wo ist das Problem?
Ich werde morgen mal weitertesten, wie sich das Script nun verhält…
Gruß,
Christoph
Hier noch einmal alles:
<?
/*
*******************************
IP-SYNCOM Event Scripting
*******************************
*/
//File: sFHTs.ips.php PUBLIC : 0.70 date 08/11/06
//File: sFHTs.ips.php BETA VERSION : 0.69 date 04/11/06 '7' settings in .ini weekend bad interpret bug by Prof
//File: sFHTs.ips.php BETA VERSION : 0.68 date 01/11/06 flank-detection problem due to TimerEvent and RunScript
//File: sFHTs.ips.php BETA VERSION : 0.67 date 29/10/06 flank-detection doesn't work in S regime. bug by Torsteng
//File: sFHTs.ips.php BETA VERSION : 0.66 date 18/06/06 Back to basic - no good
//File: sFHTs.ips.php BETA VERSION : 0.65 date 18/06/06 semaphore test
//File: sFHTs.ips.php BETA VERSION : 0.64 date 17/06/06 debug switch
//File: sFHTs.ips.php PUBLIC : 0.63 date 23/01/06
//
//Events : __imhome, __imaway, __party and all FHT_status-intervention variables
/*
Copyright rules applie under GNU-regulations
rest of copyright text ToDo
*/
// Variablen
$V_IMHOME = 18357 /*[OG\Zimmer CS\Heizung\Variablen\__imhome]*/ ;
$V_IMAWAY = 18351 /*[OG\Zimmer CS\Heizung\Variablen\__imaway]*/ ;
$V_PARTY = 48393 /*[OG\Zimmer CS\Heizung\Variablen\__party]*/ ;
$V_INHIBIT = 13117 /*[OG\Zimmer CS\Heizung\Variablen\__fht_inhibit]*/ ;
$V_DEBUG = 41022 /*[OG\Zimmer CS\Heizung\Variablen\__debug]*/ ;
include("GlobalDefines.ips.php");
/* variables needed in GlobalDefines.ips.php !!
see "tempsettings.ini" and modifie to your environment /*
/********** USER SETTINGS ***********************************************/
$tempfilepath=__myhome."tempsettings.ini"; //default: 'tempsettings.ini'
// |---> defined in GlobalDefines.ips.php
$use_imhome = true;
// Note : A IPS variabele '__iamhome' should exist !!
/* use this switch to overrule general settings
the effect is that if IPS-variable "__imhome" = true
the HOLIDAY temperature is sent as the result of
this function
!! ATTENTION BETA WORK !!
19/11/2005 : I am not happy with how this implemented but it's a start
*/
$use_imaway = true;
// Note : A IPS variabele '__iamaway' should exist !!
/* use this switch to overrule general settings
the effect is that if IPS-variable "__imaway" = true
the AWAY temperature is sent as the result of
this function
!! ATTENTION BETA WORK !!
*/
$use_party = true;
// Note : A IPS variabele '__party' should exist !!
/* For all the party people out there ;-)
Do YOU Like the Way YOU Feel when YOU Shake
the effect is that if IPS-variable "__party" = true
the party settings applie without checking days or dates.
So starting on a Saturday will set party temperatures until
you set __party=false on the Wednesday. (Oh my God what a party)
*/
/********** END OF USER SETTINGS ****************************************/
/********** ADAPTATION TO YOUR ENVIROMENT *******************************
Every FHT has to have 2 variables with the names hereunder
v(your-name)_soll : f.i. "vliv_temp_soll" = FHT soll temp in livingroom
o(your-name) : f.i. "oliv_temp" = device ID of the
FHT instance (set in GlobalDefines.ips.php)
*********** END ADAPTATION **********************************************/
/********** DEBUG SWITCHES **********************************************/
$softswitch = true; /* Send the temp-settings to FHT or not
If you're debugging set it to false
so FHZ won't be overbuffered */
$use_sollwert = false;
$sollwert = "14"; //is 'use_sollwert' = true then take this value
// if you want a master-debug switch : create an IPS variabele "__debug"
if (IPS_VariableExists($V_DEBUG)){
$debug = GetValueBoolean($V_DEBUG);
} else {
$debug = true; // set to true if you want to enable echo-output
}
/* logfilepath since we are dealing with variables which cannot be show in
the direct output window. */
$logfilepath=__mylogs."Heizung/tempSENT.txt";
// $IPS_SENDER = "TimerEvent";
/********** END DEBUG ***************************************************/
if ($IPS_SENDER == "Designer"){
//do not run when event is triggered by designer
return;
}
if (IPS_VariableExists($V_INHIBIT)){
if (GetValueBoolean($V_INHIBIT)){
if($debug) echo("INHIBITED by '__fht_inhibit'");
return;
}
}
if ($IPS_SENDER == "Variable"){
/* Switch ONLY when __imaway becomes true or __imhome becomes true
die if false -> script will be triggered in max 30 minutes.
if settings change from imhome -> imaway, then FHZ buffer get's
overbuffered because script did run 2 times
imhome -> false, imaway -> true x 5 FHT-devices = buffer overrun */
if ($IPS_VARIABLE == "__imaway" && !GetValueBoolean($V_IMAWAY)) die;
// die when imhome = false
if ($IPS_VARIABLE == "__imhome" && !GetValueBoolean($V_IMHOME)) die;
if ($IPS_VARIABLE == "__party" && !GetValueBoolean($V_PARTY)) die;
//$lastrun=IPS_GetLastRun("GetTemp");
}
if (!file_exists("$tempfilepath")) {
echo("
******* ERROR: Please install '$tempfilepath'
");
die;
}
if (!file_exists("$tempfilepath")) {
echo("
******* ERROR: Please install '$tempfilepath'
");
die;
}
$handle=fopen("$tempfilepath", "r");
if (!$handle){
// error cannot open file
echo("******* ERROR: Cannot open file '$tempfilepath'
");
}
//init variable
$aktor = array();
$now = getdate();
$isholiday = false;
$isparty = false;
$holiday="";
$season = "";
$today="";
$alldays="";
$weekend="";
$imhome=false;
$party=false;
$temp_rule="";
if ($use_imhome && IPS_VariableExists($V_IMHOME)){
$imhome = GetValueBoolean($V_IMHOME);
} elseif ($use_imhome) {
echo("
******* NOTICE: Variabele '__imhome' not found as a valid IPS variabele
");
$imhome = false;
} else {
$imhome = false;
}
if ($use_imaway && IPS_VariableExists($V_IMAWAY)){
$imaway = GetValueBoolean($V_IMAWAY);
} elseif ($use_imaway) {
echo("
******* NOTICE: Variabele '__imaway' not found as a valid IPS variabele
");
$imaway = false;
} else {
$imaway = false;
}
if ($use_party && IPS_VariableExists($V_PARTY)){
$party = GetValueBoolean($V_PARTY);
} elseif ($use_party) {
echo("
******* NOTICE: Variabele '__party' not found as a valid IPS variabele
");
$party = false;
} else {
$party = false;
}
// the serious work start with settin' the inhibit switch
SetValueBoolean($V_INHIBIT,true);
// end modifie
while(!feof($handle)) {
$buffer = fgets($handle);
Switch (substr($buffer,0,1)) {
case "@":
//general settings
if (substr($buffer,1,7) == "season=") {
$season = substr($buffer,8,1);
}
if (substr($buffer,1,1) == "H") {
if ((sprintf("%02d",$now["mon"])."/".sprintf("%02d",$now["mday"]) == substr($buffer,2,5)) or (sprintf("%02d",$now["mon"])."/".sprintf("%02d",$now["mday"])."/".$now["year"] == substr($buffer,2,10))) {
$isholiday = true;
$temp_rule = substr($buffer,strpos($buffer,"#")+1,strlen($buffer)-strpos($buffer,"#")-3);
if ($debug) echo "temp rule : $temp_rule";
}
}
break;
case "D":
//DEFAULT lines
if (substr($buffer,1,1) == "$season" && chop(substr($buffer,4,14))=="default"){
// get default default or default room
// aktor("default" -> $default OR "room" -> $default)
$default = substr($buffer,27,48);
} elseif (substr($buffer,1,1) == "$season") {
$aktor[chop(substr($buffer,4,14))]["default"] = substr($buffer,27,48);
}
break;
case "H":
//HOLIDAY table entries
if ($isholiday) {
// NOTE THEM DOWN IN array[aktor,["holiday"]
if (substr($buffer,1,1) == "$season") $aktor[chop(substr($buffer,4,14))]["holiday"]= substr($buffer,27,48);
} else {
if (substr($buffer,1,1) == "$season") $aktor[chop(substr($buffer,4,14))]["iamhome"]= substr($buffer,27,48);
}
break;
case "I":
//Table entries
// GET RID OF THIS INSTRUCTION GET THEM ALLL ;-)
// array[substr(....),alldays, weekends, thisday]
// ???? Should we apply precendence RULE here ??
// WE SHOULD HAVE ALL INFO --> see tempfile.ini
// SO HERE WE DEPEND THE RULE TO APPLY
// WHAT IF NOT ?? NO APPLICABLE ENTRY ?? THEREFORE ALL THESE IF INSTRUCTIONS
if ((substr($buffer,1,1) == "$season") and (substr($buffer,2,1) == "9")) $aktor[chop(substr($buffer,4,14))]["alldays"] = substr($buffer,27,48);
if ((substr($buffer,1,1) == "$season") and (substr($buffer,2,1) == "7") and (($now["wday"] == 0) or ($now["wday"] == 6))) $aktor[chop(substr($buffer,4,14))]["weekend"] = substr($buffer,27,48);
if ((substr($buffer,1,1) == "$season") and (substr($buffer,2,1) == $now["wday"])) $aktor[chop(substr($buffer,4,14))]["today"]= substr($buffer,27,48);
break;
case "W":
// IamAway settings
if (substr($buffer,1,1) == "$season" && chop(substr($buffer,4,14))=="default"){
// get default default or default room
// aktor("default" -> $default OR "room" -> $default)
if ($imaway) $default = substr($buffer,27,48);
}
break;
case "P":
// PaAaRtY settings
// no date-jump will occure !!
// tryout 26/11/2005
if (substr($buffer,1,1) == "$season") $aktor[chop(substr($buffer,4,14))]["party"]= substr($buffer,27,48);
break;
default:
//only thing to expect are comments '#' and temp settings
// PUT IN ARRAY !!! WE NEED THEM LATER
// USE array[sign => value]
if (substr($buffer,0,1) <> "#") {
$temp[substr($buffer,0,1)] = substr($buffer,1,5);
}
}
}
$temp["0"]=false;
$temp["1"]=true;
fclose($handle);
if ($debug) {
foreach($aktor as $key => $value){
$thisday = $now["wday"];
if ($debug) echo("
RESULT for '$key'
--------
");
if ($debug) echo(" now :'". $now["hours"] .":". $now["minutes"] . "'
");
if ($debug) echo(" today is nr# : $thisday
");
if ($debug) echo(" season : $season
");
if ($debug) echo(" Is it a holiday : $isholiday
");
if ($debug) echo(" Check precendence hereunder
");
if ($debug) echo(" Am I home ? : $imhome
");
if(array_key_exists("iamhome",$value) && $debug)echo(" IAmHome : ".$aktor[$key]["iamhome"]."
");
if ($debug) echo(" Am I away ? : $imaway
");
if(array_key_exists("iamaway",$value) && $debug)echo(" IAmAway : ".$aktor[$key]["iamaway"]."
");
if(array_key_exists("holiday",$value) && $debug)echo(" holiday : ".$aktor[$key]["holiday"]."
");
if ($debug) echo(" Paaaartyy ? : $party
");
if(array_key_exists("party",$value) && $debug)echo(" Party : ".$aktor[$key]["party"]."
");
if(array_key_exists("today",$value) && $debug)echo(" today : ".$aktor[$key]["today"]."
");
if(array_key_exists("weekend",$value) && $debug)echo(" weekends : ".$value["weekend"]."
");
if(array_key_exists("alldays",$value) && $debug)echo(" alldays : ".$aktor[$key]["alldays"]."
");
if(array_key_exists("default",$value) && $debug)echo(" default rule : ".$aktor[$key]["default"]."
");
if ($debug) echo(" def. def. rule: $default
");
if ($debug) echo("--------------------------------------------------
");
} //for
} //if
/* precendence rules
ON ALL ELEMENTS OF ARRAY = Aktors
VARIABLES = FIELDS OF ARRAY ("AKTOR" [ROOMDEFAULT, HRule, DayRULE, RESULT, soll)
NEGATIVE LOGIC Variables are filled in IF applicable */
if ($debug) echo"
";
foreach($aktor as $key => $value){
if (!array_key_exists("holiday", $value)) {
if (!array_key_exists("today", $value)) {
if (!array_key_exists("weekend", $value)) {
if (!array_key_exists("alldays", $value)) {
if (!array_key_exists("default", $value)) {
$aktor[$key]["result"] = $default;
if ($debug) echo "res = def. def";
} else {
$aktor[$key]["result"] = $value["default"];
if ($debug) echo "res = default";
} // if
} else {
$aktor[$key]["result"] = $value["alldays"];
if ($debug) echo "res = alldays";
}
} else {
$aktor[$key]["result"] = $value["weekend"];
if ($debug) echo "res = weekend";
}
} else {
$aktor[$key]["result"] = $value["today"];
if ($debug) echo "res = today";
}
} else {
$aktor[$key]["result"] = $value["holiday"];
if ($debug) echo "res = holiday";
}
// attempt to set IAmHome rule !!
if ($use_imhome and $imhome) {
if (array_key_exists("iamhome", $value)){
$aktor[$key]["result"] = $value["iamhome"];
echo "
OVERRULED RESULT set to HOLIDAY because I AM HOME
";
}
}
// attemp to set Away-rule
if ($use_imaway and $imaway) {
$aktor[$key]["result"] = $default;
if ($debug) echo ("
OVERRULED RESULT set to AWAY
");
}
// attempt to set Party rule !!
if ($use_party and $party) {
if (array_key_exists("party", $value)){
$aktor[$key]["result"] = $value["party"];
echo "
OVERRULED RESULT set to PaAaRrTYyyyy
";
}
}
if ($debug) echo("
For '$key' I did choose : '".$aktor[$key]["result"]."'
");
}
// here we get the temperature out of string
// USE ARRAY["AKTOR", "soll"]
// change 11/10/2005 'floor' into 'round' because otherwise allways back to ??h00 instead of ??h00 or ??h30
$pos = $now["hours"]*2 + round($now["minutes"]/30);
$prevpos = $pos - 1;
if ($debug) echo("hours: " . $now["hours"] . " hours *2 = " . $now["hours"]*2 . "round($now[minutes]/30) = " . (round($now["minutes"]/30) . "
"));
if ($debug) echo "pos = '$pos' (check midnight !!
";
// end change
foreach($aktor as $key => $value){
$aktor[$key]["soll"] = $temp[substr($value["result"],$pos,1)];
if ($debug) echo "res : '" . $value["result"]."'
";
if ($debug) echo "time : '12345678901234567890123456789012345678'
";
if ($debug) echo "temp = '" . $aktor[$key]["soll"]."'
";
}
// and now deal with the state-event.
// detect flanks
//if ($temp[substr($value["result"],$pos,1)] <> $temp[substr($value["result"],$pos,1)]){
// 11/10/2005 This is still a burdon !! damn boy ... where do you wanne drive the MIN-TEMP to ? and MAX-TEMP ?
//if ($use_imhome and $imhome) {
// $soll = $temp["+"];
// $status = "OVERRULED set to";
//} elseif ($use_imhome) {
// $soll = $temp["-"];
// $status = "OVERRULED set to";
//} else {
// $status = substr($result,$pos,1)." : ";
//}
// 19/11/2005 : decided when 'I am Home' is selected to choose 'holiday'-rule
$handle = fopen("$logfilepath","a");
$neg = "NOT (SSw)";
if ($softswitch) $neg = "";
// GET ALL AKTORS OUT OF ARRAY["AKTOR","SOLL"] = nice result of all the -above- work
// loop here : for every aktor in array : setTemp(Aktor, argument);
$junk = 1;
foreach($aktor as $key => $value){
if ($use_sollwert) {
echo("OVERRULED BY use_sollwert");
$value["soll"]= $sollwert;
}
SetValueFloat($key."_soll",floatval($value["soll"]));
if ($debug) echo("FHT temp for '$key"."_soll' set to '".$value["soll"]."' !!
");
// as the result of the function set aktors to soll
$thisinstance = "o" . substr($key,1);
if (!defined($thisinstance)) {
echo("
******* NOTICE: FHT-ID ($thisinstance) not defined in GlobalDefines.ips.php
");
} elseif (!IPS_InstanceExists(constant($thisinstance))) {
echo("
******* NOTICE: FHT with ID '". constant($thisinstance) . "' is not a valid instance in IPS.
");
} else {
if ($IPS_SENDER == "Variable") {
// geändert, da Triggern auf imaway etc nichts gebracht hat.
//if ($IPS_VARIABLE == "__imhome" || $IPS_VARIABLE == "__imaway" || $IPS_VARIABLE == "__party"){
if ($IPS_VARIABLE == $V_IMHOME || $IPS_VARIABLE == $V_IMAWAY || $IPS_VARIABLE == $V_PARTY){
if ($softswitch) FHT_SetTemperature(constant($thisinstance),floatval($value["soll"]));
if ($debug) echo("FHT_SetTemp for $thisinstance $neg SENT due to '$IPS_VARIABLE'-trigger
");
if ($debug) fwrite($handle, date("d.m.y")." ". date("H:i:s")." $IPS_SENDER - FHT_SetTemp for $thisinstance $neg SENT due to '$IPS_VARIABLE'-trigger
");
} else {
if ($debug) fwrite($handle, date("d.m.y")." ". date("H:i:s")." $IPS_SENDER - $thisinstance is set EXTERNALLY to " . GetValueFloat($key."_state") . "°C due to '$IPS_VARIABLE'-trigger (no value sent... logging only)
");
}
// Zeile geändert da manuelles Drehen am Rad nicht funktioniert hat
// } elseif ($IPS_SENDER == "RunScript") {
} elseif ($IPS_SENDER == "TimerEvent") {
// only set soll-temp if there are changes required (flank-detection) to reset manual intervention
if ($debug) echo("Trigger : timerevent, Is '" . $temp[substr($value["result"],$pos,1)] . "' = '" . $temp[substr($value["result"],$prevpos,1)] . "' ?
");
if ($temp[substr($value["result"],$pos,1)] <> $temp[substr($value["result"],$prevpos,1)]){
//flank detected
if ($softswitch) FHT_SetTemperature(constant($thisinstance),floatval($value["soll"]));
if ($debug) echo("FHT_SetTemp for $thisinstance $neg SENT due to change of setting (flank detection).
");
if ($debug) fwrite($handle, date("d.m.y")." ". date("H:i:s")." $IPS_SENDER - FHT_SetTemp for $thisinstance $neg SENT due to change of setting (flank detection).
");
} else {
if ($debug) fwrite($handle, date("d.m.y")." ". date("H:i:s")." $IPS_SENDER - No flank detected for $thisinstance.
");
}
} else {
//manual exec.
if ($softswitch) FHT_SetTemperature(constant($thisinstance),floatval($value["soll"]));
if ($debug) echo("FHT_SetTemp for $thisinstance $neg SENT due to manual-exec.
");
if ($debug) fwrite($handle, date("d.m.y")." ". date("H:i:s")." $IPS_SENDER/MANUAL - FHT_SetTemp for $thisinstance $neg SENT due to manual-exec.
");
}
}
// ugly way to handle FHZ buffer issues
// should be done by multiple passes so max 6 commands every 6 minutes
// multiple passes ToDo
// Paresy talked about a FHT1000 buffer; maybe there is a way to deal with this??
// removed in version: 0.66 FHT-buffer now in place
//if (bcmod($junk, 6) == 0) IPS_Sleep(1000*10); // wait 10 seconds FHZbuffer !!;
//$junk += 1;
}
// 2006/05/30 modifie due to multi-hreads
SetValueBoolean($V_INHIBIT,false);
// 2006/05/30 end modifie
if ($debug) echo("Finished
");
if ($debug) fclose($handle);
?>