First let me explain te current situation; I have 12 roller shutters around my house which are all be controlled by openhab. Every Rollershutter has:
Items:
var Timer LVTMRRS_KTCHN_Sidewindow = null
var Integer LVRS_KTCHN_Sidewindow_UpTime = 36
var Integer LVRS_KTCHN_Sidewindow_DownTime = 33
rule "RS_KTCHN_Sidewindow_Control"
when Item RS_KTCHN_Sidewindow_Control received command
then
if(receivedCommand == UP && RS_KTCHN_Sidewindow_ControlUp.state != ON && RS_KTCHN_Sidewindow_ControlDown.state != ON){
sendCommand(RS_KTCHN_Sidewindow_ControlUp, ON)
LVTMRRS_KTCHN_Sidewindow = createTimer(now.plusSeconds(LVRS_KTCHN_Sidewindow_UpTime)) [|
sendCommand(RS_KTCHN_Sidewindow_ControlUp, OFF)
]
}
else if(receivedCommand == DOWN && RS_KTCHN_Sidewindow_ControlUp.state != ON && RS_KTCHN_Sidewindow_ControlDown.state != ON){
sendCommand(RS_KTCHN_Sidewindow_ControlDown, ON)
LVTMRRS_KTCHN_Sidewindow = createTimer(now.plusSeconds(LVRS_KTCHN_Sidewindow_DownTime)) [|
sendCommand(RS_KTCHN_Sidewindow_ControlDown, OFF)
]
}
else if(receivedCommand == STOP){
if (LVTMRRS_KTCHN_Sidewindow !== null) {
LVTMRRS_KTCHN_Sidewindow.cancel()
LVTMRRS_KTCHN_Sidewindow = null
}
sendCommand(RS_KTCHN_Sidewindow_ControlUp, OFF)
sendCommand(RS_KTCHN_Sidewindow_ControlDown, OFF)
}
end
The code above is been created for every Rollershutter separately, which makes a very big rule.
I would like to create a ‘function’ which I can ‘open’ with a couple of arguments.
I’ve searched several hours, but it looks like some examples are ‘older’ and cannot be used in OH2, some other examples gives a lot of errors in my IDE and in the LOG-files. I cannot create anything which works.
Can somebody point me in the right direction so I can make a working ‘function’.
I use this rule to only close a shutter if the door behind isn’t open.
Shutter and door contact item are given as arguments such as in check_close_shutter.apply(EG_Kueche_Rolladen_Tuer,EG_Kueche_Tuer_Kontakt,closure)
val Functions$Function3 <RollershutterItem,ContactItem,NumberItem,Boolean> check_close_shutter = [ shutter, door, percentage |
if (door.state != OPEN) {
logDebug("rules", shutter.label + "(" + shutter.name + ") wird auf " + percentage + " gefahren, shutter = " + shutter)
var Number p = percentage
shutter.sendCommand(p)
} else
logDebug("rules", shutter.label + " wird nicht geschlossen, da " + door.label + " geöffnet ist.")
logDebug("rules", shutter.label + "(" + shutter.name + ") erledigt")
true
]
There is a complete alternative approach; make one rule triggered by events on a Group member, use related Item names (as you already do) so the rule can deduce which Items are associated with the “current” Group member.