openHAB JavaScript library releases

It becomes part of the add-on when I update the add-on’s POM, I am usually trying to open a PR to the add-on ASAP, but obviously I have to wait for a review (I usually ping @laursen who is really fast at reviewing and merging these PRs, thanks!!).

So I think there is a good chance that it is available in the next snapshot, but if it is not, it should be in the next next snapshot.

EDIT: It’ll be in the next snapshot, my PR was just merged!

1 Like

New month, new release: Version 4.5.0 has been published.

It brings one enhancement: The Quantity factory and the divide/multiply methods now accept compatible Items as arguments.
You can find the changelog at the openhab-js repo:


Two months after the last minor, we have just published a new minor: Version 4.6.0.

It brings several enhancements regarding rules as well as one bugfix.
Have a look at the updated post at the top to get more information, or check the changelog:

1 Like

I unfortunately missed to announce version 4.7.0 and 4.8.0 here, but anyway, I’m happy to announce openhab-js 4.9.0.

Most notably, we have upgraded JS-Joda to the latest version, which brings several fixes to JS-Joda (accessible from the time namespace) and also managed to shrink the size of the compiled, add-on included openhab-js library, which I hope speeds up library injection.

Please have a look at the changelog to learn more about the changes.


Florian great job providing PR for bug fix in JS-Joda :+1:

1 Like

Meanwhile I was able to add a new section about the 5.0.0 release to the post above, please have a look at it :top:


For those who are maintaining rule templates and want to retain backwards support you can use the following technique (which I use in my Persistence Based Presence Simulation rule template).

const hState = (helpers.compareVersions(utils.OPENHAB_JS_VERSION, '5.0.0') < 0) ? i.history.historicState(when) : i.persistence.persistedState(when);

If you don’t have OHRT (why not! :wink: ), the helpers.compareVersions function is as follows:

 * Validates that the passed in version number is of the format X.Y.Z where
 * X, Y, and Z are numbers.
 * @param {string} version a version string to validate
 * @returns {boolean} true if valid, false otherwise
const _validateVersionNum = (version) => {
  const re = /\d+\.\d+\.\d+/;
  if (version === null || version === undefined || !(typeof version === 'string')) return false;
  return re.test(version);

 * Compare version numbers of the format X.Y.Z.
 * @param {string} v1 the first version number
 * @param {string} v2 the second version number
 * @throws error if v1 or v2 are not parsable
 * @returns {-1|0|1} 0 if the versions are equal, -1 if v1 is lower and 1 if v1 is higher
const compareVersions = (v1, v2) => {
  if (!_validateVersionNum(v1)) throw v1 + ' is not a valid version number in the format X.Y.Z where X, Y, and Z are numbers!';
  if (!_validateVersionNum(v2)) throw v2 + ' is not a valid version number in the format X.Y.Z where X, Y, and Z are numbers!';

  const v1Version = Number.parseFloat(v1);
  const v1Point = Number.parseInt(v1.split('.')[2]);
  const v2Version = Number.parseFloat(v2);
  const v2Point = Number.parseFloat(v2.split('.')[2]);

  if (v1 == v2) return 0;
  else if (v1Version > v2Version) return 1;
  else if (v1Version == v2Version && v1Point > v2Point) return 1;
  else return -1;
1 Like

Version 4.2.0.M3

When i update to new version 5.0.0 i have this problem:

Works on old version:


Don’t work in version 5.0.0

[ERROR] [omation.script.javascript.7907649d8e] - Failed to execute script: TypeError: Cannot get property "numericState" of null

others works


This is not supposed to work … the begin timestamp cannot be before the end timestamp.

I think it should read: begin timestamp must be before end timestamp.

The code might have been more forgiving in the past and not throw an error, but it would definitely not have generated the right result.

1 Like

We are on track for openHAB 4.2.0, I have just released version 5.1.0 of the openHAB JavaScript library!
Please have a look at my first post to see what’s new,