• sales

    +86-0755-88291180

Home Assistant Modbus RTU 16-Channel Industrial Relay Module

2024-03-10 14:20:43 Ask

Hello. I bought a modbus rtu relay 16ch. How do I set it up correctly in the Home Assistant program? I can't set up work in modbus. Do you have any instructions? Sincerely, Anton

Home Assistant Modbus RTU 16-Channel Industrial Relay Module
16answers
SpotPearUser4
Answer time:
2024-03-10 14:22:33

】For reference, the wiki includes the modbus control protocol and driver routines

https://www.spotpear.com/index/study/detail/id/1085.html-》Development Protocol

https://files.waveshare.com/upload/f/f0/Modbus_RTU_Relay_16CH_Code.zip

】If you have a USB to RS485 module on hand, you can directly connect it to a computer to test the sending and receiving of Modbus commands to control the relay. The operation reference is as follows:

https://www.spotpear.com/index/study/detail/id/1085.html-》  Hardware Test

】If it still cannot work properly, you can check whether the power supply is normal, whether the module's status indicator light and STA are flashing normally, and whether the RXD and TXD indicator lights have corresponding changes when RS485 is normal?

】The problem still cannot be solved. Please provide specific physical hardware connections, actual running software environment and test code, as well as operation videos, etc., so that we can assist in troubleshooting the problem

Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:23:25

This device works perfectly with your program "main.py ". But how to set it up correctly in the "Home Assistant" program?

I am trying to get data on the current status of each relay. Here is a sample code in the Home Assistant:

modbus:
- name: hub1
 type: serial
 port: /dev/ttyS0
 baudrate: 9600
 bytesize: 8
 method: rtu
 parity: N
 stopbits: 2
 
binary_sensors:
- name: rele0_state
 address: 0
 device_class: plug
 input_type: coil
 slave: 1
 slave_count: 15
 unique_id: rele_WSH_sens_0

The code is sent:01 01 00 00 00 10 3D C6 and the correct relay status code 0x1 0x1 0x2 0x0 0x0 0xb9 0xfc is received, but only once. Then the responses no longer come and the relay status displayed as "unavailable".

I work with Raspberry Pi 4B 8Gb via RS485 CAN HAT card.

Like0

report

SpotPearUser4
Answer time:
2024-03-10 14:23:51

What exactly does the "Home Assistant" program refer to?

If it is third-party source code, it requires secondary development and integration. Or ask if there is any relevant open source code and usage instructions,

and also how you operates and what are the related errors.

If it is commonly used, we can arrange for R&D to do some compatibility adaptation.

Like0

report

SpotPearUser4
Answer time:
2024-03-10 14:24:29

The stop position of the arrow is set to 1 by default; If you has not reset the stop position, they can modify it to 1 and try again

Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:27:55

Thank you so much for trying to help.

Home Assistant is the most famous program for managing a smart home system.

Here is their website:

https://www.home-assistant.io

Stopbits 1 or 2 has no effect

A-A and B-B and Gnd are connected correctly.

Maybe the CAN HAT board has some secret settings that affect modbus operation?

I am attaching photos of my devices and logs of modbus in Home Assistant operation.

Like0

report

SpotPearUser4
Answer time:
2024-03-10 14:29:19

Our testing on home assistant is normal, and the detailed configuration is as follows:

You Can try to disconnect the 120R resistor and try it out to see if there is any connection

Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:29:35

It didn't help me, anyway, only six bytes come in response instead of seven.

After switching on the relay, the switch becomes unavailable, and then it is displayed off, although the relay is on.

I'm attaching a video clip

Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:29:46

Hello.

Can't you help me anymore?

Turning on a resistor on the board or connecting an additional 100 or 120 ohm resistor at the end of the line does not affect anything.

Why does the correct answer come only twice? Do you always receive 7 bytes without errors?

Maybe except for "enable_uart=1" in config.txt Is there anything else you need to add?


Like0

report

SpotPearUser4
Answer time:
2024-03-10 14:30:00

Can you provide an operation video? Please send it for review. The hardware should be fine, and the Raspberry Pi OS you're using shouldn't have any issues. We've also tested with Home Assistant without any problems. If it still doesn't work, I'll see if I can organize my operations into a tutorial for you to refer to and try again.

Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:30:14

Hello.

I am sending a video of my system's operation.

Like0

report

SpotPearUser4
Answer time:
2024-03-10 14:31:03

Got your tested video

I recommend to Connect an additional USB to RS485 module in parallel with the RS485 interface, so as to synchronize the transmission and viewing of instructions on the homeassistant

Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:31:23

Thanks a lot for the hints.

But, when using a USB converter, using the CAN HAT board makes no sense. I tried to do without USB.

Related questions:

1) Does your circuit without a USB converter also work incorrectly?

2) Which USBto485 converter do you recommend using?

Like0

report

SpotPearUser4
Answer time:
2024-03-10 14:32:05

There should be no problem with his video configuration, it should be caused by unstable communication.

The sending character is normal, but the first character was lost during reception.
It is possible that this 120R resistor is short circuited.

Try turning it to the OFF end, but if the wire distance is too short, connecting to 120R will actually affect communication.

Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:32:22

The loss of the first character in the response always occurs after the third request. This is clearly a hardware error.  Switching on, off, and even adding an additional resistor does not affect anything. Maybe it's just that the Can Hat board is faulty? Maybe I'm trying in vain to set up the correct operation of the system? Maybe I should just replace the board with a new one?

You did not answer two of my questions in the previous letter.


Like0

report

SpotPearUser4
Answer time:
2024-03-10 14:33:14

】Yes, using USB TO RS485 is just for the convenience of synchronously viewing and debugging hardware,

as well as synchronously observing the transmission and reception of modbus commands

】USB TO RS485:   https://www.spotpear.com/index.php/index/product/detail/id/404.html

】  Our actual testing environment and records here:

Using Modbus RTU Relay 16CH with Homeassistant:

https://note.youdao.com/s/XgKRpRdi

】Tested video:

https://files.waveshare.com/wiki/Modbus%20RTU%20Relay/Modbus-Relay-Homeassistant-Test-Video.mp4


Like0

report

SpotPearGuest7a0b1
Answer time:
2024-03-10 14:33:43

Hello.

Thank you so much for all your help.

After upgrading Core to version 2024.3, everything started working fine. There are no erroneous answers, 7 bytes always arrive. All the switches are working, nothing freezes. It was just a mistake in the Home Assistant. Your equipment is working perfectly.

Like0

report

Price: $39.8
Part Number: Modbus-RTU-Relay-16CH
Brand: Spotpear