I rebuild everything into a rule and now i get the following questions:
a) What is the return value if the sendHttpGetRequest() fails and how could I check it. The return type is String. Logfile show me - null if http failed
[...]
val Light1JSON = sendHttpGetRequest("http://192.168.x.xxx/api/<api-id>/lights/1", 60000)
logInfo("Light1JSON", Light1JSON)
if ( Light1JSON === null ) {
} else {
}
[...]
log:
2020-08-30 10:36:00.033 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Hue Bridge rule: Check state.on and state.reachable every minute (hue-bridge-changed.rules)': An error occurred during the script execution: index=1, size=1
b) Why can’t I use headers?
val headers = newHashMap("Cache-control" -> "no-cache")
val Light1JSON = sendHttpGetRequest("http://192.168.x.xxx/api/<api-id>/lights/1", headers, 60000)
log:
2020-08-30 10:00:00.012 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Hue Bridge rule: Check state.on and state.reachable every minute (hue-bridge-changed.rules)': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.HTTP.sendHttpGetRequest(java.lang.String,int) on instance: null
2020-08-30 10:00:35.110 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'hue-bridge-changed.rules', using it anyway:
// The value of the local variable headers is not used
As you’ve already discovered, the return is null.
That’s not a string though, it is just null.
So this will fail with the unhelpful mesage An error occurred during the script execution: index=1, size=1
when Light1JSON is null, because logInfo() needs two strings.
You just need to rejig your if()
val Light1JSON = sendHttpGetRequest( ...)
if ( Light1JSON === null ) {
logInfo("Light1JSON", "http response was null")
...
} else {
logInfo("Light1JSON", "http response was " + Light1JSON)
...
}
Headers are a recent addition to HTTP Actions.
I have an idea these are core Actions, and the core has been frozen at 2.5.0, so you won’t get headers until OH3