Functions are possible in OH: Reusable Functions: A simple lambda example with copious notes.
However I will warn you that there is almost always a better approach to achieve the same thing in OH. Functions like this are awkward and challenging to write and maintain and usually end up being brittle and excessively long.
So my recommendation is to:
-
if you insist on wanting to code Rules in a more functional way, use the JSR223 binding and code your Rules using Jython, JavaScript, or Groovy
-
trade having a few more Items and Groups for massively simpler Rules code.
Look at the Design Pattern postings for lots of approaches that work better in Rules DSL than trying to force functions and data structures on the Rules DSL.
Not really but you haven’t provided enough details to provide any additional advice. But, for example,
rule "time changed"
when
Item MorningScenario changed to ON or
Item AfternoonScenario changed to ON or
...
then
val rs1Direction = UP
val rs2Direction = UP
val rs1Timer = 5
val rs2Timer = 10
switch triggeringItem.name {
case "MorningScenario": {
// defaults are already correct
}
case "AfternoonScenario": {
rs1Direction = UP
rs2Direction = UP
rs1Timer = 10
rs2Timer = 10
}
...
}
rsCommand.apply(rs1, rs1Direction, rs1Timer)
rsCommand.apply(rs2, rs2Direction, rs2Timer)
end
Of course it could be simpler if you apply the Time of Day DP and use a single String Item to represent the time of day.
There are other approcahes one can use such as Associated Items DP to implement the Timer itself.