HTTP Binding - commandTransformation Problem

Hello,

I want to send the follwing requests by changing a switch item.

http://<IP_ADDRESSE>/json-rpc?request={"command":"instance","subcommand":"startInstance","instance":1}

http://<IP_ADDRESSE>/json-rpc?request={"command":"instance","subcommand":"stopInstance","instance":1}

I use http binding with JINJA transformation. (maybe an easier approach is possible?)
Unfortunately I don’t get this to work.
With the follwing configuration, only the baseURL + commandExtension is sent.
The parameters used in the commandTransformation are not added to the URL.

Any idea what I did wrong?

thanks for a hint :slight_smile:

UID: http:url:HDR_Instance_1_State
label: HTTP URL Thing
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://<IP_ADDRESSE>/
  delay: 0
  stateMethod: GET
  refresh: 3000
  commandMethod: GET
  contentType: text/html
  timeout: 3000
  bufferSize: 2048
channels:
  - id: HDR_Instance_1_ON_OFF
    channelTypeUID: http:switch
    label: HDR_Instance_1_ON_OFF
    description: LED On / Off
    configuration:
      onValue: startInstance
      commandTransformation: JINJA:{"command":"instance","subcommand":"{{value}}","instance":1}
      offValue: stopInstance
      commandExtension: json-rpc?request=

Hi,

i wouldnt do this with the http binding…
i do something similar and do this via RulesDSL, the only rules i can :slight_smile:

create a Switch Item i.e. HDR_Instance_1_ON_OFF.
create a ruleDSL with:

rule "HDR Instance ON OFF"
when
Item HDR_Instance_1_ON_OFF changed 
then
if (newState == ON)
sendHttpGetRequest ('http://<IP_ADDRESSE>/json-rpc?request={"command":"instance","subcommand":"startInstance","instance":1}')
else sendHttpGetRequest ('http://<IP_ADDRESSE>/json-rpc?request={"command":"instance","subcommand":"stopInstance","instance":1}')
end

I think this will do what you want.
Greets.

Hi,
I used this approach already - and it works :slight_smile:

However, I use the http binding already to retrieve other LED parameters from HyperHDR.
The idea was to have all the parameters covered by the same binding and Thing, without an extra rule.
If I don’t get this to work, I will keep using the workaround using the rule.

The transformed value is being put into the body of the HTTP request. You need to put this into the URL instead.

For that you need to use the commandExtension: HTTP - Bindings | openHAB

The docs say thetransformed command is referenced in the commandExtension as %2$. So your command extension should be json-rpc?request=%2$ so that the result of the Jinja transformation is appended to the URL. Otherwise it’s included as the body of the HTTP request.

1 Like

Thanks a lot!
I missed this important information while reading the doc :frowning:
I added %2$s to the command extension - now it works. :slight_smile: