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