@mikaelgu
@rlkoshak
Guys, after re-reading the rules documentation, it began to dawn on me that I need to fundamentally change my understanding regarding rule triggers. You just confirmed it
So, here’s how I (hopefully) solved my problem:
- I defined two switches called ‘dayTime’ and ‘nightTime’. It is probably a simplified version of @rlkoshak’s Time of Day Design Pattern.
- I defined a GroupItem switch that comprises all my rollershutter. It will be used for checking whether the command to open the rollershutters will be fired at all. That is, if the GroupSwitch’s state is ‘ON’, i.e. the rollershutters are already open, the command won’t be executed.
- A simple CRON job will open the rollershutters at 08.30am if they are still closed (and eventually set the GroupItem’ state to ‘ON’).
myItems.items:
// Astro
DateTime Sunrise_Time "Sonnenaufgang [%1$tH:%1$tM]" <sun> { channel="astro:sun:local:civilDawn#start" }
DateTime Sunset_Time "Sonnenuntergang [%1$tH:%1$tM]" <moon> { channel="astro:sun:local:nauticDusk#start" }
// rollershutter
Group:Switch:OR(ON, OFF) gEG_rollershutter_switch "Rolläden Erdgeschoss [(%d)]" <blinds>
Switch eg_wz_rollade1 "Wohnzimmerrollade 1 [%d%%]" (gEG_rollershutter_switch) ...
Switch eg_wz_rollade2 "Wohnzimmerrollade 2 [%d%%]" (gEG_rollershutter_switch) ...
Switch eg_wz_rollade3 "Wohnzimmerrollade 3 [%d%%]" (gEG_rollershutter_switch) ...
Switch eg_wz_rollade4 "Wohnzimmerrollade 4 [%d%%]" (gEG_rollershutter_switch) ...
Switch eg_kueche_rollade "Kuechenrollade [%d%%]" (gEG_rollershutter_switch) ...
Switch eg_bad_rollade1 "Badezimmerrollade 1 [%d%%]" (gEG_rollershutter_switch) ...
Switch eg_bad_rollade2 "Badezimmerrollade 2 [%d%%]" (gEG_rollershutter_switch) ...
// multi-sensors
String eg_flur_multiSensor "Bewegungsmelder [%s]" <light> ... (Alternates between the two states "alarm" and "clear")
myRules.rules:
// Astro
rule "Set day time"
when
Channel 'astro:sun:local:civilDawn#event' triggered START
then
nightTime.sendCommand(OFF)
dayTime.sendCommand(ON)
end
rule "Set night time"
when
Channel 'astro:sun:local:nauticDusk#event' triggered START
then
nightTime.sendCommand(ON)
dayTime.sendCommand(OFF)
end
// Rollershutter
rule "Open rollershutter ground floor via motion sensor"
when
Item eg_flur_multiSensor changed from "clear" to "alarm"
then
if ( (dayTime.state == ON) && (gEG_rollershutter_switch.state == OFF) )
gEG_rollershutter_switch.sendCommand(ON)
end
rule "Open rollershutter ground floor at specific time"
when
Time cron "0 30 8 ? * * *"
then
if (gEG_rollershutter_switch.state == OFF)
gEG_rollershutter_switch.sendCommand(ON)
end
Do you see any possibilities for code improvements?
I still find it a bit strange how OpenHAB rules are designed. In my view, all the potential triggers should go into the ‘when’ part and the ‘AND’ operator should be available, maybe something like this:
when (or better if)
(dayTime.state == ON) &&
((gEG_rollershutter_switch.state == OFF) &&
(Item eg_flur_multiSensor changed from "clear" to "alarm")
then
gEG_rollershutter_switch.sendCommand(ON)
end
But I am pretty sure the OH designers implemented rules the way they did it on purpose. Maybe someone can enlighten me why they did it in this particular way, i.e. specifing event-based triggers, time-based triggers, and system-based triggers and omitting the ‘AND’ operator?