Transformation with javascript dont work

  • Platform information:
    • Hardware: VM with 2GB of RAM
    • OS: Ubuntu Server 22.04.2 LTS
    • Java Runtime Environment: openJDK 18
  • Issue of the topic: please be detailed explaining your issue:

Hi,
I wanted to create a rule which reads the HTML Code of a internal Website which shows the state of our Meetings Room and set the state as the value of an item.
I created a Rule and a js File to transform the HTML into a String which says whether the Room is free or not.
My Problem is the everytime my item gets the value “NULL”.

Here are my Code

Rule:

var htmlCode = sendHttpGetRequest("http://192.168.0.90/Raumbuchung/GROB_Besprechungsraum/Raum?Raumnummer=1#MasterTable")
var roomstate = transform("JS", "raumstatus.js", htmlCode)
RaumStatus.postUpdate(roomstate)

The js file is stored under /etc/openhab/transform/raumstatus.js
js to transform the data:

(function(htmlCode){
    var freiBtn = htmlCode.match(/<input[^>]+value="Frei"[^>]+disabled/);
    var status = freiBtn ? "Frei" : "Besetzt";
    return status;
})(input)

I have tested my JavaScript and it is working
If i use RaumStatus.postUpdate(htmlCode) instead of RaumStatus.postUpdate(roomstate) in my rule i get the htmlCode as the value for my item, so this is working too.

Thanks for your help!

What do the logs say?

Do you have the JavaScript Transformation Service installed?

In the file /var/lib/openhab/log/openhab.log is nothing
And in /var/lib/openhab/logs/openhab.log is my last entry from the 13th June
Is there any other log files?

Yes i installed the addon Javascript Transformation

When i only execute

RaumStatus.postUpdate("Test")

my Item is getting updated buf if i execute

var roomstate = transform("JS", "raumstatus.js", htmlCode)
RaumStatus.postUpdate("Test1")

my Item isn’t getting the Value Test1

So the whole rule is getting fucked up when i try to execute the js?

Wrong Java version, openHAB 3 requires Java 11 and openHAB 4 Java 17. No other versions supported !

Ahh okeyy thanks
I will try it

It might cause your issue, but it might not….

Yes

It was the Java Version
Thank you!

1 Like