This rule checks to see if npm is available via a local to the user nvm installation. If it’s not the template installs nvm, then uses nvm to install node locally to the user. This local to the user instance is then used to install openhab_rules_tools.
Install the template, instantiate a rule from the template, and manually run it while watching openhab.log.
Do not use this if you are running openHABian. openHAB Rules Tools can be installed from openhabian-config.
Watch openhab.log for errors. If there are errors, this template may not work for you and you will have to do a manual install.
This script does work for Docker users. Make sure to set the path parameter is set to /openhab/conf.
Language: JS Scripting
Dependencies:
Requires wget to be installed and in the path for the user openHAB is running under.
Only tested on Linux and Docker. I cannot say if it works on other platforms. It almost certainly won’t work on Windows.
Changelog
Version 0.2
executeCommandLine now returns stderr more reliably. Test for “not found” in the output to see if npm isn’t installed.
Version 0.1
initial release
Sponsorship
If you want to send a tip my way or sponsor my work you can through Sponsor @rkoshak on GitHub or PayPal. It won’t change what I contribute to OH but it might keep me in coffee or let me buy hardware to test out new things.
I assume that means that the upgrade to OH5 removes openHAB Rules Tools [4.0.0.0;4.9.9.9]? Or should that be ‘uninstalled’ manually before trying to install openHAB Rules Tools [5.0.0.0;5.9.9.9]?
No, this is just a convenience rule template for those who are not running openHABian (use openhabian-config instead) and are running on a POSIX OS (e.g. Linux) who may not be able or willing to install the library from the command line.
Note this is for the node.js module, not the Block Library. The Block Library is just a way to expose the node.js module for Blockly users. The Block Library requires the node module to be installed to work.
I have released a new minor version of the OHRT node module that includes a few new features. If you’ve already installed OHRT, from the command line navigate to $OH_CONF/automation/js and run npm upgrade. There isn’t much new but it will let you cancel Gatekeeper timers now if you are a Block library users. If you don’t need that, there really is no need to upgrade. openHABian will upgrade the library automatically when you upgrade the rest of the system.
I’m setting up a new openHab installation with Docker on my synology. openHab looks fine so far but I’m struggling with the installation of OHRT.
I downloaded the template and created a rule. Running the rule gives me the following output:
11:26:33.315 INFO org.openhab.automation.script.ui.3d955fd354 Checking to see if npm is available
11:26:33.316 INFO org.openhab.automation.script.ui.3d955fd354 npm --version
11:26:33.322 INFO org.openhab.automation.script.ui.3d955fd354 bash: line 1: /openhab/.nvm/nvm.sh: No such file or directory
11:26:33.323 INFO org.openhab.automation.script.ui.3d955fd354 Installing openhab_rules_tools...
11:26:33.323 INFO org.openhab.automation.script.ui.3d955fd354 cd /etc/openhab/automation/js && npm install openhab_rules_tools
11:26:33.328 INFO org.openhab.automation.script.ui.3d955fd354 bash: line 1: /openhab/.nvm/nvm.sh: No such file or directory
11:26:33.329 INFO org.openhab.automation.script.ui.3d955fd354 Done, check the output above for errors
I’m quite new to openHab on Docker so would need some hints to troubleshoot.
It might have something to do with the user I’m running the container and openhab with. So I guess some dependencies are not available.
There was a change in executecommandLine which makes it more reliably return stderr now. Previously I just tested to see if there was no output to determine if NPM needed to be installed. I’ve updated it to check also for “not found” in the output" to determine if NPM needs to be installed.
Remove and reinstall the template and refresh the rule.
I tried updating, but something’s wrong with the persmissions, I think:
erik@MinipcLG2:/etc/openhab/automation/js$ sudo -u openhab npm i openhab_rules_tools
npm ERR! code EACCES
npm ERR! syscall open
npm ERR! path /etc/openhab/automation/js/package-lock.json
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, open '/etc/openhab/automation/js/package-lock.json'
npm ERR! [Error: EACCES: permission denied, open '/etc/openhab/automation/js/package-lock.json'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/etc/openhab/automation/js/package-lock.json'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /var/lib/openhab/.npm/_logs/2026-08-05T20_04_38_642Z-debug-0.log
erik@MinipcLG2:/etc/openhab/automation/js$ ls -pal
totaal 20
drwxr-xr-x 3 openhab openhab 4096 dec 27 2025 ./
drwxr-xr-x 4 openhab openhab 4096 apr 16 2024 ../
drwxr-xr-x 3 openhab openhab 4096 aug 5 22:04 node_modules/
-rw-r--r-- 1 root root 64 mei 29 2024 package.json
-rw-r--r-- 1 root root 767 aug 28 2024 package-lock.json
erik@MinipcLG2:/etc/openhab/automation/js$
I could change them of course, but that would be a shot in the dark. I’d rather do things properly, so I need help, I’m afraid…
at one point npm was run as root so some of the files are owned by root. So you need to run npm as root, or change the ownership of those two .json files and why file it folder under node_modules to openhab:openhab. I think openhab-cli fixPermissions (or something like that) will do that for you, not sure if it hits that folder though.