Program Rollershutter with GUI

All, I have leveraged the AlarmClock function to program my rollershutter up/down. For each rollershutter and for each up or down i therefore need a separate rule that looks like the below. The amazing thing is, similar as in the Wiki for the alarm clock i can program the time etc. when a rollershutter should go down / up. Even this works fine, i think its quite a complicated solution. Has anyone a better, simpler and more efficent idea?

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.openhab.action.squeezebox.*
import java.util.concurrent.locks.ReentrantLock

var Timer timer1 = null
var java.util.concurrent.locks.ReentrantLock lock1 = new java.util.concurrent.locks.ReentrantLock()

rule “Initialization”
when
System started
then
postUpdate(StorenTimerSuedWeekendhochZeitStunde, 07)
postUpdate(StorenTimerSuedWeekendhochZeitMinute, 45)
postUpdate(StorenTimerSuedhochSamstag, ON)
postUpdate(StorenTimerSuedhochSonntag, ON)
end

rule “Herunterfahrzeit”
when
Item StorenTimerSuedWeekendhochZeitStunde changed or
Item StorenTimerSuedWeekendhochZeitMinute changed
then
// If the UI to change the Alarm time is clicked several times the code below
// is subject to race conditions. Therefore we make sure that all events
// are processed one after the other.
lock1.lock()
try {
var String msg = “”

// Copy the Alarm-Time from the UI to local variables
var stunde = StorenTimerSuedWeekendhochZeitStunde.state as DecimalType
var minute = StorenTimerSuedWeekendhochZeitMinute.state as DecimalType
// Combine the hour and minutes to one string to be displayed in the 
// user interface
if (stunde < 10) { msg = "0" } 
msg = msg + StorenTimerSuedWeekendhochZeitStunde.state.format("%d") + ":"
if (minute < 10) { msg = msg + "0" }
msg = msg + StorenTimerSuedWeekendhochZeitMinute.state.format("%d")
postUpdate(StorenTimerSuedWeekendhochZeitMessage,msg)
// calculate the alarm time [min]
var int weckzeit1
weckzeit1 = (StorenTimerSuedWeekendhochZeitStunde.state as DecimalType).intValue * 60 + 
            (StorenTimerSuedWeekendhochZeitMinute.state as DecimalType).intValue
weckzeit1 = weckzeit1.intValue
// calculate current time [min]
var int jetzt1
jetzt1 = now.getMinuteOfDay
jetzt1 = jetzt1.intValue
// calculate the difference between the requested alarm time and 
// current time (again in minutes)  
var int delta1
delta1 = (weckzeit1 - jetzt1)
delta1 = delta1.intValue
// add one day (1440 minutes) if alarm time for today already passed
if (jetzt1 > weckzeit1) { delta1 = delta1 + 1440 }
// check if there is already an alarm timer; cancel it if present
if (timer1 != null) {
   timer1.cancel
   timer1 = null
}
// create a new timer using the calculated delta [min]
timer1 = createTimer(now.plusMinutes(delta1)) [|
    // This code will be executed if the timer triggers
    // ************************************************
    // check if alarm clock is armed for this weekday
    var Number day = now.getDayOfWeek
    if (((day == 6) && (StorenTimerSuedhochSamstag.state == ON))    ||
        ((day == 7) && (StorenTimerSuedhochSonntag.state == ON)) ) {
            // The things to do if the alarm clock is enabled for this day of week: 
       Lamellen_EG_Whz_Sued.sendCommand(UP)
            
       }
       // Re-Arm the timer to trigger again tomorrow (same time) 
       timer1.reschedule(now.plusHours(24))
    // ************************************************
    // Here the code ends that executes once the timer triggers 
    ]

} finally {
// release the lock - we are ready to process the next event
lock1.unlock()
}
end

It somewhat depends on your needs and requirements. The alarm clock example is itself rather complex as it needs to get around a weakness in openHAB (i.e. the inability to schedule events from the sitemap easily).

However, if you can control your rollershutters based on some other event, e.g. sunrise and sunset, weather condition ID, light sensor, temperature sensor, etc., you can simplify this quite a bit. Your system started rule would go away, your Timer and the bulk of the rule would go away and your rule would only have to worry about see what the event is and set the rollershutter accordingly (e.g its 2 hours before sunset, close the rollershutter).

I totally agree, there are other triggers which could down/up my rollershutters. Also, I agree it seems a weakness with openhab 1.X. Are you aware on this going to be changed soon with OH 2?

Point is in my case, i would like to use both, the other trigers and the timing element. In an ideal world I could even say in the GUI for example switch the sunset trigger on/off. Switch between automated triggers based on the weatherstation and manual triggers based on time I am programming.

I don’t know.

Well, the complication in the above rule is caused by the alarm clock example and if you also include combining all sorts of different ways to control the rollershutter more complications will ensue.