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);
}