Here is my rules file. It is basically a copy from yours above, but with my family!
I get this error in my log:
2017-11-27 16:18:06.052 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model AlarmClock.rules'
2017-11-27 16:18:06.077 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'AlarmClock.rules' is either empty or cannot be parsed correctly!
2017-11-27 16:18:06.327 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'AlarmClock.rules' has errors, therefore ignoring it: [33,23]: mismatched input ',' expecting '}' [40,4]: mismatched input '}' expecting ']'
but, in SmartHome Designer I get A LOT of errors:
(Line#6)
Multiple markers at this line
- Incorrect number of arguments for type Function3; it cannot be parameterized with arguments <string, map, Function0, Function0, Boolean>
- Function0 is a raw type. References to generic type Function0 should be parameterized
(Line#7)
Type mismatch: cannot convert from (Object, Object, Object, Object)=>Timer to Function3<string, map, Function0, Function0, Boolean>
(Line 20)
Cannot refer to the non-final variable dayName inside a lambda expression
(Line 23, 24, 25)
The method or field day is undefined
(Line 28, 36)
Type mismatch: cannot convert from OnOffType to String
(Line 31, 35)
The method apply() is undefined for the type Object
(Line 33)
Multiple markers at this line
- mismatched input ',' expecting '}'
- The method or field put is undefined for the type Object
(Line 37)
The method put(Object, Object) is undefined for the type Object
(Line 40)
mismatched input '}' expecting ']'
Whew! I am sure it’s something silly, but my lack of experience with openHab functions is glaringly obvious!
This starts at Line 1:
import org.eclipse.xtext.xbase.lib.Functions
import java.util.Map
val Map<String, Timer> timers = newHashMap
val Functions$Function3 <String, Map<String, Timer>, Functions$Function0, Functions$Function0, Boolean> processAlarm =
[person, timers, alarmStart, alarmStop |
var dayName= "NA"
switch now.getDayOfWeek{
case 1: dayName = "MO"
case 2: dayName = "DI"
case 3: dayName= "MI"
case 4: dayName= "DO"
case 5: dayName= "FR"
case 6: dayName= "SA"
case 7: dayName= "SO"
}
val person1On = gAlarm.members.filter[s | s.name == person+dayName].head.state
if(person1On == ON){
var sollMinute = (gAlarm.members.filter[s | s.name == person+day+"_M"].head.state as Number).intValue
var sollHour = (gAlarm.members.filter[s | s.name == person+day+"_H"].head.state as Number).intValue
var runTime = (gAlarm.members.filter[s | s.name == person+day+"_RUN"].head.state as Number).intValue
if(sollMinute == now.getMinuteOfHour && sollHour == now.getHourOfDay) {
sendCommand(person+"_Active", ON)
// alarmStart is a passed in lambda that implements the stuff to do for that person's alarm
alarmStart.apply()
timers.put<person, createTimer(now.plusMinutes(runTime), [|
// alarmStop is a passed in lambda that implements the stuff to do at the end of that person's alarm
alarmStop.apply()
sendCommand(person+"_Active", OFF)
timers.put(person, null)
])
}
}
true
]
//===================================================================================
rule "Alarms"
when
Time cron "0 0/1 * * * ?"
then
val Functions$Function0 <Boolean> CraigAlarmStart = [|
sendCommand(Light_US_MasterRoom_CraigsLamp, ON)
true
]
val Functions$Function0 <Boolean> CraigAlarmStop = [|
sendCommand(Light_US_MasterRoom_CraigsLamp, OFF)
true
]
// define functions for each person, if there is nothing to do for that person you can use [| true]
// as illustrated with person2 below.
processAlarm.apply("Craig", timers, CraigAlarmStart, CraigAlarmStop)
processAlarm.apply("Ellen", timers, [| true], [| true]) // PERSON2 has nothing to do when the alarm starts and ends so we pass empty lambdas
processAlarm.apply("Nick", timers, [| true], [| true]) // PERSON2 has nothing to do when the alarm starts and ends so we pass empty lambdas
processAlarm.apply("Marcus", timers, [| true], [| true]) // PERSON2 has nothing to do when the alarm starts and ends so we pass empty lambdas
end