Smart Home Automation Forum

Full Version: KC868-A16 work with relay board by RS485 modbus in ESPHome
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
use KC868-A16 work with KC868-H32BS by RS485 cable via modbus.

this is a demo , i have created one switch button in ESPHome, you can create many others.

KC868-H32BS use modbus command:
01 05 00 00 FF 00  CRC turn on relay1
01 05 00 00 00 00  CRC turn off relay1

make sure your relay board as these:
ON = 0xFF00 OFF=0000

if your relay board not use by this protocol. you can also write esphome as "write_lambda" way. i have tested, "write_lambda" to create switch also work fine. just need to create ON and OFF two command.

[attachment=2234]
[attachment=2233]
yaml files for KC868-A16 work with modbus switch:
[attachment=2235]
I have a KinCony ESP32 Tuya IoT adapter module. Is there a library you would recommend to use as modbus_switch in home assistant? My aim is to use it as a gateway between home assistant and TUYA. Is it possible?
can you draw a photo, what do you want to do? no any relay controller connected?
There are 32 buttons on the KinCony ESP32 Tuya IoT adapter module that we can control from TUYA. I want to introduce them as Home assistanta modbus_switch. It will be as if the module has a virtual relay. When I open switch_1 from Modbus, I will see that it is opened from the TUYA application. The KinCony ESP32 Tuya IoT adapter module already has rs485 hardware. But I am trying to add the modbus code.
do you want to use ESP32 tuya adapter connect to your own relay board by modbus protocol?
(04-23-2023, 02:51 AM)admin Wrote: [ -> ]do you want to use ESP32 tuya adapter connect to your own relay board by modbus protocol?

YES...!
ok, you need to modify ESP32 arduino code, replace KinCony's protocol with your board's.
Yes, I will modify the ESP32 Tuya IoT adapter module software. I changed the program before with your help. https://www.kincony.com/forum/showthread...light=TUYA
I am using RS485 in that article. But now I am trying Modbus protocol. In the Arduino IDE. I've used several modbus libraries. I couldn't decide which one is the best. That's why I asked your suggestion. Thanks
this need test, debug with your board.
would this be a correct config with 4 A16 boards?

uart:
id: mbus
tx_pin: GPIO13
rx_pin: GPIO16
baud_rate: 9600

modbus:
id: modbus1
uart_id: mbus
send_wait_time: 200ms

modbus_controller_board2:
- id: a16-Board2
address: 1
modbus_id: modbus1
update_interval: 1s

modbus_controller_board3:
- id: a16-Board3
address: 2
modbus_id: modbus1
update_interval: 1s

modbus_controller_board4:
- id: a16-Board4
address: 3
modbus_id: modbus1
update_interval: 1s

switch:
- platform: modbus_controller_board2
name: 'modbus_board2-switch1'
address: 0 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1c
....


switch:
- platform: modbus_controller_board2
name: 'modbus_board2-switch16'
address: 15 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1

#Board 3

switch:
- platform: modbus_controller_board3
name: 'modbus_board3-switch1'
address: 0 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1c
....


switch:
- platform: modbus_controller_board3
name: 'modbus_board3-switch16'
address: 15 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1

#Board 4

switch:
- platform: modbus_controller_board4
name: 'modbus_board4-switch1'
address: 0 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1c
....


switch:
- platform: modbus_controller_board4
name: 'modbus_board4-switch16'
address: 15 # 0:relay1 1:relay2 ......
register_type: coil
bitmask: 1
Pages: 1 2