I have 15 Rollershutters and would like to use one coded rule for all the rollershutter items.
here my rule
rule "Item EG_WO_Rolladen_Links"
when Item EG_WO_Rolladen_Links_Proxy received command
then
if (receivedCommand == UP || receivedCommand == STOP || receivedCommand == DOWN) {
if (receivedCommand == UP) {
EG_WO_Rolladen_Links_Set.sendCommand(99)
}
if (receivedCommand == STOP) {
EG_WO_Rolladen_Links_Stop.sendCommand(ON)
}
if (receivedCommand == DOWN) {
EG_WO_Rolladen_Links_Set.sendCommand(0)
}
}
else { //bei allen anderen Werten Wert direkt in Actuator schreiben
EG_WO_Rolladen_Links_Set.sendCommand(receivedCommand)
}
end
rule "Item EG_WO_Rolladen_Links -postupdate"
when Item EG_WO_Rolladen_Links_Level changed
then EG_WO_Rolladen_Links_Proxy.postUpdate(EG_WO_Rolladen_Links_Level.state)
end
I want the code one method / function and call the function just with “EG_WO_Rolladen_Links” .
Thought I can find an example how to do it but I may search for the wron g keywords.
Does someone has an example where I can start with.
While this would be very simple to do with scripted automation, do you really need a function or just a single rule? If you put your proxy Items into a group named PROXY_ITEMS…
rule "Item EG_WO_Rolladen_Links"
when
Member of PROXY_ITEMS received command
then
if (receivedCommand == UP || receivedCommand == STOP || receivedCommand == DOWN) {
if (receivedCommand == UP) {
sendCommand(triggeringItem.name.replace("_Proxy", "_Set"), "99")
}
if (receivedCommand == STOP) {
sendCommand(triggeringItem.name.replace("_Proxy", "_Stop"), "ON")
}
if (receivedCommand == DOWN) {
sendCommand(triggeringItem.name.replace("_Proxy", "_Set"), "0")
}
} else { //bei allen anderen Werten Wert direkt in Actuator schreiben
sendCommand(triggeringItem.name.replace("_Proxy", "_Set"), receivedCommand.toString)
}
end
val rollerShutters_Left = [RollershutterItem item,UpDownType command |
switch command.toString {
case "UP" : item.sendCommand(99)
case "DOWN" : item.sendCommand(0)
default : item.sendCommand(command)
}
]
rule "Item EG_WO_Rolladen_Links -postupdate"
when
Item EG_WO_Rolladen_Links_Level changed
then
rollerShutters_Left.apply(EG_WO_Rolladen_Links_Set, EG_WO_Rolladen_Links_Level.state as UpDownType)
end
But I’m not sure what kind of items or groups you use. I noticed that voor STOP you use a different item. That is not possible with a simple procedure as I’ve given you.
Can you please share your items?
Group gRollProxy //(all _Proxy Items)
Group gRollSet //(all _Set Items)
Group gRollStop //(all _Stop Items)
Group gRollLevel //(all _Level Items)
Now it’s easy to build two Rules
rule "Rollladen Proxy"
when
Member of gRollProxy received command // A member of the Group gRollProxy received a command
then
val String strItem = triggeringItem.name.replace("_Proxy", "") // get first part of name
switch(receivedCommand){
case UP : gRollSet.members.filter[i|i.name.contains(strItem)].head.sendCommand(99)
case DOWN : gRollSet.members.filter[i|i.name.contains(strItem)].head.sendCommand(0)
case STOP : gRollStop.members.filter[i|i.name.contains(strItem)].head.sendCommand(ON)
default : gRollSet.members.filter[i|i.name.contains(strItem)].head.sendCommand(receivedCommand)
}
end
rule "gRollLevel postUpdate"
when
Member of gRollLevel changed
then
val String strItem = triggeringItem.name.replace("_Level", "")
gRollProxy.members.filter[i|i.name.contains(strItem)].head.postUpdate(triggeringItem.state.toString)
end