[OH3] How to Create Rules in OpenHAB 3 using JavaScript / ECMAScript

Thanks for passing. My only quibble is it’s easier to get the state of an item using

items["Item name"]

You only ever really need to pull an item from the registry of it’s a Group Item and you want to get access to it’s members.

Also, event is undefined for any rule trigger that didn’t come from an Item.

It also might be worth mentioning that you can trstt for the existence of a variable using

if(myvar === undefined)

Finally, to save a variable from one run if the rule to the next, save it to this.

this.myTimer = (this.myTimer === undefined) ? null : this.myTimer

You can’t share this with other script actions or script conditions though.

I posted a tutorial for creating and importing libraries as well which would be of interest.

2 Likes