Help with Waveshare POE TCP Modbus Relay configuration

I have a Waveshare 8-channel Modbus POE ETH Relay and I’m really struggling with getting it integrated into Home Assistant.

I know the IP address is correct and the port is what I see in the web UI. I have been able to connect in python directly using pymodbus TCP client, but I can’t get the relays to toggle on\off using HA or in the Python REPL with pymodbus.

This is my test config using relay 8.

modbus:
  - name: waveshare_relay
    type: tcp
    host: 192.168.0.107  # Replace with your device's IP address
    port: 4196           # Replace with your device's port
    binary_sensors:
      - name: relay_1_status
        slave: 1
        address: 0
        input_type: coil
        scan_interval: 5
    switches:
      - name: relay_1
        slave: 1
        address: 0
        write_type: coil

Has anyone used this device before and configured it successfully? I’m really at a loss after several hours of different attempts. ty!

Some logs for this…

2024-05-19 13:40:18.364 INFO (MainThread) [homeassistant.setup]
    Setting up modbus
2024-05-19 13:40:18.376 INFO (MainThread) [homeassistant.setup]
    Setting up switch
2024-05-19 13:40:18.378 INFO (MainThread) [homeassistant.setup]
    Setup of domain switch took 0.00 seconds
2024-05-19 13:40:18.381 INFO (MainThread) [homeassistant.setup]
    Setup of domain modbus took 0.02 seconds
2024-05-19 13:40:18.388 INFO (MainThread) [homeassistant.components.modbus.modbus]
    modbus waveshare_relay communication open
2024-05-19 13:40:29.088 INFO (MainThread) [homeassistant.components.binary_sensor]
    Setting up modbus.binary_sensor
2024-05-19 13:40:29.092 INFO (MainThread) [homeassistant.components.switch] 
    Setting up modbus.switch
2024-05-19 13:40:42.084 ERROR (MainThread) [homeassistant.components.modbus.modbus]
    Pymodbus: waveshare_relay:
    Error: device: 1 address: 0 -> Modbus Error: [Input/Output] 
    ERROR: No response received after 3 retries

My device config from VirCOM looks like this.

And the device Web UI shows the same.

Removing the sensor section fixed it… this works.

modbus:
  - name: waveshare_relay
    type: tcp
    host: 192.168.0.107  # Replace with your device's IP address
    port: 502           # Replace with your device's port
    switches:
      - name: Relay 1
        address: 0
        slave: 1
        write_type: coil
      - name: Relay 2
        address: 1
        slave: 1
        write_type: coil
      - name: Relay 3
        address: 2
        slave: 1
        write_type: coil
      - name: Relay 4
        address: 3
        slave: 1
        write_type: coil
      - name: Relay 5
        address: 4
        slave: 1
        write_type: coil
      - name: Relay 6
        address: 5
        slave: 1
        write_type: coil
      - name: Relay 7
        address: 6
        slave: 1
        write_type: coil
      - name: Relay 8
        address: 7
        slave: 1
        write_type: coil
3 Likes

Hi mate,

Side question, did you just plug that relay module in and IP was detected automatically?
I just received one and plugging it into my network it doesnt get an ip assigned.

Is there some sort of magic preconfiguration required?

TIA
Mick

The device does not get an DHCP IP address by default - it is assigned the IP 192.168.1.200. I followed the guide below to download the VirCom software, which saw the relay on the network and then I enabled DHCP for IP addressing. Worked great!

3 Likes

Hi all, first post in this forum for me and hoping on some support from the team here.

I have a similar issue with the Waveshare POE Eth Relay module.

  • it looks like my communication to the module is working as both the Rxd & Txd led are flashing once I send a command out of HA to toggle the relay. (this is not working if any of the communication parameters would change)

  • Home assistant is also getting the feedback that the relay has been switched although it has not.

  • It looks like my waveshare module is in linkage mode (when triggering an input the corresponding output relay will also trigger with led indication)

  • with SSCOM I tried to disable the linkage mode by sending the following command;

    while sending the command the Rxd led flashes so I would assume it’s being received but nothing changes for the relays.

  • pushing the “CH1 relay ON” in SSCOM does also not work (and it is also not being received)

This is what I tried so far and likely there is something stupid that I’m missing.
Who can give some advice?

Thanks,

Stign

Use sscom to send the neccesary command. Then use HA to toggle relays or Modbus Poll.

0x0000:Normal mode,relays are directly controlled by commands;
0x0001: Linkage mode,relay status is consistent with the corresponding input channel status;
0x0002:Toggle mode,a pulse in the input channel toggles the relay state once;
0x0003: Edge mode,an edge change in the input channel toggles the relay state once

  • To set all relays to Toggle Mode (control mode 0x0002) using Modbus TCP, the command needs to write the value 0x0002 to all 8 registers starting at 0x1000.

Modbus TCP Command:

