I try to convert a DSL rule to a ECMA script, but i’m getting stuck for the right strings:
DSL Rule:
val orangeassistPostURL = "http://92.168.1.2:2828/assist/ask"
val timeoutSec = 10
val orgeassistcmd = '{"request": "zet badkamer aan"}'
rule "Badkamer radio Aan"
when
Item Schakel_Knop_Badkamer received command
then
Thread::sleep(100)
if(Schakel_Knop_Badkamer.state.toString == "single") {
var result = sendHttpPostRequest(orangeassistPostURL, "text/plain", orgeassistcmd, timeoutSec*1000)
}
end
ECMA Script so far:
var HttpUtil = Java.type("org.openhab.core.io.net.http.HttpUtil")
var url = "http://192.168.1.2:2828/assist/ask";
var orgeassistcmd = '{"request" : "zet badkamer aan"}';
HttpUtil.executeUrl("POST", url, orgeassistcmd, "text/plain", 2000)
But this gives me this error:
2021-01-21 09:35:56.863 [WARN ] [e.automation.internal.RuleEngineImpl] - Fail to execute action: 2
java.lang.ClassCastException: Cannot cast java.lang.String to java.io.InputStream
After changing orgeassistcmd to null, it’s working(POST send empty content), so I might need to change the format of orgeassistcmd?