Help with Waveshare POE TCP Modbus Relay configuration

@BKifft Thank you very much for your reply!

Your integration is working. But I do not see how it is possible to configure it into HA to make it flash for 500 or 700ms

The integration sebastianfs82 does not seem to work and with that integration it should be possible.

I see the following in the logs:

Logger: homeassistant.util.loop
Bron: util/loop.py:77
Eerst voorgekomen: 22:54:50 (1 gebeurtenis)
Laatst gelogd: 22:54:50

Detected blocking call to import_module with args (‘custom_components.waveshare_relay.sensor’,) in /usr/src/homeassistant/homeassistant/loader.py, line 1282: return importlib.import_module(f"{self.pkg_path}.{platform_name}“) inside the event loop; This is causing stability issues. Please create a bug report at GitHub · Where software is built For developers, please see Blocking operations with asyncio | Home Assistant Developer Docs Traceback (most recent call last): File “”, line 198, in _run_module_as_main File “”, line 88, in _run_code File “/usr/src/homeassistant/homeassistant/main.py”, line 227, in sys.exit(main()) File “/usr/src/homeassistant/homeassistant/main.py”, line 213, in main exit_code = runner.run(runtime_conf) File “/usr/src/homeassistant/homeassistant/runner.py”, line 154, in run return loop.run_until_complete(setup_and_run_hass(runtime_config)) File “/usr/local/lib/python3.13/asyncio/base_events.py”, line 706, in run_until_complete self.run_forever() File “/usr/local/lib/python3.13/asyncio/base_events.py”, line 677, in run_forever self._run_once() File “/usr/local/lib/python3.13/asyncio/base_events.py”, line 2034, in _run_once handle._run() File “/usr/local/lib/python3.13/asyncio/events.py”, line 89, in _run self._context.run(self._callback, *self._args) File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 2568, in async_forward_entry_setups await integration.async_get_platforms(platforms) File “/usr/src/homeassistant/homeassistant/loader.py”, line 1151, in async_get_platforms platforms.update(self._load_platforms(platform_names)) File “/usr/src/homeassistant/homeassistant/loader.py”, line 1076, in _load_platforms platform_name: self._load_platform(platform_name) File “/usr/src/homeassistant/homeassistant/loader.py”, line 1250, in _load_platform cache[full_name] = self._import_platform(platform_name) File “/usr/src/homeassistant/homeassistant/loader.py”, line 1282, in _import_platform return importlib.import_module(f”{self.pkg_path}.{platform_name}")

Any idea what is wrong?

Or @BKifft can you tell me how it possible with your integration how to make the relay flash on for 500 of 700ms please?

With my own integration its only possible thru an automation or something like that, youll have to use the fork from icecoldfire, his version has flash intervals, the version from sebastianfs82 only works with the 8 Channel Version, not shure if it supports flash intervals too…

If you want to use my integration, you should be able to configure an automation that flashes the relay for 500/700ms

Here is a blueprint that can flash switches for 100-5000ms, it should work perfectly with my Waveshare Integration. If u need help setting it up, or need more features, feel free to massage me…

blueprint:
  name: Flash Switch
  description: "Schaltet einen Schalter mehrfach mit einstellbarem Zeitintervall (ms) ein/aus."
  domain: automation
  input:
    target_switch:
      name: Ziel-Schalter
      selector:
        entity:
          domain: switch
    flash_interval:
      name: Intervall (ms)
      default: 500
      selector:
        number:
          min: 100
          max: 5000
          unit_of_measurement: milliseconds
          step: 100
          mode: slider
    repetitions:
      name: Wiederholungen
      default: 5
      selector:
        number:
          min: 1
          max: 20
          step: 1

trigger:
  platform: event
  event_type: flash_switch

action:
  - repeat:
      count: !input repetitions
      sequence:
        - service: switch.turn_on
          target:
            entity_id: !input target_switch
        - delay:
            milliseconds: !input flash_interval
        - service: switch.turn_off
          target:
            entity_id: !input target_switch
        - delay:
            milliseconds: !input flash_interval

@BKifft Thank you for the bluescript. That worked out fine! :slightly_smiling_face:
Thanks for helping me. Now I can get it working like I want :+1:

1 Like

My pleasure, have fun with your projekt. :slight_smile:

I’m considering using this as well. I haven’t used TCP Modbus devices before so there are a couple of things I’m unsure about:

a. Will this relay connect to HA if HA’s on a subnet LAN? Eg. My main gateway (to which I’ll connect this relay) has another router (with its own LAN) connected to it - my HA is connected to this “other” router. Will TCP modbus still work? I have other relays connected this way to HA and they’re all doing MQTT, with some port forwarding involved.

b. Can I make this work with HA over MQTT?

Thanks.

i have question about those relays
if you make toggle the DIs
my question is if you trigger the Di1 why in HA is not showing that input is triggered ?
is there any info about how to fix this ?
my DIs work on roll on swiches and if i press them the relay responds but in home assistant the appearance of swich stays off …
can some one help

Thanx in advance

any idea ?

Hi!

