Hi,
for a while I used openHAB rarly, now as OH2 should be stable, I started over again. Now as I start clean, I would like to learn how to write more effective and clever rules.
I have a window and would like to indicate with my hue, if it stays open for a longer period. At the moment I have three rules and it is working:
var Timer GaesteWC_timer = null
rule "Fensteralarm GĂ€ste-WC Offen"
when
Item EG_Fenster_Gaeste_WC changed to OPEN
then
logInfo("GaesteWC_timer","Fenster ist OFFEN")
GaesteWC_timer = createTimer(now.plusMinutes(5), [|
EG_Hue_bloom_Wohnzimmer.sendCommand(HSBType::RED)
])
end
rule "Fensteralarm GĂ€ste-WC TILTED"
when
Item EG_Fenster_Gaeste_WC changed to TILTED
then
logInfo("GaesteWC_timer","Fenster ist TILTED")
GaesteWC_timer = createTimer(now.plusMinutes(7), [|
EG_Hue_bloom_Wohnzimmer.sendCommand(HSBType::GREEN)
])
end
rule "Fensteralarm GĂ€ste-WC Closed"
when
Item EG_Fenster_Gaeste_WC changed to CLOSED
then
if(GaesteWC_timer != null) {
EG_Hue_bloom_Wohnzimmer.sendCommand(OFF)
logInfo("GaesteWC_timer","Canceling the Timer")
GaesteWC_timer.cancel()
GaesteWC_timer = null
}
end
I believe this can be done more easily with less of code. I cannot figure it out. This is not working:
var Timer GaesteWC_timer = null
rule "Fensteralarm GĂ€ste-WC"
when
Item EG_Fenster_Gaeste_WC changed
then
if(EG_Fenster_Gaeste_WC == "OPEN") {
logInfo("GaesteWC_timer","Fenster ist OFFEN")
GaesteWC_timer = createTimer(now.plusMinutes(5), [|
EG_Hue_bloom_Wohnzimmer.sendCommand(HSBType::RED)
])
}
if(EG_Fenster_Gaeste_WC == "TILTED") {
logInfo("GaesteWC_timer","Fenster ist TILTED")
GaesteWC_timer = createTimer(now.plusMinutes(7), [|
EG_Hue_bloom_Wohnzimmer.sendCommand(HSBType::GREEN)
])
}
else {
if(GaesteWC_timer != null) {
logInfo("GaesteWC_timer","Canceling the Timer")
GaesteWC_timer.cancel()
GaesteWC_timer = null
}
}
end
Is somebody able to give me a hint?
Thank you,
Timo