OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules

Not easily. You’ve two choices really.

  1. Do it just like the above to essentially include the contents of the library into your rule.

  2. Follow any tutorial out there for how to build an npm module.

2 is the standard way to do it and will be more flexible and sharable in the long run. But it’s more involved so may be more work than you may want to do. If you want to go that rout look for just about any tutorial on Google and you should be OK. The modules go in $OH_CONF/automation/js/node_modules/<your folder>. For example, I’ve got a personal folder there where I’ve put a few of my personal libraries. I’m working on an openhab_rules_tools module which I hope to push to npm and eventually integrate some of them into the helper library that comes with JS Scripting.

Maybe once I figure the ins and out of this approach I’ll write a tutorial but I’m still learning it myself.

1 Like