Hello,
I want to build a stopwatch. Unfortunately, I do not know how to do it. The clock should start at a status change. and refresh every fifteen minutes.
I’ve already done a little bit of DIY. But I can not get any further.
I have a switch when the time is up. and the item (stopwatch) should be updated every 15 minutes.
Es soll nur stunden und minuten angezeigt werden. 112std:15min
What I already have: Item
Switch Gmc_test
Time Gmc_stoppuhr "Stoppuhr [%1$td.%1$tm]"
Sitemap
Switch item=Gmc_test
DateTime item=Gmc_stoppuhr
rules
rule "Stoppuhr"
when
Item Gmc_test changed or
Time cron "0 0/15 * * * ?"
then
val long start
val long dauer
if (Gmc_test.state==ON)
{
start = now.minutes
}
else
{
dauer = now.minutes - start
postUpdate(Gmc_stoppuhr,dauer)
}
end
Using this cron job the rule will run every 15 minutes regardless of the switch state.
For a timer you could create a proxy item and use the expire binding.
See my example rule below that uses iPhone detection and the expire binding as a timer. The rule executes when gPresent receives an update. If no one is detected a timer set for 20 minutes is started. After the 20 minute timer expires then Presents will send a command off. If during the 20 minutes presents is detected then the timer is canceled.
If you modify the items and the expire timer, to suit your needs, you should be able to use the rule with a switch as well.
rule "gPresent updated, at least one change of state"
when
Item gPresent received update
then
// someone came home
if(gPresent.state == ON && Present.state != ON) {
Present_Timer.postUpdate(OFF) // cancel the timer if necessary
Present.sendCommand(ON)
}
// no one is home and timer is not yet ticking (otherwise endless loop)
else if(gPresent.state == OFF && Present.state != OFF && Present_Timer.state != ON) {
Present_Timer.sendCommand(ON) // start the timer
}
end
rule "Present_Timer expired"
when
Item Present_Timer received command OFF
then
Present.sendCommand(OFF)
end