I will read
.items
Group:Switch:OR(ON, OFF) gLightHallwaySwitch
Group:Dimmer:AVG gLightHallwayDimmer
Switch DimmStufe
Group:Switch:OR(ON, OFF) gMotion "Bewegungsmelder" <motion> (Home)
Switch Light1_Toggle "Licht Spot1" <light> (Hallway,gLight,gLightHallwaySwitch) { channel="hue:0220:0017884804a5:bulb1:brightness" }
Dimmer Light1_Dimm "Licht Spot1" <light> (Hallway,gLight,gLightHallwayDimmer) { channel="hue:0220:0017884804a5:bulb1:brightness" }
[...]
Switch Light4_Toggle "Licht Spot4" <light> (Hallway,gLight,gLightHallwaySwitch) { channel="hue:0220:0017884804a5:bulb4:brightness" }
Dimmer Light4_Dimm "Licht Spot4" <light> (Hallway,gLight,gLightHallwayDimmer) { channel="hue:0220:0017884804a5:bulb4:brightness" }
Switch hueMotionSensor_1_Presence "presence [%s]" <motion> (Hallway,gMotion) { http="<[hueMotionSensor_1_Presence:100:JS(getHuePresence.js)]" }
Switch hueMotionSensor_2_Presence "presence [%s]" <motion> (Hallway,gMotion) { http="<[hueMotionSensor_2_Presence:100:JS(getHuePresence.js)]" }
.rules
import java.util.Map
val Map<String, Timer> timers = newHashMap
val Map<String, Timer> dimmers = newHashMap
rule "Rule 2: Bewegungsmelder Flur - Lichtsteuerung"
when
Item gMotion changed from OFF to ON
then
logInfo("rule_2", "Start")
// Variablen
var hour = now.getHourOfDay
val TimerTimeoutSeconds = 90
// Regel
if (AfriColaButton.state == OFF) {
if ( timers.get(gLightHallwaySwitch) !== null) {
logInfo("rule_2", "Dimm-Stufe noch nicht erreicht. Timer wird zurueckgesetzt ...")
timers.get(gLightHallwaySwitch).reschedule(now.plusSeconds(TimerTimeoutSeconds))
}
if ( dimmers.get(gLightHallwaySwitch) !== null) {
logInfo("rule_2", "Timer ist schon auf Null, aber Dimm-Timer noch nicht erreicht.")
dimmers.get(gLightHallwaySwitch).cancel
dimmers.put(gLightHallwaySwitch, null)
}
if ((timers.get(gLightHallwaySwitch) === null) && (dimmers.get(gLightHallwaySwitch) === null)) {
if ( hour < 7 || hour >= 22 ) {
// Nachtschaltung
logInfo("rule_2", "Nachtschaltung")
sendCommand(gLightHallwayDimmer, 10) }
if ( hour < 22 && hour >= 20 ) {
// Abendschaltung
logInfo("rule_2", "Abendschaltung")
sendCommand(gLightHallwayDimmer, 30) }
if ( hour < 20 && hour >= 7 ) {
// Tagschaltung
logInfo("rule_2", "Tagesschaltung")
sendCommand(gLightHallwayDimmer, 100) }
}
}
logInfo("rule_2", "Ende")
end
rule "Rule 3: Bewegungsmelder Flur - Zeitsteuerung"
when
Item gMotion changed from ON to OFF
then
logInfo("rule_3", "Start")
// Variablen
Thread::sleep(100) // give persistence time to save the update
val TimerTimeoutSeconds = 90
val DimmerTimeoutSeconds = 30
// Regel
if (AfriColaButton.state == OFF) {
if ((timers.get(gLightHallwaySwitch) === null) && (dimmers.get(gLightHallwaySwitch) === null)) {
logInfo("rule_3", "Timer wird gestartet.")
timers.put(gLightHallwaySwitch, createTimer(now.plusSeconds(TimerTimeoutSeconds), [|
logInfo("rule_3", "Timer abgelaufen, jetzt wird gedimmt.")
sendCommand(gLightHallwayDimmer, 10)
logInfo("rule_3", "Dimmer wird gestartet.")
dimmers.put(gLightHallwaySwitch, createTimer(now.plusSeconds(DimmerTimeoutSeconds), [|
logInfo("rule_3", "Dimmer timer abgelaufen, jetzt wird ausgeschalten")
sendCommand(gLightHallwaySwitch, OFF)
logInfo("rule_3", "Variable dimmers wird zurückgesetzt.")
dimmers.put(gLightHallwaySwitch, null)
]))
logInfo("rule_3", "Variable timers wird zurückgesetzt.")
timers.put(gLightHallwaySwitch, null)
]))
}
}
logInfo("rule_3", "Ende")
end