Page 2 of 2

Re: Feature request: GUI to set multiple timers at once, depending on variables

Posted: Wed Jan 06, 2016 12:24 pm
by Jocke.g
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:
  • 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.
And then, this is where the magic happens: some code (PHP) I got from a friend once, to calculate the start time.

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);
}

Re: Feature request: GUI to set multiple timers at once, depending on variables

Posted: Wed Jan 13, 2016 10:38 am
by TotalPE
Really nicely done with the new timer has been tested by it and it seems to work just fine. Regarding the "every other week" timer , perhaps it is only me who want and need it, an alternative might be that, if it is simple and does not cause too much trouble, you might create a ordinary timer, but it reaches over two weeks instead of one week?

Re: Feature request: GUI to set multiple timers at once, depending on variables

Posted: Wed Jan 13, 2016 10:48 am
by TotalPE
Perhaps that was an stupid idea, i dont know. There has to be some way to have more than two action as well then. One on and one off action for the first week, and one on and off action for the secound week as well.

Re: Feature request: GUI to set multiple timers at once, depending on variables

Posted: Wed Jan 13, 2016 10:02 pm
by stefangsbb
Well, one idea I have been thinking of would be a "DateTimer", where you could specify date or week ranges, and it could be used to activate and deactivate alternative week timers. You could for example specify:

W1,W3,W5,10/2->13/2

I have not thought this through fully yet, but it is an idea...

Re: Feature request: GUI to set multiple timers at once, depending on variables

Posted: Thu Jan 14, 2016 7:12 am
by TotalPE
It's actually a really good idea, or if it is possible to choose the number of days from a date.
Like this:
D14,18:00,02/14->05/20 (every 14 days, time 18.00, betwen dates 02/14 and 05/20)
Or like this
D14,18:00,01/14-> (every 14 days,time 18:00,from 01/14)

I this case there only need to be just one OnAction, then I can trigger some weektimers or trigger a scene that trigger weektimers.

Re: Feature request: GUI to set multiple timers at once, depending on variables

Posted: Thu Aug 25, 2016 8:23 am
by niclas
Hi, Is this tested by someone, Having an open end Suntimer?
Jocke.g wrote: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->"

Re: Feature request: GUI to set multiple timers at once, depending on variables

Posted: Fri Aug 26, 2016 6:19 pm
by stefangsbb
Well, there is at least a unit test that tries to verify that it works, so I expect it does...