rule "CCU825_StateRead"
when
Time cron "0 0/5 * 1/1 * ? *"
then
var CCU825_JSON=sendHttpPutRequest("https://ccu.sh:8080/data.cgx?cmd=%7bBAuthorization=Basic%20Base64LoginAndPass%7d","application/json","{\“Command\”%3A%20\"GetStateAndEvents\"}”)
CCUPowerVoltage=transform("JSONPATH", "$.Power", CCU825_JSON)
end
In logs:
18:27:01.941 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'default.rules' has errors, therefore ignoring it: [5,167]: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )
[6,29]: missing ')' at 'JSONPATH'
[6,48]: String literal is not properly closed
rule "CCU825_StateRead"
when
Time cron "0 0/5 * 1/1 * ? *"
then
var CCU825_JSON=sendHttpPutRequest("https://ccu.sh:443/data.cgx?cmd=%7bBAuthorization=Basic%20Base64LoginPass%7d","application/json","{\"Command\":\"GetStateAndEvents\"}")
CCUPowerVoltage=transform("JSONPATH", "$.Power", CCU825_JSON)
end
If I use port 443 I see the following in logs:
19:45:00.346 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'CCU825_StateRead': json string can not be null or empty
In case of 8080:
19:35:01.008 [ERROR] [e.smarthome.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.TimeoutException: Total timeout 1000 ms elapsed
19:35:01.009 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'CCU825_StateRead': An error occurred during the script execution: Cannot assign a value in null context.
rule "CCU825_StateRead"
when
Time cron "0 0/2 * 1/1 * ? *"
then
var CCU825_JSON=sendHttpGetRequest("https://ccu.sh/data.cgx%7BAuthorization=Basic%20LOGINPASS%7D?cmd%3D%7B%22Command%22%3A%22GetStateAndEvents%22%7D")
logInfo("State Read", "CCU825_JSON: " + CCU825_JSON)
if (CCU825_JSON !== null ) { CCUPowerVoltage.sendCommand(transform("JSONPATH", "$.Power", CCU825_JSON)) }
end
and getting logs:
17:46:00.206 [INFO ] [pse.smarthome.model.script.State Read] - CCU825_JSON:
17:46:00.207 [ERROR] [untime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'CCU825_StateRead': json string can not be null or empty
So the request returns null. It seems that IF does not work because error comes from transform().
I saw PHP examples of the similar functionality for CCU825, they work with simple URL including request string. Separately headers are formed for authorisation. But here I have to put auth string into URL. Working PHP code:
I also easily did connection to the site using 2 lines of Python code. So my belief is that OpenHAB requires further development to provide useful functionality.
I don’t think so. It works just fine for me without url encoding. It treats everything you to the : as the username and everything after the : to the @ as the password. So you wouldn’t have a problem unless your username had a : in it.
There is no way to set a header using sendHttpGetzRequest.