Problem with 'createTimerWithArgument' in OH2

I have started using OH2, and I currently working on getting my most complex script running on OH2 (inspired by the article “Taking rules to new Hights”). I have found solutions for most things I have been dealing with, there is one thing that I can’t figure out - that is the createTimerWithArgument. I keep getting this error:
Error during the execution of rule 'SecurityZones sensor tripped TEST': The name 'createTimerWithArgument(<XMemberFeatureCallImplCustom>,<XFeatureCallImplCustom>,<XClosureImplCustom>)' cannot be resolved to an item or type.

I have written a new rule with just a create time in it, but it keeps failing:

var cookie = "timer2"
logInfo("timer_test", cookie)
var Timer timer2 = createTimerWithArgument(now.plusSeconds(10), null,
	[ x |
		logInfo("timer_expired", " with cookie: " + x)
	])

If I just use the plain Timer:

logInfo("timer_test", "<No Cookie>")
var Timer timer1 = createTimer(now.plusSeconds(10))
	[ x |
		logInfo("timer_expired", "(No arguments present)")
	]

Everything works, the timer is fired as expected.

All I have done is just to copy my code from the OH1 rule to my OH2 rule.

Any suggestions what I might have done wrong.

I somebody could give a working sample it would be just fine.

Found a copy / paste error in my non worting sample, the var cookie is declared as String in my sample that fails:

I’m so embarrassed of having published this ugly piece of code. I have since rewritten the rule much cleaner in python. But that is in OH1, not sure what the status of jython support is in OH2.
Like me, you have probably invested a substantial amount of time in learning how xtend works, and now you don’t want to ditch it, but at least for me, that was the right decision, if only for the fact that it allowed me to write code without the designer.

Very simple: You did nothing wrong, but the method ‘createTimerWithArgument’ simply does not exist in ESH, because it was missed to sync this change in the code base, see https://github.com/openhab/openhab/pull/1436.

Hi Kai,

Cool. I was absolutely sure that I have missed something…

Best regards
Martin

Hi Bernd,

You are right I have used a lot of time trying to learn and understand the rule engine. I still find it difficult, and I have also been looking for another way of solving this. Since I have started to develop a binding for ZoneMinder I have been looking in the direction of OH2. I believe I will revert my complex rules to OH1 and then take advantage of JSR223, as it seems to be just what I have been looking for. Even when the timerproblem is fixed in OH2 I will still have some complex rules that it will be hard to maintain.

Best regards
Martin

Hi Kai
I’m using current Beta, but “createTimerWithArgument” still produces “The name ‘createTimerWithArgument(,,)’ cannot be resolved to an item or type.”

Did I miss something. I though It’d been solved in Feb by teichsta.

Regards
Toni

I also miss this function.

It is planed to implement it?

I’ve been working on writing some rules and ran into the same problem that you all did as well. So I re-implmented the code for OH2 so I could use the function. :grinning:

issue: https://github.com/eclipse/smarthome/issues/2718
PR: https://github.com/eclipse/smarthome/pull/3234

If you are interested in testing it (I’ve had it working for about a day or so, change seemed pretty streight forward as it was already done on OH1.

http://www.ktechs.net/pvt_filz/org.eclipse.smarthome.model.script-0.9.0-SNAPSHOT.jar

----Directions to use the JAR - a bit cumbersome… -----
0. BACKUP!!! :slight_smile: - Use at your own risk!

  1. login to the openhab console

  2. find the running bundle of the ‘old’ “Eclipse SmartHome Script” bundle and stop it

openhab> bundle:list | grep -i script
131 | Active   |  80 | 0.9.0.201703201701    | Eclipse SmartHome Script Runtime
191 | Active   |  75 | 0.9.0.201703201701    | Eclipse SmartHome JavaScript Transformation Service
218 | Active   |  80 | 0.9.0.201704090215    | Eclipse SmartHome Script <-- Only this one!
openhab>
openhab> bundle:stop 218
openhab> bundle:uninstall 218
  1. Copy the JAR file to your addons directory
cd /your/install/path/addons
wget http://www.ktechs.net/pvt_filz/org.eclipse.smarthome.model.script-0.9.0-SNAPSHOT.jar .
  1. Check to see if OpenHAB2 picked it up
openhab> bundle:list | grep -i script
131 | Active    |  80 | 0.9.0.201703201701    | Eclipse SmartHome Script Runtime
191 | Active    |  75 | 0.9.0.201703201701    | Eclipse SmartHome JavaScript Transformation Service
220 | Installed |  80 | 0.9.0.201704111257    | Eclipse SmartHome Script <-- it did - note date!
openhab>
  1. stop the running “feature”…
openhab> feature:list | grep -i script
Name                                        | Version          | Required | State       | Repository              | Description
esh-automation-module-script                | 0.9.0.SNAPSHOT   |          | Uninstalled | distro-2.1.0-SNAPSHOT   |
esh-automation-module-script-defaultscope   | 0.9.0.SNAPSHOT   |          | Uninstalled | distro-2.1.0-SNAPSHOT   |
esh-model-script                            | 0.9.0.SNAPSHOT   |          | Resolved    | distro-2.1.0-SNAPSHOT   |
esh-model-script-runtime                    | 0.9.0.SNAPSHOT   |          | Started     | distro-2.1.0-SNAPSHOT   |
esh-transform-javascript                    | 0.9.0.SNAPSHOT   |          | Started     | addons-2.1.0-SNAPSHOT   | Javascript Transformation
openhab-transformation-javascript           | 2.1.0.SNAPSHOT   | x        | Started     | addons-2.1.0-SNAPSHOT   | Javascript Transformation
openhab> feature:uninstall esh-model-script
Error executing command: Feature named 'esh-model-script/0.0.0' is not installed
openhab> feature:stop esh-model-script
  1. Restart openHAB2, none of your rules will work until you do and it should be working. You might get an error as it starts up with the following:
17:01:34.719 [ERROR] [org.eclipse.smarthome.model.script  ] - FrameworkEvent ERROR - org.eclipse.smarthome.model.script
org.osgi.framework.BundleException: Could not resolve module: org.eclipse.smarthome.model.script [221]
  Another singleton bundle selected: osgi.identity; osgi.identity="org.eclipse.smarthome.model.script"; type="osgi.bundle"; version:Version="0.9.0.201704111257"; singleton:="true"

I believe this is the framework looking for the correct version matching revision of the bundle but we’ve loaded the newer version. It’s been working OK for me.

I followed all the steps - but it is for me not working.

After restart - the old version comes back -> 221
Could this be te reason?

openhab> bundle:list | grep -i script
130 | Resolved | 80 | 0.9.0.b4 | Eclipse SmartHome Script Runtime
190 | Active | 75 | 0.9.0.b4 | Eclipse SmartHome JavaScript Transformation Service
218 | Installed | 80 | 0.9.0.201704111257 | Eclipse SmartHome Script
221 | Active | 80 | 0.9.0.b4 | Eclipse SmartHome Script

@Kai It will be implemented in the next version? OH2.1 ? :slight_smile:

Hello all,

I installed the latest version of OH2.1 but still it is not running.

Someone else was testing this function?

openhab> bundle:list | grep -i script
130 | Active | 80 | 0.9.0.201705120951 | Eclipse SmartHome Script
131 | Active | 80 | 0.9.0.201705120951 | Eclipse SmartHome Script Runtime
194 | Active | 75 | 0.9.0.201705120951 | Eclipse SmartHome JavaScript Transformation Service