How to upload JavaScript rules?

Oh, wait. You are not using the default Nashorn ECMAScript 5.1 that comes with OH by default? Yea, the JS add-on totally breaks Nashorn, does not work much like Nashorn rules do and is incompatible with the Helper Libraries.

There is very little documentation yet on it and most of the documentation you will find in the OH docs do not apply.

If you installed the JS addon you are largely on your own for now. There are a couple of threads (All my ECMAScript scripts stopped working throwing exceptions and Usage of new ECMA2021 Automation Scripting (GraalVM)) and @jpg0 has a helper library referenced in that second thread.

But what I’ve been talking about is the default built in Nashorn JavaScript. The two work differently from each other and rules written for one are not compatible with the other. Essentially, the add-on doesn’t import anything by default whereas the default inserts a whole bunch of stuff (e.g. a dict of the Items and their states, utilities like events that let you sendCommand and postUpdate, access to Actions, etc.).

Having said all that, just about everything I talked about above concerning what is possible should apply. But the specific syntax you’ll use will be different. And the syntax David linked to won’t apply either nor will the Helper Libraries. So you’ll have to choose which one to pursue.

1 Like