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.
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.