Has anyone used Dingtian 8ch Ethernet Relay?

How can I integrate this module using MQTT with HA?

If it uses mqtt then it should be able to work with ha. Got any documentation?

There is a programming manual over here: ftp://ftp.dingtian-tech.com/relay_sdk.zip
Set up Mosquitto broker which is reading state of relay but do not know how to integrate it with HA.
I tried to implement a switch in confirguration.yaml file like that:
switch:

switch:

  • platform: mqtt
    name: ‘Relay1’
    state_topic: ‘dingtian/relay1413/out/relay1’
    command_topic: ‘dingtian/relay1413/in/relay1’
    payload_on: ‘on’
    payload_off: ‘off’

but it does not work.

Maybe someone has done it before?

The switch entiti is listed but does not work as toggle. I think, need some pyton code to read it???

I cannot get that link to the docs to work. Can you check it?

It works for me, after uploading and unzipping file all docs are there.

In the manual the data is stated to be ON and OFF not on and off.

The path has a leading / (according to the docs)

You right, changed it in yaml file but after restart it is the same.

I suggest some testing with mqttexplorer or mosquitto_pub/mosquitto_sub

Also although their documentation is a little confusing, aren’t they saying the commands and responses are JSON encoded? See https://www.home-assistant.io/integrations/switch.mqtt/

That’s work for me

  • platform: mqtt
    name: “lan relay 4”
    state_topic: “/dingtian/relay1690/out/r4”
    command_topic: “/dingtian/relay1690/in/control”
    payload_on: ‘{“type”:“ON/OFF”,“idx”:“4”,“status”:“ON”,“time”:“0”,“pass”:“0”}’
    payload_off: ‘{“type”:“ON/OFF”,“idx”:“4”,“status”:“OFF”,“time”:“0”,“pass”:“0”}’
    state_on: “ON”
    state_off: “OFF”
1 Like

H mate,
Ths for your code. I have tried it earlier and my moscito mqtt broker sees all message but when I am trying to toggle switch from UI nothing happen:(
What are your mqtt log?

Hi! I looks like we have different versions of dingtian relay.
The following code should work for you:

  - platform: mqtt
    name: "lan relay 1"
    state_topic: "/dingtian/relay1690/out/relay1"
    command_topic: "/dingtian/relay1690/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"}'


Here is my mqtt log, with shorts aliases (thats why previous code listing did not work for you)

Hi thx, my output from mqtt broker is completely diffrent, maybe because of the type of my relay which is 1413. More or less is working but HA does not know the current state of switch. Any idea how to solve this particular issue?

Config for light, switch, cover, garage door, rolling shutter.
need install cover time based component


 - 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"}'

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

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

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

light:
  - platform: switch
    name: "lampa  relay 1"
    entity_id: switch.lan_relay_1
    
cover:
  - platform: mqtt
    name: "GARAGE relay 2"
    device_class: garage
    command_topic: "/dingtian/relay1916/in/control"
    state_topic: "/dingtian/relay1916/out/input2"
    payload_open: '{"type":"DELAY","idx":"2","status":"ON","time":"1","pass":"0"}'
    payload_close: '{"type":"DELAY","idx":"2","status":"OFF","time":"1","pass":"0"}'
    payload_stop: '{"type":"DELAY","idx":"2","status":"ON","time":"1","pass":"0"}'
    state_open: '{"idx":"2","status":"HIGH"}'
    position_open: 100
    state_closed: '{"idx":"2","status":"LOW"}'
    position_closed: 0
    

  - platform: cover_time_based
    devices:
      room_rolling_shutter:
        name: Rolety Salon
        travelling_time_down: 20
        travelling_time_up: 20
        open_switch_entity_id: switch.lan_relay_3
        close_switch_entity_id: switch.lan_relay_4
        aliases:
        - room_rolling_shutter
1 Like

Please format your code properly.

Hi
I bought this dingtian switch and made configuration for HA. Generally everything is ok, but …

I disconnected switch from LAN and I looked in LOG of Mosquitto broker and found: “1616921500: Socket error on client 44H3mTP105rIGFa6Jkeqkb, disconnecting”, but the entity in HA is still active and available. The state in HA should be unavailable.

I found nothing about MQTT topic “avaibility” in documentation of switch. Do you have idea to get state of switch “online” and “offline” w/o this MQTT topic?

BR
Dariusz

I talked witch the manufacturer. The switch has not function " MQTT LWT". It’s impossible to use state unavailable, only state “on” and “off”.

Hi,
Did you sort out the issue with reatining a state of a switch?
BR
Rob