Hey guys,
I have a little issue with my windows notification rule. I’ve just chnaged it, so that it is group based and this works very well, but I had the issue that there was only one timer which have been created for all the windows in the gFenster group. I’ve tried to change it now, but this ends in errors.
import java.util.Map
import org.openhab.model.script.actions.*
val Map<String, Timer> windowtimer = newHashmap
val currMonth = now.getMonthOfYear
var int windowtime = 0
//var windowsmessage = "Fehler"
rule "Fenster Meldung"
when
Member of gFenster received update
then
val window = triggeringItem
//var Timer windowtimer = null
if(window.state.toString=="OPEN") {
gFenster.members.filter[window | window.state.toString=="OPEN"].forEach[window |
if(windowtimer.get(window.name) !== null) {
windowtimer.get(window.name).cancel()//cancel windowtimer
windowtimer.put(window.name, null) // remove the timer from the Hashmap
}
else {
if(currMonth == 1 || currMonth == 2 || currMonth == 12) {
windowtime = 5
}
else if(currMonth == 3 || currMonth == 11) {
windowtime = 10
}
else if(currMonth == 4 || currMonth == 9) {
windowtime = 15
}
else if(currMonth == 5 || currMonth == 10) {
windowtime = 20
}
else if(currMonth == 6 || currMonth == 7 || currMonth == 8) {
windowtime = 25
}
windowtimer.put(window.name, createTimer(now.plusMinutes(windowtime))) [|
val StringBuilder windowsmessage = new StringBuilder
windowsmessage.append(windowtime + " Minuten Lüftung abgeschlossen.")
windowsmessage.append(transform("MAP", "Fensterkontakt.map", window.name) + " Fenster schließen.")
logInfo("Fenstermeldung",transform("MAP", "Fensterkontakt.map", window.name) + "Fenster ist länger als {} Minuten geöffnet!",windowtime)
sendPushbulletNote("DEFAULT", "riza@as-lan.eu", "Badezimmer Fenster offen", windowsmessage.toString)
sendBroadcastNotification(windowsmessage.toString)
say(windowsmessage, null, "chromecast:audio:kueche")
windowtimer.get(window.name).cancel() //cancel windowtimer
windowtimer.put(window.name, null) // remove the timer from the Hashmap
]
}
]
}
else if (window.state.toString == "CLOSED") {
if(windowtimer.get(window.name) !== null) windowtimer.get(window.name).cancel() //cancel windowtimer
windowtimer.put(window.name, null) // remove the timer from the Hashmap
}
end
This is my current rule. The first thing is, that I’m using a wildcard import and I don’t know what exactly do I have to import it the right way?
[INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'komfort_fenster-timer.rules', using it anyway:
The use of wildcard imports is deprecated.
But the more important thing is, that my rule is not working. If i open my “virtual window”, i’m getting the following errors
[WARN ] [me.internal.engine.RuleContextHelper] - Variable 'windowtimer' on rule file 'komfort_fenster-timer.rules' cannot be initialized with value 'newHashmap': The name 'newHashmap' cannot be resolved to an item or type; line 4, column 38, length 10
[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Fenster Meldung': cannot invoke method public abstract java.lang.Object java.util.Map.get(java.lang.Object) on null
I think for you guys it should be a little to solve this issue. I would be very happy if you could help me.
Regards,
Riza