00 01 00 00 00 17 01 10 10 00 00 08 10 00 02 00 02 00 02 00 02 00 02 00 02 00 02 00 02
  • To set all relays to Normal Mode (0x0000), the command needs to write the value 0x0000 to all 8 registers starting at 0x1000.

Modbus TCP Command:

00 01 00 00 00 17 01 10 10 00 00 08 10 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  • To set all relays to Edge Mode (0x0003), the Modbus TCP command writes the value 0x0003 to all 8 registers starting at 0x1000.

Modbus TCP Command:

00 01 00 00 00 17 01 10 10 00 00 08 10 00 03 00 03 00 03 00 03 00 03 00 03 00 03 00 03

Tried this with toggle mode in HA. Works perfect after a few days of wanting to put a hammer to relay.

Code used in HA:

modbus:
  - name: waveshare_relay
    type: tcp
    host: 1.2.3.4 # Replace with your device's IP address
    port: 502 # Replace with your device's port
    switches:
      - name: Relay 1
        address: 0
        slave: 1
        write_type: coil
      - name: Relay 2
        address: 1
        slave: 1
        write_type: coil
      - name: Relay 3
        address: 2
        slave: 1
        write_type: coil
      - name: Relay 4
        address: 3
        slave: 1
        write_type: coil
      - name: Relay 5
        address: 4
        slave: 1
        write_type: coil
      - name: Relay 6
        address: 5
        slave: 1
        write_type: coil
      - name: Relay 7
        address: 6
        slave: 1
        write_type: coil
      - name: Relay 8
        address: 7
        slave: 1
        write_type: coil

thanks, worked first time trying! (putting it in normal mode)