I’m planning to buy few of those to control home lights. As long as I’m aware of I can set all inputs to toggle latches, so it should work by itself, without connection to any controller or HA, right?
Also, can you actually read the states of relays or inputs inside HA?

My application is home lights:

  • wall momentary switch (a.ka. doorbell switch) connected to DI1
  • latch DO in toggle mode
  • Through modbus, rs242, ethernet (that’s not important), HA will receive the relay state change on DO1 (on/off)
  • Through modbus, rs242, ethernet (that’s not important), HA will receive the pulse DI1 signal to later use

Why like that? I wan’t my lights to work when:

  • There’s no internet connection
  • The HA is not working

I started to educate in that metter yesterday and I’m pretty surprised there are not much implementions like this, except those needing expensive controllers. I had an idea to use “dumb” bistable relay switches, but those actually implement some more complexity, with changing voltages from 24v to 5/3.3 and become fairly expensive when we talk about 20+ channels to implement.

This Waveshare module actually look like “the one”, and it will cost like 10-15% of commercial smart home system :slight_smile:

  • There’s no internet connection
  • The HA is not working

you dont need internet to control (local)
the ha is not working ? what you mean ???
DIs can be in 4 different modes
follow , toggle , edge , normal
also about the lights control is not big deal depents of your swich’s
example is buttons normal swich you must define the di’s what you need to read to do
example follow and normal must be controlled by HAOS the rest can be autonomus they dont need haos to change theyr stastes in case of haos is off or not working those modes will work perfect …

i face alot problems with those cuz as you see theyr not any support at all…

So welcome to the club :smiley:

Hey guys,

i also have one of these POE 8 port relays and i have now played about 8h with it and i sear i am pulling my hair out with this thing.

I got it that far that it i select multi-host non-storage type in More Advanced Settings... i am able to run the python demo script linked here: https://www.waveshare.com/wiki/Modbus_POE_ETH_Relay#Raspberry_Pi

running the modbus_tcp.py script

and i can hear all relays click. perfect

i dont know if the modbus_rtu.py script should work as well with the following settings but in my case it does not.

then after switching to Simple Modbus TCP to RTU i am just not able to connect homeassistant to it. I tried the native way with the switches manually configured as well as both plugins:

and it seems that the waveshare module is just not answering. I always get

Modbus Error: [Input/Output] No response received after 3 retries, continue with next request

in SSCOM i can toggle the first switch in multi-host non-storage type mode with

00 00 00 00 00 06 01 05 00 00 00 00

and

00 00 00 00 00 06 01 05 00 00 FF 00

but i can not toggle it with

01 05 00 00 FF 00 8C 3A

in Simple Modbus TCP to RTU mode.

i dont know what to test or debug any further but at least i know that its not broken because the python script works in multi-host non-storage type mode.
i tripple checked all the settings but maybe i have overseen something?

so to sum it up: it seems like only this Simple Modbus TCP to RTU does not work.

not sure if relevant but the waveshare is powered by my unifi POE switch and is in the same vlan as my home assistant (which is also attached to the same switch)

Update:

I got it sort of working in TCP mode with the following config:

modbus:
  - name: waveshare-1
    type: tcp
    host: 10.0.20.59
    port: 502
    timeout: 9
   
    switches:
    - name: Valve 1
      slave: 1
      address: 0
      write_type: coil
      unique_id: valve1

# does not work
    binary_sensors:
    - name: Valve 1
      slave: 1
      address: 0
      input_type: discrete_input
      device_class: door
      scan_interval: 1
      unique_id: valve1

with

type: rtuovertcp

or any of the pluging i didn’t get it to work. What still does not work is fetching the state so the switching mechanism is one-way only. I dont know why RTU over TCP does not work and why the status-fetching does also not work. if anyone has an idea i would love to hear :smiley:

UPDATE 2:

i finally got it working. the following setup works for me

modbus:
  - name: waveshare-1
    type: tcp
    host: 10.0.20.59
    port: 502
    timeout: 9
    
    binary_sensors:
    - name: Waveshare Valve 1 Sensor
      slave: 1
      address: 0
      #input_type: discrete_input
      input_type: coil
      scan_interval: 1
      unique_id: valve1_sensor
        
    switches:
    - name: Waveshare Valve 1 Switch
      slave: 1
      address: 0
      write_type: coil
      unique_id: valve1_switch

switch:
  - platform: template
    switches:
      valve_1:
        friendly_name: "Valve 1"
        value_template: "{{ states('binary_sensor.valve_1_sensor') }}"
        turn_on:
          service: switch.turn_on
          entity_id: switch.valve_1_switch
        turn_off:
          service: switch.turn_off
          entity_id: switch.valve_1_switch   

When using:

did you follow the instructions from the readme ? and actually installed… the integration it was forked from: by sebastianfs82

since it is a pull request… to the original repo… the Documentation has still the link to the not working original…

yes, of course. In my case as soon as i switch to “Simple Modbus TCP to RTU” nothing works anymore. Not natively in homeassistant, not with these two plugins.

only the TCP mode works. But that is no problem because with my solution it just works as expected.