HTTP 1.x Binding to OH3 HTTP Binding?

For years now I’ve had my OH Items file setup to call a HTTP URL to turn on a ESPEasy device.
Here is an example of my items file.

//Relay items
Switch  ESP_0A902A      "Living Room Lamp"    <poweroutlet_us> (SmartLights)                          {http=">[ON:POST:http://192.168.2.56/control?cmd=GPIO,5,1:on] >[OFF:POST:http://192.168.2.56/control?cmd=GPIO,5,0:off]", alexa="Switchable"}

But I can’t figure out how that should be setup in OH3. I’ve migrated my Items file but I guess the old HTTP binding is no longer supported.
The HTTP Binding Documentation doesn’t show examples of using the new GUI HTTP binding. After I fill out the form here is what the code page looks like.

UID: http:url:a1470cc74c
label: ESP_0A902A Living Room Lamp
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://192.168.2.56/control?cmd=
  refresh: 30
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
location: Living Room
channels:
  - id: ESP_0A902A
    channelTypeUID: http:switch
    label: Living Room Lamp
    description: ""
    configuration:
      onValue: "1"
      offValue: "0"
      commandExtension: GPIO,5,1

Does anyone know of any examples of how to use the new OH3 UI for sending HTTP commands?

commandExtension: GPIO,5,%2$s

Weren’t you using POST before?

I’ve corrected both here is the new thing code.

UID: http:url:a1470cc74c
label: ESP_0A902A Living Room Lamp
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://192.168.2.56/control?cmd=
  refresh: 30
  commandMethod: POST
  timeout: 3000
  bufferSize: 2048
location: Living Room
channels:
  - id: ESP_0A902A
    channelTypeUID: http:switch
    label: Living Room Lamp
    description: ""
    configuration:
      onValue: "1"
      offValue: "0"
      commandExtension: GPIO,5,%2$s

Here is what the logs show.

2021-04-13 08:05:46.431 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'ESP_0A902A' received command ON
==> /var/log/openhab/openhab.log <==
2021-04-13 08:05:52.734 [WARN ] [ttp.internal.http.RefreshingUrlCache] - Splitting header '' failed. No '=' was found. Ignoring
2021-04-13 08:05:58.366 [WARN ] [ttp.internal.http.RefreshingUrlCache] - Splitting header '' failed. No '=' was found. Ignoring
2021-04-13 08:05:58.394 [WARN ] [.transform.SingleValueTransformation] - Executing transformation ChannelStateTransformation{pattern='$.state', serviceName='JSONPATH'} failed: Invalid path '$.state' in '
Failed'

What would the commandExtension be for a command like this? This command is momentary telling GPIO Pin 5 to pulse high1 for 500ms.

Switch  Garage_Relay     "Garage Door"        <garagedoor>     (SmartDevice)                          {http=">[ON:POST:http://192.168.2.53/control?cmd=Pulse,5,1,500]"}

None at all.

It’s not working but I did find a problem after looking at the log of the ESPEasy.
If I manually send the command via the browser using http://192.168.2.61/control?cmd=GPIO,12,0
I see a different response than when I use the OH UI. Here is the ESP log the first HTTP was sent via the web browser. The OpenHAB UI is sending a / before the command.

1278491682: HTTP: GPIO,12,0
1278491688: GPIO : port#12: set to 0
1278491739: SW : GPIO=12 State=0 Output value=0
1278491749: EVENT: Relay1#State=0.00
1278500833: HTTP:
1278514200: WD : Uptime 21309 ConnectFailures 24348 FreeMem 21536 WiFiStatus WL_CONNECTED ESPeasy internal wifi status: Conn. IP Init
1278530512: HTTP:
1278531586: HTTP: /GPIO,5,1
1278531591: Command unknown: '/GPIO,5,1'
1278531596: Command unknown: '/GPIO,5,1'

ESPEasy is super easy to integrate with MQTT. ESPEasy even supports Homie now which openHAB can automatically discover, meaning you don’t have to create or configure the Things at all.

Sometimes it’s worth considering alternatives.

That definitely would be a problem but you can address that by including “control?cmd=” in the commandExtension instead of the baseURL.

Yes, see the binding page:

When concatenating the baseURL and stateExtension or commandExtension the binding checks if a proper URL part separator (/, & or ?) is present and adds a / if missing.

So change to:

baseURL: http://192.168.2.56/control

and

commandExtension: ?cmd=GPIO,5,%2$s

I don’t think this will work as it doesn’t include one of the three quoted characters between the base and command URLs

1 Like

That’s really good to know thanks Rich.

I’m working to update my ESPEasy firmware now.

Note that I’m just going from their website. I’ve no idea how to enable it.

To enable MQTT in ESPEasy just add the following lines to your configuration-file:

mqtt:
  broker: <IP-Address of your MQTT-Broker>
  # Optional variables:
  discovery: true

The ‘discovery: true’ part is to enable autodiscovery-topics

1 Like

Christian

When you say configuration file are you talking about the config.dat file that can be downloaded from the ESPEasy? Or is that a OpenHAB config file?

Sorry, I mixed up ESPEasy and ESPHome :flushed:

Maybe you can find the info for ESPEasy here:
https://espeasy.readthedocs.io/en/latest/Controller/C014.html

Sorry for the confusion

No problem, I’m thinking about giving ESPHome a try now.
Have you ever used ESPEasy?
I’m curious, is one easier to use than the other for someone that’s not a programmer?

I only used ESPHome for a sensor I built of my own.
So unfortunately I cannot say if ESPEasy is easier :wink:

I selected ESPHome because it is able to do OTA-Updates and my Sensor is not near my computer.
As ESPEasy is not able to do that, I did not even tried it out.

Another alternative I would look at in your place, is TASMOTA
It is actively developed, has a huge userbase and many many examples here in the forums how to connect devices powered with it to openHAB.

For a simple lightswitch you should get online in minutes.

Kindest regards,
Christian…

Maybe I’m mistaken but ESPEasy she’s OTA updates too. I know I’ve updated mine without needing to plug them in to a computer.

Though you need to manually download the update to your machine running the browser. Maybe that’s what you are referring to?

Oh man, my knowledge of ESPEasy is less than nothing :blush:

I should stop making statements about functionalities I did not use by myself. :crazy_face:

Thank you for clarifying, Rich.