Migration oh2 to oh3 http binding

Hi!

I want to write here a short example to migrate the OH2 HTTP Binding to the new HTTP Binding in OH3 with your help.

At the moment I have the following http.cfg file with that:

beckhoff.url=https://192.168.1.50/beckhoff/callajax.php{Authorization=Basic xxy} beckhoff.updateInterval=2000 the callajax.php gives a JSON File back for States.

Item example:

String Gaeste_OutValue { http="<[beckhoff:2000:JSONPATH($.Gaeste_Light)]" }
Switch Gaeste_Out “Gäste Zimmer” (OG) { http=">[ON:POST:https://192.168.1.50/beckhoff/postdata.php?gaeste=true{Authorization=Basic xxy}] >[OFF:POST:https://192.168.1.50/beckhoff/postdata.php?gaeste=false{Authorization=Basic xxy}]" }

so, in OH3 I defined a new http thing, with base url: https://192.168.1.50/beckhoff/callajax.php

next would be a channel (switch channel) for the bulb in “Gäste Zimmer”.
I do not know what I have to configure for stat and command transformation and for ON / OFF Value.

You have to know that I wrote a php file with getting values as JSON in callajx.php and to POST values to toggle on off the light. (gaeste=true and gaeste=false).

so can anyone tell me how I can migrate these part ?
Thanks,
Klaus

Can you show us what you tried? Is there something in the docs which didn’t make sense? Can you also post an example of your JSON string?

json example:

{
Gaeste_Light: “off”,
Kind2_Light: “off”,
Kind1_Light: “off”,
EG_Bad_Dusche: “off”,
Garage_aussen: “off”,
Rainsensor: “off”,
ActPositionBuero: 99
}

ActPositionBuero is the percent for the blinds. 100 (complete closed), 0 (opened).

I only tried using http.cfg but I think this would not work. I do not know how to configure channels.
thanks,

Do you have a configuration preference? Using the UI is quite easy - have you tried that?

i would prefer UI. Can you tell me what I have to set in for the following channel configurations:

  • State Transformation
  • Command Transformation
  • On Value
  • Off Value

So if you type

https://192.168.1.50/beckhoff/postdata.php?gaeste=false

Into your browser, that turns your device off? And

https://192.168.1.50/beckhoff/postdata.php?gaeste=true

Turns your device on? If that’s all correct, I would do as follows (make sure you have the JSONPATH Transformation Service installed):

Thing

Channel

YAML

UID: http:url:phpSwitches
label: PHP Switches
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: https://192.168.1.50/beckhoff
  refresh: 30
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
channels:
  - id: Gaeste_Light
    channelTypeUID: http:switch
    label: Gaeste Light
    description: ""
    configuration:
      onValue: "true"
      stateExtension: /callajax.php
      offValue: "false"
      commandExtension: /postdata.php?gaeste=%2$s
      stateTransformation: JSONPATH:$.Gaeste_Light
1 Like

thanks for that perfect documentation!! can you tell me how I can test this? or how is my item declared to use it ? (in items file, and how?).
thanks in advance

Switch sGaesteLight "Gaeste Light" <light> { channel="http:url:phpSwitches:Gaeste_Light" }

thank you so much for your help! It works! I finally had to link the item to the Thing in the GUI, after that it worked!
Does my config in the gui writes the lights.items file too ?
I ask because I am now on my windows and I want to copy later all my configuration to my raspberrypi if everything works. is this just the conf folder to copy ?
thanks,

No, GUI configuration is saved in a JSON DB file. It does not get written to an Items file. I’m not sure what the correct procedure is for transferring to another device from Windows, I’m afraid.

hi, am I right, that I can use GUI or file based config ? if I configure my http thing in an .things file and the switch in my .items it would also be possible?

found the json files:
openHAB stores configuration information in JSON (JavaScript Object Notation) formatted (structured) text files located in the OPENHAB_USERDATA/jsondb/ directory.

Yes, it is possible. There’s no formal tutorial for this, but I have posted two examples in this forum which you could use to help: