Port JSR223 bundle to openHAB 2

Thanks a lot!
I now I found it.

I’m going to port some script rules from 1.8.3.
Can you give me any hint are the scripts are stored? I need to edit the external, because they are to complex for this integrated UI.

Is the object model / api similar to 1.8.3 ?

Puhhh, I’m in the same Situation. It is for me not as comfortable doing it by a GUI. I have complex javascripts and have external javascript libraries which I can load very simple in jsr223.

Because it is experimental and not “the last word”. I wait to port at the moment.

I did not test it, don’t know if the object model / api is similar. I would study the Sources to find out.

For some reason I don’t get the Rules section in the Paper UI menu even after a refresh.

Any ideas?

I have installed yesterdays version, and got an error too, Bundle is not starting.
Yes, its experimental.

Are there any news on this?
I have lots of rules running very well in jython and slowly I am thinking about OH2.
Is there now full support of JSR223 (+jython)?

This is a bit of cross post from Excellent presentation of Kai at jPrime conference: Recording somewhere? because that has the best example I have found to start with these types of scripts.

It would be good to have some basic API/debug starting points to get us started on using this more effectively.

Hello!

Just checking what is the progress on this - is there any basic tutorial/set of steps needed to get this to work?

Would be great to start using Python in rules!

Anyone? I am still waiting for jython and jsr223 so I can move over to OH2.

3 Likes

Any news on jsr223 port to OH2?
I look forward…:grinning:

I have the same question.

ditto

A missing jsr223 scripting engine like in OH1 is the only “brake pad” to migrate to OH2 for me too.

@smerschjo, (he did the cool OH1 jsr223 engine) do you here us? :vulcan:

Same here - would LOVE to be able to migrate and start fresh with 2.0 but I am not willing spend any more time with the Xtend scripting language.

1 Like

Hi,

same here. I migrated many rules from XTend scripts to python scripts.

Greetings
Dennis

I had to implement scripting at work, so i ‘hacked’ a oh2-jsr223 extension together
last week.
At the moment it’s very basic and i can’t promise how much time i can spend on it.
I mainly user nashorn and a little bit of grrovy for scripting, so jre8 is required.

I never looked into the original jsr223, so i can’t tell what the differences are.

At the moment i can use simple timers( no cron at the moment),
turn lights on and off (motion triggered),
and format date/date strings to display LastUpdate stuff on sensor data

I can call cross-language methods from global available ‘script’ libs…

I try to use javax.time internally, because i’ve re read that joda is in maintainance mode…

My rule-interface looks like this:

var BaseRule = new Object(
 {
  type     : function() { return 1; },
  
  id       : function() { return null; },
  name     : function() { return null; },
  priority : function() { return null; },
  
  itemFilter  : function() { return null; },
  groupFilter : function() { return null; },
  
  OnStartup	   : function() { return null; },
  OnShutdown	   : function() { return null; },
  OnItemStateEvent : function() { return null; },
  OnTimer 	   : function(timerId) { return null; }
 });

the main global-context object to interact with OH looks like this:

public interface AseItemService {
  // item handling
  public Item get(String name);  
  public Item getOrCreate(String name, Item item);
  
  public List<Item> find(String pattern);
  
  public Item create(Item item);
  public void createItems(List<String> names, Item prototype, String prefix, String suffix);
          
  public void remove(String name);
  
  public void createGroup(String name);
  public void removeGroup(String name);
  
  
  
  // group handling 
  public List<Item>   getGroupItems(String groupName);
  public List<String> getGroupItemNames(String groupName);
  
  public Set<String> getGroupNames();

  // persistence handling
  public LocalDateTime getLastUpdate(String name);
  public LocalDateTime getLastUpdate(String name, String persistenceId); 
  
  
  // comman handling
  public void sendCommand(String itemName, Object c);
  public void sendCommand(String itemName, Command cmd, Object val);
 }

I may have some time this winter to help. @smerschjo, do you have a git repo somewhere with your current work? Can you give an update on the status?

1 Like

Don’t push @smerschjo, he already did all his work on this a long time ago. The one to blame that it isn’t moving forward is me; I didn’t find the time to follow up on his PR: https://github.com/eclipse/smarthome/pull/1783

So all you developers that are waiting for this feature: Please join the discussion/testing/suggestions on this PR to get things moving!

I’m not a Java developer so there is little point me reviewing the PR. However, I just want to say that lack of JavaScript support has currently road blocked my OH2 upgrade. I understand why Xtend was picked, it’s a nice easy language for non-programmers to grasp but for me it has clunky syntax and lacks any kind of object orientation. I converted all of my rules to JavaScript for that reason. JavaScript is much better at being able to to create a class and instantiate an object of that class for each item you want to associate with the implemented rule in that class. I really hope that other potential OH2 users are clamoring for this so that we don’t get stuck at OH1. I’ll bridge my OH2 to NodeRed before I write another rule in Xtend.

I am happy to test the PR if I had the vaguest idea about I how would merge into my current OH2 installation.

@markrad, I’ve been testing Simon’s OH2 JSR223 PR and it’s working quite well for me (with Jython). I’ve been providing feedback and I hope it will not be long before the PR is merged into the code base. I encourage even the non-programmers here to subscribe to the GitHub issue since you may want to participate in feature discussions that don’t require code review.

1 Like

Hi @steve1,

Thanks for the update. Hopefully this will get in before the end of January. I want to flip to the new OpenHab service after I have converted to OH2 but that window is rapidly closing.

I’m watching the GitHub PR but, as of yet, there is not much in the discussion that gives me any real use details. If there were a quick and easy mechanism to incorporate this into my system I would. However I have no doubt this is going to involve cloning the original, merging the PR and then building. Just setting up to build a Java project of this magnitude would be an extended learning curve for me. I don’t use Eclipse, IntelliJ, Maven, Gradle, Ant or whatever other build system someone came up with for Java. I like make files.

Basically I was pretty darn happy with the JS support just as it was in OH1. That’s all I really want.