Re: Feature request: GUI to set multiple timers at once, depending on variables
Posted: Wed Jan 06, 2016 12:24 pm
Great, I will try this out later on. I was just wondering, the documentation does not tell how to do if you for example want a start time, but no end time, or vice versa. Does it work to just type "06:45->"
For example I would like my blinds to go up in the morning when I'm supposed to wake up, but i use my remote when i want them to go down. Would probably also be usefull if you have light turned on over midnight (->01:00,06:00->R,S->).
And the other thing I thought of, the CarTimer. I think it would be better to just make an own HomeItem for this one, instead of combining a lot of them in a big mess. I'm not sure if this is possible to implement as Homeitem, but I think something like this would be nice.
You give the HomeItem the following fields:
For example I would like my blinds to go up in the morning when I'm supposed to wake up, but i use my remote when i want them to go down. Would probably also be usefull if you have light turned on over midnight (->01:00,06:00->R,S->).
And the other thing I thought of, the CarTimer. I think it would be better to just make an own HomeItem for this one, instead of combining a lot of them in a big mess. I'm not sure if this is possible to implement as Homeitem, but I think something like this would be nice.
You give the HomeItem the following fields:
- TargetTime, the "Leave home time" for each day of week(or leave blank, weekends).
- OutdoorTemp, A link to another HomeItem that is the outdoor thermometer.
- Links to actions for on and off.
- Optional: OffDelay, a field telling how long after TargetTime will the engine heater stay on (15 minutes?).
- Optional: some of the other values to interpolate function, to tweak how early it should start.
Code: Select all
$Started = 0;
$StopTime = $TargetTime - $OffDelay
while (1)
{
$CurTime = new DateTime();
$StartTime = CalculateStartTime($TargetTime, $OutdoorTemp);
// Kolla om det är dags att slå på
if ($Started == 0 && $CurTime > $StartTime && $CurTime < $StopTime)
{
ExecuteOnAction();
$Started = 1;
echo "Startade motorvärmaren\n";
}
elseif ($Started == 1 && $CurTime > $StopTime)
{
ExecuteOffAction();
$Started = 0;
echo "Stoppade motorvärmaren\n";
}
Sleep(60);
}
function CalculateStartTime($TargetTime, $OutdoorTemp)
{
$Minutes = Round(Interpolate(-20, 120, 10, 0, 0, 120, $OutdoorTemp));
echo "Utetemperaturen är " . $OutdoorTemp . " C\n";
echo "Starta i förväg med " . $Minutes . " minuter\n";
// Beräkna starttid
$StartTime = clone $TargetTime;
$StartTime->sub(new DateInterval('PT'.$Minutes.'M'));
echo "Starttid " . $StartTime->Format(DateTime::ATOM) . "\n";
return $StartTime
}
// Linear interpolation between two known points with limit to endpoints
function Interpolate($xmin, $ymin, $xmax, $ymax, $min, $max, $x)
{
if ($x == $xmin)
return $ymin;
else if ($x == $xmax)
return $ymax;
else
return min(max($ymin+($x-$xmin)*($ymax-$ymin)/($xmax-$xmin), $min), $max);
}