Dear Rich,
dear rossko57,
dear Forum,
thank you very much. I learned a lot and would like to share some of my learnings:
As my window has three states (TILTED, OPEN, CLOSED) I had the issue, if I moved from OPEN to TILTED, it lost the origin status of the light. First I had the following solution. I added
if(Alarm_MasterEvent.state == OFF) Alarm_MasterEvent.sendCommand(ON)
in the Timer. Then I realized to put
Item Alarm_MasterEvent changed to ON
instead of
Item Alarm_MasterEvent received command ON
in the when section of the ’rule "Alam Lights"
. This seems to have the same function.
Furthermore I realized that
var HSBType lastColor = null
does not work. It gave me a mismatch error message in the Eclipse SmartHome Designer. I tried it, it practically did not work. By not defining the type of variable, it worked. I have no explanation for that.
My code looks like that in the moment and my next step will be to add more windows.
var lastColor = null
rule "Fensteralarm Gäste-WC Offen"
when
Item EG_Fenster_Gaeste_WC changed
then
GaesteWC_timer?.cancel // the ? will skip this line if GaesteWC_timer is null
Thread::sleep(3000)
logInfo("GaesteWC_timer", "Fenster ist " + EG_Fenster_Gaeste_WC.state)
switch EG_Fenster_Gaeste_WC.state {
case "OPEN": {
GaesteWC_timer = createTimer(now.plusSeconds(5), [|Alarm_MasterEvent.sendCommand(ON)])
}
case "TILTED": {
GaesteWC_timer = createTimer(now.plusSeconds(7), [|Alarm_MasterEvent.sendCommand(ON)])
}
case "CLOSED": {
Alarm_MasterEvent.sendCommand(OFF)
}
}
end
rule "Alam Lights"
when
Item Alarm_MasterEvent changed to ON
then
if(lightsBlinkingTimer != null) {
lightsBlinkingTimer.cancel
lightsBlinkingTimer = null
}
lastColor = EG_Hue_bloom_Wohnzimmer.state
Thread::sleep(500)
EG_Hue_bloom_Wohnzimmer.sendCommand(HSBType::RED)
lightsBlinkingTimer = createTimer(now.plusSeconds(1), [|
EG_Hue_bloom_Wohn_Switch.sendCommand(if(EG_Hue_bloom_Wohn_Switch.state == ON) OFF else ON)
lightsBlinkingTimer.reschedule(now.plusSeconds(1))
])
end
rule "Stop Alarm"
when
Item Alarm_MasterEvent received command OFF
then
EG_Hue_bloom_Wohnzimmer.sendCommand(lastColor)
if(lightsBlinkingTimer != null) {
lightsBlinkingTimer.cancel
lightsBlinkingTimer = null
}
end
If you should have anything to add, I am always happy to learn from you!
Greetings,
Timo