Dingtian IOT Relay Generic MQTT Things

Hi, I need a little help creating “things” for this module. I can read the status but not control it. the command in home assistant looks like this:

  - platform: mqtt
    name: "lan relay 1"
    state_topic: "/dingtian/relay1916/out/relay1"
    command_topic: "/dingtian/relay1916/in/control"
    payload_on: '{"type":"ON/OFF","idx":"1","status":"ON","time":"0","pass":"0"}'
    payload_off: '{"type":"ON/OFF","idx":"1","status":"OFF","time":"0","pass":"0"}'
    state_on: '{"idx":"1","status":"ON"}'
    state_off: '{"idx":"1","status":"OFF"}'

in Openhab like this:

Type switch : Din01r2  [ stateTopic="/dingtian/relay1916/out/relay2" , transformationPattern="JSONPATH:$.status", commandTopic="/dingtian/relay1916/in/control", on="ON", off="OFF"]

For the module to react, I have to send the following message:

control = {"type":"ON/OFF","idx":"1","status":"ON","time":"0","pass":"0"}

Thanks for your help

I found a solution

Type switch : Din01r1  [ stateTopic="/dingtian/relay1916/out/relay1" , transformationPattern="JSONPATH:$.status", commandTopic="/dingtian/relay1916/in/control", on="{\"type\":\"ON/OFF\",\"idx\":\"1\",\"status\":\"ON\",\"time\":\"0\",\"pass\":\"0\"}", off="{\"type\":\"ON/OFF\",\"idx\":\"1\",\"status\":\"OFF\",\"time\":\"0\",\"pass\":\"0\"}"] //Relay1
1 Like

Hi,

I recently bought the relay myself and I prefer old school config files.
I added this post in case someone needs a copy & paste example.

To control the relay, only the “chX_on_off” lines are necessary. The lines with “chX_state” show the current state of the input switch of that relay. In case you pulled e.g. input of relay 1 to ground, it shows “high”. Note: “chX_state” does not show the same state as the “chX_on_off” → you can toggle the relay on without needing to keep the input of that relay connected to ground.

The serial number of the device in this example is “55555”, so the mqtt channel name is “relay55555”

mqtt.things:

Thing topic dintianbroker “dingtian” {
Channels:
Type switch : ch1_on_off “Channel 1” [ stateTopic=“/dingtian/relay55555/out/r1”, commandTopic=“/dingtian/relay55555/in/r1”, qos=1 ]
Type string : ch1_state “Channel 1 input state” [ stateTopic=“/dingtian/relay55555/out/input1” ]
Type switch : ch2_on_off “Channel 2” [ stateTopic=“/dingtian/relay55555/out/r2”, commandTopic=“/dingtian/relay55555/in/r2”, qos=1 ]
Type string : ch2_state “Channel 2 input state” [ stateTopic=“/dingtian/relay55555/out/input2” ]
Type switch : ch3_on_off “Channel 3” [ stateTopic=“/dingtian/relay55555/out/r3”, commandTopic=“/dingtian/relay55555/in/r3”, qos=1 ]
Type string : ch3_state “Channel 3 input state” [ stateTopic=“/dingtian/relay55555/out/input3” ]
Type switch : ch4_on_off “Channel 4” [ stateTopic=“/dingtian/relay55555/out/r4”, commandTopic=“/dingtian/relay55555/in/r4”, qos=1 ]
Type string : ch4_state “Channel 4 input state” [ stateTopic=“/dingtian/relay55555/out/input4” ]
Type switch : ch5_on_off “Channel 5” [ stateTopic=“/dingtian/relay55555/out/r5”, commandTopic=“/dingtian/relay55555/in/r5”, qos=1 ]
Type string : ch5_state “Channel 5 input state” [ stateTopic=“/dingtian/relay55555/out/input5” ]
Type switch : ch6_on_off “Channel 6” [ stateTopic=“/dingtian/relay55555/out/r6”, commandTopic=“/dingtian/relay55555/in/r6”, qos=1 ]
Type string : ch6_state “Channel 6 input state” [ stateTopic=“/dingtian/relay55555/out/input6” ]
Type switch : ch7_on_off “Channel 7” [ stateTopic=“/dingtian/relay55555/out/r7”, commandTopic=“/dingtian/relay55555/in/r7”, qos=1 ]
Type string : ch7_state “Channel 7 input state” [ stateTopic=“/dingtian/relay55555/out/input7” ]
Type switch : ch8_on_off “Channel 8” [ stateTopic=“/dingtian/relay55555/out/8”, commandTopic=“/dingtian/relay55555/in/r8”, qos=1 ]
Type string : ch8_state “Channel 8 input state” [ stateTopic=“/dingtian/relay55555/out/input8” ]
}

youritemsfortherelay.items:

Switch ch1_on_off “Channel 1” {channel=“mqtt:topic:myBroker:dintianbroker:ch1_on_off”}
String ch1_state “Channel 1 input” {channel=“mqtt:topic:myBroker:dintianbroker:ch1_state”}