Item with exec binding

Hi there,

I’m a beginner in openhab and have some problems to make an item with a exec binding work. :sob:
I installed the openhab-offline-2.0.0-SNAPSHOT version so that I assume all the extentions are installed as well.

My simple item looks like this:

Number Aussentemperatur "Aussentemperatur [%.1f °C]" <temperature> {exec="<[curl -i -H "Accept: application/json" http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature:JSONPATH($.value)]"}

…and the sitemap like this:

sitemap test label="Temperatur"
{
    Frame label="Aussentemperatur" {
		Text item=Aussentemperatur label="Aussentemperatur [%.1f °C]"
    }
}

If I use the curl instruction in a cmd window then I get back the expected answer from a REST server in JSON format.

This command:

C:\temp\curl>curl -i -H "Accept: application/json" http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature

gives the following reply from the REST server:

HTTP/1.1 200 The request has succeeded
Content-Type: application/vnd.com.bosch.bios.fusion.ems.http.property+json; charset=ISO-8859-1
Content-Length: 392
Date: Mon, 26 Sep 2016 19:39:11 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Accept-Ranges: bytes
Server: Noelios-Restlet-Engine/1.1.7
Connection: close

{“unitOfMeasure”:"?C","_links":{“getFromECU”:{“href”:“http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature?forceUpdate=true"},“self”:{“href”:“http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature”},“update”:{“href”:“http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature”}},“lastChanged”:“2016-09-26T21:39:11”,“name”:“HTIII_EMS_OutdoorTemperature”,"value”:14}

But openhab only returns this error message in the log: :frowning:

22:57:48.018 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Aussentemperatur’ for widget org.eclipse.smarthome.model.sitemap.Text
22:57:48.019 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text
22:57:48.020 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item for widget org.eclipse.smarthome.model.sitemap.Text
22:57:48.023 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Aussentemperatur’ for widget org.eclipse.smarthome.model.sitemap.Text
22:57:48.023 [ERROR] [ui.internal.items.ItemUIRegistryImpl] - Cannot retrieve item ‘Aussentemperatur’ for widget org.eclipse.smarthome.model.sitemap.Text

Any idea what I made wrong? Or what is missing?

I should probably write a big, bold, blinking warning on the wiki for the Exec binding. The Exec binding is not easy to use. I do not recommend it for beginners until they have a bit of both OS (if you are new to the OS OH is running on as many new Raspberry Pi users seem to be) and OH.

For one you have to escape the double quotes in your command string.

exec="<[curl -i -H \"Accept: application/json\" http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature:JSONPATH($.value)]"

Second, you MAY have to replace the spaces in the command with ‘@@’

exec="<[curl@@-i@@-H@@\"Accept:@@application/json\"@@http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature:JSONPATH($.value)]"

Finally, if you actually want to see what the curl command spits out when you call it, you need to create a Rule and use:

val results = executeCommandLine("curl -i -H \"Accept: application/json\" http://192.168.0.12:8182/properties/HTIII_EMS_OutdoorTemperature", 5000)
logInfo("Test", results)

Look in openhab.log for the results.

Once again, if the above doesn’t work, replace the spaces with @@.

One thing to remember when openHAB runs command lines like this:

  • The command is executing as the openhab user which has limited permission
  • The command is not executing in a shell so some shell features like piping and redirects may not be available
  • The openhab user may or may not have a path which includes the command you are trying to run, so use the fully path to and commands and files referenced

And even when all of this is taken into account a lot of times it still won’t work. Though often putting the command into a simple shell script and calling that script will work.

2 Likes

Many many thanks for the very detailed reply. I will try your recommendations today evening.
Unfortunately I have to use the exec binding because of the data I would like to handle with openhab are from a REST server. Normally I wanted to use the http binding but since it is not possible to send message bodies (this is what I read somewhere) there seems to be no way around the exec binding. Isn’t it?

Have I nice day. :relaxed:

I think you can send a body if you use the HTTP actions.

It still isn’t as flexible as curl but it might be good enough.