Port JSR223 bundle to openHAB 2

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.

I also would like to see this happening because I have already converted 30% to Jython.

I was thinking about converting mye rules to jython when upgradring to OH2, would be nice to have this feature merged and ready for final release :slight_smile:

I just want to add my two cents that JSR223 is one of the major things that drew me to openhab. I’m a bit surprised it wasn’t put into the “must have” bucket for openhab 2. It really seems like it’s a core feature, or should be.

Will Groovy be supported? I’m much more comfortable in Groovy that Python or JavaScript. Support for pure Java rules would be great, but Groovy covers that use case well enough for my purposes…

Thanks,

Doug

@lfs_alp5, @Marty56, @markrad, @fonz, @petr, @Dennis650, @Spaceman_Spiff and everyone else who is a fan of JSR223 scripting/rules. Even if you don’t have the time or the programming skills to review the PR, you can help by visiting the PR discussion and commenting or even just voting up Simon’s recent message suggesting the PR be merged into 2.0 before the release. I’ve been doing heavy testing with the code and I believe it’s 99% ready to go.

@torpex77, Groovy should be supported in a similar manner as in OH1. A recent change to the PR might enable other JSR223 languages like JRuby, JLua, ABCL (Armed Bear Common Lisp), etcetera to be used at least for scripting purposes, if not rule definitions. I still need to experiment with those languages, so no promises.

5 Likes

I would like to try to get Scala scripting working with OH2.

@steve1 Great. I’ll try to take a look at OH 2.0 and the PR soon.

I have a dozen or so base classes for my Groovy rules that greatly simplify my rules. For example:

import org.openhab.core.jsr223.internal.shared.*

class BigGarageOpen extends OpenTooLongRule {
  public BigGarageOpen() { super('BigGarageDoorTripped', 'Big garage door', 5) }
  protected void alert() { warnMsg("Big garage dr open for " + minutes + " mins") }
}

class BasicDoorOpen extends OpenClosedRule {
  public BasicDoorOpen(String itemName, String friendlyName) { super(itemName, friendlyName); }
  protected void open(Event event) { debugMsg(getFriendlyName(event) + ' open') }
}

RuleSet getRules() {
  return new RuleSet(
    new BigGarageOpen(),
    new BasicDoorOpen('BackDoorTripped', 'Back door'),
    new BasicDoorOpen('FrontDoorTripped', 'Front door'),
    )
}

These are (obviously) OH 1 only for now, but once I get OH 2 up and going I will look at porting those as well.

Thanks,

Doug

Hello everyone!

Just checking, was there any progress?

Yes, it would be really good to have progress.
Getting rid of the DSL of OH would be a high priority for me.

After having used the OH DSL for more than 3 years I am still annoyed by its inconsistencies, limitations and the need for silly workarounds resulting into a really poor productivity. I probably will never get used to it and would be very happy to see it replaced soon.

I have already converted 20% of my rule to jython using OH 1.x and it would be great to get this working again in OH 2.

2 Likes