Retrieving a result from a command line HTTPS curl for use in a rule

I would like to use a command line invoked from a rule to query a HTTPS address to retrieve my AC’s status so that I can use in in a rule to update a switch item, the output is from the web query is JSON.

As my copy of Openhab is incapable of speaking HTTPS directly, I need to use Curl in a command line to retrieve the status. (I’ve already spent many hours trying to get SSL to work in Openhab and have given up!)

From the rule I call

var result = executeCommandLine(‘curl -sSH “Accept: application/json” “https://myurl?apiKey=myapi&limit=1&fields=acState”’, 5000)
logInfo(“Testing”, result)

which gives me in the log

{“status”: “success”, “moreResults”: true, “result”: [{“acState”: {“on”: false, “targetTemperature”: 25, “temperatureUnit”: “C”, “mode”: “cool”, “fanLevel”: “auto”}}]}

Can someone advise how I can extract the value after the word “on”: which will be either true or false?

I’ve tried using

var String status = (transform(“JSONPATH”, “$.on”, result))
logInfo(“Testing”, status)

but that only gives me a value of status=null and
Couldn’t resolve reference to JvmIdentifiableElement ‘transform’ from the designer, so I guess the example in the transformation wiki doesn’t work. (Cutting and pasting the example results in the same error in the designer, and I’m running V1.8 Nightly from a few weeks back so it should be up to date enough to work)

I’ve discovered by a lot of trial / error / google that the designer is telling lies and it is actually working if I use
var String status = (transform(“JSONPATH”, “$.result…on”, result))
Can someone explain how to get the designer to behave? Last time I updated it, it regularly gave syntax errors on everything so I’m on one of the earlier 1.8 Nightly designers, and it gives similar errors for Ecobee commands in rules.

I just built the latest openHAB code from the master branch, unzipped the resulting distribution-1.8.0-SNAPSHOT-designer-macosx64.zip, ran openHAB Designer.app, and saw that the Ecobee actions were being properly understood by the Designer, including helpful tooltips for usage and syntax.

How did what you try differ from this?

I would try an external script to do the curl + parsing, you are calling an executeCommandLine anyhow. Just put what you need into an external program and call it instead of “curl …”

The last one I tried was a few weeks back on Win7/64 over SMB to the Pi and after a minute or 2 it went crazy marking everything in the rules as an error, so I reverted to the older version. I’ll try the latest tomorrow on Win10 - do I have to update the rest of it or should it be broadly compatible?

It’s an idea, but given that I’ve got it working and my knowledge of Linux command lines is limited at best, I’ll leave it alone for now. I updated the post to help others following behind, I’ve learnt with Openhab and Raspbian to not meddle with working things!

The Designer ought to be usable standalone without impacting the runtime or addons, so give a recent build a try and please let us know. I did not test the Designer on Windows (no Windows machine on hand), so your input will be valuable. A screenshot or two of problems might also help, if possible. Thank you!

I just downloaded the latest and it shows errors with “transform” see pic


the line is:
var String status = (transform(“JSONPATH”, “$.result…on”, OfficeHeatpumpStatus))
In reality the command works.

The designer doesn’t show the Ecobee error anymore and hasn’t gone nuts after a few minutes use so that seems to be the only error.on Win10 64Bit

I can reproduce the problem (Designer does not recognize the transform action) on Mac 10.10.5 as well. I just opened issue #3432 for that. Luckily the action works in the runtime, regardless.

I’ve just updated to the released version of 1.8 and confirm this appears to be fixed.

1 Like