I’ve looked far and wide and not finding the answer to this one. In DSL, it is as simple as
Doing this in an OpenHab 3 ECMA script generates an error
Script execution of rule with UID 'camera_trigger_all' failed: ReferenceError: "sendHttpGetRequest" is not defined in <eval> .
I’m not surprised it needs to be coded a little different. Just can’t find it.
Though if the returned output is gzip encoded then I dont know how to decode that
Better to use the http binding
One line in DSL is now 15 lines of code? There must be something I’m missing here?
I am using http requests in my ECMA Script rules to send commands to my radio.
For me it works to add the HttpUtil namespace in the rule an then use the executeurl function.
var HttpUtil = Java.type("org.openhab.core.io.net.http.HttpUtil")
HttpUtil.executeUrl("GET", radioIpAdress + "/main/setVolume?volume=up&step=1", 2000)
Java function from openhab-core for reference:
Thanks for the code snippet!
Was looking for hours to do the same (pinging healthchecks.io) and did not find any good solution to translate the sendHttpGetRequest to ECMA. With your code it works!
Fantastic! That’s way better than 15 lines of code. Thanks
But to come back to the original problem: I don’t see it as very handy to find out the correct namespace before being able to use functions like these.
And the devs also see this as a problem: