KMTronic via HTTP binding

KMTronic is one of cheapest Web based wired IP DIN mountable relays available on the market. They not only are cheap, but also look cheap an have some shortcomings . Nevertheless they do the job (all my personal opinion).

One of the shortcommings is that the build in web-server is not able to proces a lot of requests at the same time. Therefore, do not set the “delay” parameters of the thing lower than 300 ms, even prefer 500 ms. If to many request in a short time, the device will hang and a reboot (disconnect power) is needed.

The devices can use DHCP, but no hostname is registered in DNS.

For those who want to use them, the only requirement is the HTTP binding.

The configuration :

UID: http:url:KMTronic1
label: KMTronic 8 x Relais nr 1
thingTypeUID: http:url
configuration:
  authMode: BASIC
  ignoreSSLErrors: false
  baseURL: http://hostmame-or-ipaddress/
  delay: 300
  stateMethod: GET
  refresh: 30
  commandMethod: GET
  contentType: text/html
  timeout: 3000
  bufferSize: 2048
channels:
  - id: KMTronic-1-1
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 1
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0101" else "FF0100"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay2/text()
  - id: KMTronic-1-2
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 2
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0201" else "FF0200"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay1/text()
  - id: KMTronic-1-3
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 3
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0301" else "FF0300"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay3/text()
  - id: KMTronic-1-4
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 4
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0401" else "FF0400"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay4/text()
  - id: KMTronic-1-5
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 5
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0501" else "FF0500"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay5/text()
  - id: KMTronic-1-6
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 6
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0601" else "FF0600"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay6/text()
  - id: KMTronic-1-7
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 7
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0701" else "FF0700"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay7/text()
  - id: KMTronic-1-8
    channelTypeUID: http:switch
    label: KMTronic 1 Kanaal 8
    description: ""
    configuration:
      onValue: "1"
      commandTransformation: DSL:|if(input == "1") "FF0801" else "FF0800"
      offValue: "0"
      stateExtension: status.xml
      commandExtension: "%2$s"
      stateTransformation: XPATH:/response/relay8/text()

Thanks to @rlkoshak for assisting getting this done.

1 Like

If you ever run into a situation where you need to send a bunch of commands to this device all at once (e.g. sending a command to a Group will forward that command to all members potentially resulting in a barrage of commands to the device locking it up), see Design Pattern: Gate Keeper.

There are several ways to use it but perhaps the easiest would be:

  1. create a Group:Switch to hold the proxy Items

  2. create a proxy Item for each Item actually linked to the the Channels from the Thing above and put them all into the Group created in 1. Make the names consistent with the naming of the linked Items (e.g. if the linked Item is named “Foo” name the proxy “Foo_Proxy”).

  3. create a rule that triggers on commands to members of the Group created in 1

  4. Use the Gatekeeper (see link above) to forward the command to the linked Item based on the name of the triggering Item (e.g. in JS Scripting items[event.itemName.replace('_Proxy', '')].sendCommand(event.itemCommand.toString()).

  5. Only use the proxy Items in your Rules, UI, semantic model, etc.

Gatekeeper will spread the commands out so they do not get sent to the device too fast and overwhelm it no matter where the commands come from.

Ideally this would be something that would be prevented in the binding. But since there is no binding for KMTronic, you need a rule to spread the commands out.

Note: I’ve rewritten the Gatekeeper design pattern and it now includes Blockly and JS Scripting implementations.

If somebody wants to take a deep dive :slight_smile:
There is also an “all relay” command, with FFE0xx you can set all relays at once (where xx is hex coded bit pattern, MSB is relay 8, LSB is relay 1).

So a simple solution to speed up multi-command switching would be to get all states of the relays, calculate the pattern needed for the new states of all relays and then send an all relay command.