Hello,
Generally, I am struggling to find some exhaustive documentation or IDE for rules and lambda functions and the xtend language. I find it a lot of guess-work concerning what types are defined, how the syntax should be, etc.
I am thinking about using the Exec bridge and have the stuff carried out by shell scripts, c-code or similar, but this would kind of undermine the whole idea of openhab, I guess…
Anyway:
I am using openhab2 on a cubietruck which is an armbian based board similar to RPi etc.
The board has IR-LED, RF transmitters etc. connected to it, basically using GPIO functions to control IR receivers (stereo, a transmitter to a projector and the projector itself). I am using the LIRC bridge for this.
Now I am using rules. E.g.: if I turn on the projector, turn on the amplifier as well, roll down the screen and turn on the transmitter (sending the video content to the projector which is under the ceiling).
Timing is very crucial here, as the ir-diode is put on and of in us delays to ‘mimic’ remote controls.
The issue is, that if I use several LIRC commands in a rule consecutively, it is not working, There needs to be a delay, otherwise the consecutive signals interfere or only part of the signals are caught or transmitted properly. In the syslog I sometimes find errors “busy repeating” meaning that the sending of the previous signal has not finished when the next one is sent to lirc.
I tried to delay the signals with Thread::sleep, but this is not working at all. I guess when the CPU is sleeping, it messes up the timing for the lirc, for good.
The idea is that I give each of the devices a time slot (e.g. the amplifier power, the amplifier input selector, the transmitter, screen and projector) and after 200ms the amplifier power is receiving a command, if it needs to, after 400ms the input selector etc.
The rule can then build a a hashmap or something similar and when everything is clear that needs to be done, a reusable lambda function can be called that iterates through this map and fires the necessary lirc commands by creating a set of timers at the dedicated time slots
I tried to create two maps and a Lambda (just for testing, for the time being, not doing anything, yet):
val functionMap =<Integer, String>newHashMap()
val commandMap =<Integer, String>newHashMap()
val Functions execCommands = [Map<Integer, String> fm, Map<Integer, String> cm |
fm.forEach[tim, func |
logInfo("execCommands: time",tim.toString)
logInfo("execCommands: func",func)
logInfo("execCommands: comm",cm.get(tim))
]
]
in the rule, I add “stuff to these maps” and then call the lambda (or I try)
functionMap.put(200,"amplifier")
commandMap.put(200,"on")
....
execCommands.apply(functionMap,commandMap)
I tried to define the lambda as “Runnable” or leave the type definition empty, but I am not getting anywhere, here.
I get the following errors in the log:
There is no context to infer the closure’s argument types from. Consider typing the arguments or put the closures into a typed context.
2019-08-21 00:59:03.181 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'entertainment.rules', using it anyway:
There is no context to infer the closure's argument types from. Consider typing the arguments or put the closures into a typed context.
2019-08-21 00:59:03.471 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'entertainment.rules'
2019-08-21 00:59:16.250 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'amplifier on': 'apply' is not a member of 'org.eclipse.xtext.xbase.lib.Functions'; line 22, column 2, length 42
Any idea, either where to find a full documentation of types like Runnable, Functions or this example here: Reusable Functions: A simple lambda example with copious notes ?
Or of course, even better, a suggestion on how to solve this problem?