HTTP help for a Newbie

Let me share an example. Here is my thing:

UID: http:url:e5a14ec3b0
label: Lareira
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: true
  baseURL: https://192.168.129.10:8000/recepcion_datos_4.cgi
  delay: 0
  stateMethod: POST
  refresh: 120
  commandMethod: POST
  contentType: text/plain
  timeout: 3000
  bufferSize: 2048
channels:
  - id: switch
    channelTypeUID: http:switch
    label: Switch
    description: ""
    configuration:
      onValue: "1"
      mode: READWRITE
      stateContent: idOperacion=1002
      commandTransformation: JS:cmdEcoforestSwitch.js
      offValue: "0"
      stateTransformation: JS:getEcoforestSwitch.js

A small explanation:

  1. OH uses ‘0’ and ‘1’ as a switch status. So, when I query the device status (using a POST with idOperacion=1002), I have to convert its answer to a ‘0’ or a ‘1’. I use getEcoforestSwitch.js for that. It receives the device answer, parses it, and returns either a ‘0’ or a ‘1’. Therefore, even when I switch the device on/off using another method, OH is able to collect the actual status
  2. When I want OH to switch the device on or off, I use cmdEcoforestSwitch.js for that. It receives either ‘0’ or ‘1’ as input and converts it to the string that the device expects to switch on or off. The binding sends this output to the device with a POST

This requires an HTTP binding version that, at the time of writing, is only available in snapshots. Probably it will be included in OH3.1.0.M2 by month end. My device accepts text/plain for the commands, in your case you should probably use text/xml or text/html.

My actual configuration has more channels. It’s a pellet stove and I use these other channels to control temperature and alarms. The concept is the similar to the switch shown above (the main difference is that you are not obliged to have ‘0’ and ‘1’ states).

  - id: temp
    channelTypeUID: http:string
    label: Temperature
    description: null
    configuration:
      mode: READONLY
      stateTransformation: JS:getEcoforestTemp.js
      stateContent: idOperacion=1002
  - id: stat
    channelTypeUID: http:string
    label: Status
    description: null
    configuration:
      mode: READONLY
      stateTransformation: JS:getEcoforestStat.js
      stateContent: idOperacion=1002
  - id: temp_obj
    channelTypeUID: http:string
    label: Set Temperature
    description: null
    configuration:
      mode: READWRITE
      stateContent: idOperacion=1002
      commandTransformation: JS:cmdEcoforestTempObj.js
      stateTransformation: JS:getEcoforestTempObj.js
  - id: alarm
    channelTypeUID: http:string
    label: Alarm
    description: null
    configuration:
      mode: READONLY
      stateTransformation: JS:getEcoforestAlarm.js
      stateContent: idOperacion=1079

In the case of a IR remote additional channels can be used to control other TV functions.

Hope this helps.

1 Like