Ich habe mal eine Version für IPS V2 „übersetzt“.
Da ich sowohl IPS, als auch PHP-Anfänger bin, möge man mir einige „unvollkommene“ Lösungsansätze verzeihen.
$NDAYS = 3; // Intervall in Tagen für Setzen der Zeit
// Wo sind wir? Dort legen wir unsere Variablen an
$script_info = IPS_GetObject($IPS_SELF);
$parent_info = $script_info['ParentID'];
// we need this variables, to be created if needed
$VarName = "FHT_SET_MINUTE_FHTID";
$VarID = IPS_GetVariableIDByName($VarName, $parent_info);
if ($VarID == 0) // Variable existiert nicht
{
// this is the ID of FHT that needs setting
$VarID = IPS_CreateVariable(1); // Typ Integer
IPS_SetName($VarID, $VarName); // Benennen der eben erstellten Variablen
IPS_SetParent($VarID, $parent_info);
}
if (GetValue($VarID) > 0 )
{
// there is a minute set command waiting, so we send it
$FHT_ID = GetValue($VarID);
// this is te FHT to send to
FHT_SetMinute ($FHT_ID, intval(date('i')));
FHT_SetMode($FHT_ID, 1);
SetValue($VarID,0);
// switch off the timer
IPS_SetScriptTimer ($IPS_SELF,0);
$LOGMSG = 'Command sent to ' . $FHT_ID . ' - Set Minute to ' . date('i') ;
IPS_LogMessage ('Update FHT Clock', $LOGMSG);
return;
}
//Alle Modulnamen mit GUID ausgeben
foreach(IPS_GetModuleList() as $guid)
{
$module = IPS_GetModule($guid);
if ($module["ModuleName"] == "FHT"){ // Wenns ne FHT ist
$moduleID = $module["ModuleID"]; // ModuleID merken
}
}
unset($module);
unset($guid);
$AlleFHTs = (IPS_GetInstancesByModuleID($moduleID)); // Alle FHT-Instanzen laden
//
if (intval(date('i')) > 5 )
{
if (intval(date('i')) < 55 )
{
$FREE_BUFFERS = FHZ_GetFreeBuffer(32647 /*[FHZ1X00PC]*/);
if ($FREE_BUFFERS == 10)
{
foreach($AlleFHTs as $FHT_ID)
{
$LAST_CLOCK_VARNAME = 'FHT_LAST_CLOCK_SET_'.$FHT_ID;
$LAST_CLOCK_VAR_ID = IPS_GetVariableIDByName($LAST_CLOCK_VARNAME, $parent_info);
if ($LAST_CLOCK_VAR_ID == 0) // Variable existiert nicht
{
// this is the ID of FHT that needs setting
$LAST_CLOCK_VAR_ID = IPS_CreateVariable(1); // Typ Integer
IPS_SetName($LAST_CLOCK_VAR_ID, $LAST_CLOCK_VARNAME); // Benennen der eben erstellten Variablen
IPS_SetParent($LAST_CLOCK_VAR_ID, $parent_info);
}
// read when clock was set
$LAST_CLOCK_SET =GetValue($LAST_CLOCK_VAR_ID);
// if last update more than n days ago then send time to fht
if (TIME() - $LAST_CLOCK_SET > ($NDAYS * 86400))
{
$STELL_VARIABLE = (IPS_GetStatusVariable($FHT_ID, "PositionVar"));
$STELL_VARIABLE_ID = $STELL_VARIABLE["VariableID"];
// check wehn it was last received
$STELL_VARIABLE_INFO = IPS_GetVariable($STELL_VARIABLE_ID);
$LAST_STELL_UPDATE = $STELL_VARIABLE_INFO["VariableUpdated"];
// Positions come about every 116 seconds, this is the time left until the next pos comes.
// a tx timeslot is available just before, so we send our command 5 beofre the slot is open
// if the commands are sent to late , then change this value (111) a bit
$MINUTE_TO_SET = 111- (TIME() -$LAST_STELL_UPDATE );
if ($MINUTE_TO_SET < 15)
{
// to close to next timeslot, better take the next one
$MINUTE_TO_SET=$MINUTE_TO_SET + 116;
}
// we rememeber the FHT we need the miute to send to
SetValue($VarID, $FHT_ID);
// we call ourselves just before the timeslot is ready
IPS_SetScriptTimer ($IPS_SELF, intval( $MINUTE_TO_SET ));
// update the Variable that remebers last time setting for this FHT
SetValue ($LAST_CLOCK_VAR_ID,TIME());
$LOGMSG = 'Set Minute Command queued to be sent to ' . $FHT_ID . ' in ' . $MINUTE_TO_SET . ' seconds';
IPS_LogMessage ('Update FHT Clock', $LOGMSG);
// done
return;
}
}
}
}
}
Bei der Ermittlung der FREE_BUFFERS habe ich direkt meine FHZ Objekt-ID eingesetzt. Hier kann man natürlich analog der FHT-Ermittlung vorgehen, um z.B. mehrere FHZ zu bedienen.
Gruß
HausAuto