still wondering why the code on the wiki (https://www.waveshare.com/wiki/Modbus_POE_ETH_Relay_(B)#Modbus_RTU_Development_Protocol) is wrong or not suitable to switch the waveshare relay module from linkage mode to normal mode.

either way, thanks again! :slight_smile:

Most probably the assumption that Modbus RTU protocol is the default most will use. So giving the tools / explanation on the wiki to convert RTU to TCP is sufficient.

But like all of us, we want a one stop solution!

Waveshare have so many products that do similar things, so easier to copy and paste I reckon.

Glad it’s all working now, was banging my head against my desk for a while then it clicked.

1 Like

I know the last post is quiet old. But in case someone else is having trouble with the POE TCP Modbus relay: On my side I couldn’t get the readout work reliably. When resetting the device via the “DEF” pin, the TCP modbus readout would work but after setting a custom IP, it would no longer work.

What solved it on my side is an update to Firmware version 1.523, which is available here:
https://files.waveshare.com/wiki/RS485-TO-ETH-B/Firmware/1.523(2007).BIN

Please note that this version cannot be downgraded anymore. For details on the upgrade process, please refer to the manual (page 49 to 52).
After upgrading, the webinterface has to be re-downloaded to the device.

You are a genius, this worked after I wanted to throw it through hades. The last command. Now to figure out the way to detect inputs

00 01 00 00 00 17 01 10 10 00 00 08 10 00 02 00 02 00 02 00 02 00 02 00 02 00 02 00 02

That works for me for the B Poe ETH module. It goes in the lower right white space of SSCOM and hit send when you are connected. Then everything worked in case anyone was confused like I was.

Then the code for configuration.yaml

modbus:
  - name: Waveshare_01
    type: tcp
    host: 192.168.20.211  # Replace with your device's IP address 
    port: 502           # Replace with your device's port
    switches:
      - name: "Waveshare Relay 1-1"
        address: 0
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_1
      - name: "Waveshare Relay 1-2"
        address: 1
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_2
      - name: "Waveshare Relay 1-3"
        address: 2
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_3
      - name: "Waveshare Relay 1-4"
        address: 3
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_4
      - name: "Waveshare Relay 1-5"
        address: 4
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_5
      - name: "Waveshare Relay 1-6"
        address: 5
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_6
      - name: "Waveshare Relay 1-7"
        address: 6
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_7
      - name: "Waveshare Relay 1-8"
        address: 7
        slave: 1
        write_type: coil
        unique_id: modbus_01_relay_8

  - name: Waveshare_02
    type: tcp
    host: 192.168.20.212
    port: 502
    switches:
      - name: "Waveshare Relay 2-1"
        address: 1
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_1
      - name: "Waveshare Relay 2-2"
        address: 2
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_2
      - name: "Waveshare Relay 2-3"
        address: 3
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_3
      - name: "Waveshare Relay 2-4"
        address: 4
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_4
      - name: "Waveshare Relay 2-5"
        address: 5
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_5
      - name: "Waveshare Relay 2-6"
        address: 6
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_6
      - name: "Waveshare Relay 2-7"
        address: 7
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_7
      - name: "Waveshare Relay 2-8"
        address: 8
        slave: 1
        write_type: coil
        unique_id: modbus_02_relay_8

    binary_sensors:
      - name: "Waveshare Input 2-1"
        slave: 1
        address: 0
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_1

      - name: "Waveshare Input 2-2"
        slave: 1
        address: 1
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_2

      - name: "Waveshare Input 2-3"
        slave: 1
        address: 2
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_3

      - name: "Waveshare Input 2-4"
        slave: 1
        address: 3
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_4

      - name: "Waveshare Input 2-5"
        slave: 1
        address: 4
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_5

      - name: "Waveshare Input 2-6"
        slave: 1
        address: 5
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_6

      - name: "Waveshare Input 2-7"
        slave: 1
        address: 6
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_7

      - name: "Waveshare Input 2-8"
        slave: 1
        address: 7
        input_type: discrete_input
        scan_interval: 1  # Update every 1 second
        unique_id: modbus_02_input_8
        

Only issue is unque Id’s aren’t working, HA makes them, not sure why. But inputs work with 1 second delay, relays all work pretty fast. (I have the A and B Module, A is Waveshare 1, B is waveshare 2.

Anyone who knows how to get unique id’s fixed feel free to fix my code. BTW Toggle mode I believe will toggle the relay when B module input detects signal, so you need normal mode. Now I can use it to detect like my fire alarm or 8 inputs.

1 Like

Archades previous post was the only thing I could find on the entire internet that worked for getting my digital inputs working. (chatgpt had been telling me to set “input_type:discrete” instead of “input_type:discrete_input” for the binary_sensors section).

I didn’t update my firmware (V1. 486) and everything seemed to get working now.

Excited to automate!

Could you elaborate on the steps it took to get this working? How complicated is all this?

I am looking at buying one of these boards to automate my irrigation system in HA, but from this thread as well as the seemingly crazy complicated instructions on the waveshare wiki I’m wary whether I’ll get this working with my very limited coding / networking knowledge.

Where does all this code go that was posted in the thread?

For anyone looking for the solution to this, I found a video explaining all the steps to get this working - its in italian, but youtubes CC will translate it well. Following this, it was super easy to get it all working.

I copied the following code into my config file. You’ll have to adjust the IP you set using the VirCOM and you can obviously adjust the names to whatever you want. For me this going to be an irrigation controller, so they are valves.

modbus:
  - name: Irrigation
    type: rtuovertcp
    host: 192.168.0.200
    port: 4196
    timeout: 9
    switches:
    - name: Valve 1
      slave: 1
      address: 0
      write_type: coil
    - name: Valve 2
      slave: 1
      address: 1
      write_type: coil
    - name: Valve 3
      slave: 1
      address: 2
      write_type: coil
    - name: Valve 4
      slave: 1
      address: 3
      write_type: coil
    - name: Valve 5
      slave: 1
      address: 4
      write_type: coil
    - name: Valve 6
      slave: 1
      address: 5
      write_type: coil
    - name: Valve 7
      slave: 1
      address: 6
      write_type: coil
    - name: Valve 8
      slave: 1
      address: 7
      write_type: coil

Hey how do you make to read the digital inputs from the WaveShare ModBus RTU Relay (D) ? Im using the configuration below, but is not working :slightly_frowning_face:

Only works the relays…

modbus:
  - name: modbus_waveshare_0
    type: rtuovertcp
    host: 192.168.1.254
    port: 502

    #delay: 2
    #message_wait_milliseconds: 30
    #timeout: 10

    binary_sensors:
      - name: panel_1_input_1_
        slave: 1
        slave_count: 8
        address: 0
        input_type: coil
        unique_id: panel_1_input_1_
        scan_interval: 1  # Update every 1 second
    
    lights:
      - name: "panel_1_relay_1_1"
        address: 0
        write_type: coil
        slave: 1
        #verify:
      - name: "panel_1_relay_1_2"
        address: 1
        write_type: coil
        slave: 1
        #verify:      
      - name: "panel_1_relay_1_3"
        address: 2
        write_type: coil
        slave: 1
        #verify:
      - name: "panel_1_relay_1_4"
        address: 3
        write_type: coil
        slave: 1
        #verify:
      - name: "panel_1_relay_1_5"
        address: 4
        write_type: coil
        slave: 1
        #verify:
      - name: "panel_1_relay_1_6"
        address: 5
        write_type: coil
        slave: 1
        #verify:
      - name: "panel_1_relay_1_7"
        address: 6
        write_type: coil
        slave: 1
        #verify:
      - name: "panel_1_relay_1_8"
        address: 7
        write_type: coil
        slave: 1
        #verify:

Hi, try to add them one by one.

    binary_sensors:
      - name: wsrelayinput1
        slave: 1
        address: 0
        input_type: discrete_input
        device_class: door
        scan_interval: 1
        unique_id: wsrelayinput1
      - name: wsrelayinput2
        slave: 1
        address: 1
        input_type: discrete_input
        device_class: door
        scan_interval: 1
        unique_id: wsrelayinput2