I use duiffie´s rule and it work well. Is just extended it a little bit for my needs, but I´m still not familiar with javascript. Here is my code:
import java.util.Map
val Map<String, Timer> OpenWindowTimers = newHashMap
val Functions$Function2<ContactItem, Map<String, Timer>, Boolean> checkOpenWindow = [
windowItem,
timerMap |
var String myTimerKey = windowItem.name.toString
var String season_name = transform("MAP", "astro.map", Jahreszeit.state.toString)
var winopentime = 0
switch Jahreszeit {
case Jahreszeit.state == "SPRING" : winopentime = 15
case Jahreszeit.state == "SUMMER" : winopentime = 30
case Jahreszeit.state == "AUTUMN" : winopentime = 10
case Jahreszeit.state == "WINTER" : winopentime = 5
default : winopentime = 5 //just in case if no season is set
}
logInfo("Fenster-Check", "Jahreszeit ist " + season_name )
if (windowItem.state == CLOSED) {
if (timerMap.get(myTimerKey) !== null) timerMap.get(myTimerKey).cancel()
} else if (windowItem.state == OPEN) {
timerMap.put(myTimerKey, createTimer(now.plusMinutes(winopentime)) [|
timerMap.put(myTimerKey, null)
val String shortName = transform("MAP", "windowShortName.map", windowItem.name.toString)
val String longName = transform("MAP", "windowLongName.map", windowItem.name.toString)
logInfo("Fenster-Check", shortName + " ist seit "+ winopentime +" Min. offen")
sendBroadcastNotification(longName + " ist seit "+ winopentime +" Min. offen")
echodotWZ_reminder.sendCommand(longName + " ist seit "+ winopentime +" Minuten offen")
])
}
true
]
rule "Fenster-Check"
when
Item gWindoors received update
then
logInfo("Fenster-Check", "Fenster/Tür hat sich verändert")
Thread::sleep(500) // this gives the persistence service time to store the last update
val lastUpdatedWindowItem = gWindoors.members.filter[s|s.lastUpdate("mapdb") !== null].sortBy[lastUpdate("mapdb")].last as ContactItem
checkOpenWindow.apply(lastUpdatedWindowItem, OpenWindowTimers)
end
What i´ve done is simple, I just use the astro binding to check which season it is and depending on that, set a specific amount of minutes for the timer.
What I still want is a further extension to recheck if a window is still open after the first timer expired. I know there´s a command to reschedule a timer: https://docs.openhab.org/addons/actions.html#timers
Could someone assist to make this possible?