32 channel ethernet relay module – KinCony KC868-H32

Hi guys! I bought a relay module from Kincony. On board he has 32 outnput channels and 6 intput channels. The cost of one channel is approximately 2$.
But I have questions about its integration into HA.
On a local area network, it works on tcp socket.
This JS code works.

var net = require(‘net’);

var client = new net.Socket();
client.connect(4196, ‘192.168.2.108’, function() {
console.log(‘Connected’);
client.write(‘RELAY-SET-1,4,0’);
});

client.on(‘data’, function(data) {
console.log('Received: ’ + data);
client.destroy(); // kill client after server’s response
});

client.on(‘close’, function() {
console.log(‘Connection closed’);
});

Please help integrate this module into HA.
I think it should be -
switch:

  • platform: tcp
2 Likes

you great !! I just imagined that I can use it or not.

but you challenge now, work with Home Assistant

I think you can challenge ESPHOME if you can.

this system is ESP based integrated system.

I wish you can make it work in some day.

Good Luck !!

The manufacturer has a voice control module based on ESP8266. It is based on firmware from sinric. You can flash it on ESPHome. But this is a workaround. It makes sense to use the built-in support TCP Socket.

The following code works:

sensor:

  • platform: command_line
    sensors:
    relay01:
    device_class: light
    command: ‘echo -n RELAY-STATE-1,1 | nc IP PORT’
    relay02:
    device_class: light
    command: ‘echo -n RELAY-STATE-1,2 | nc IP PORT’

switch:

  • platform: command_line
    switches:
    relay01:
    command_on: ‘echo -n RELAY-SET-1,1,1 | nc IP PORT’
    command_off: ‘echo -n RELAY-SET-1,1,0 | nc IP PORT’
    value_template: ‘{{ “1,OK” in value }}’
    friendly_name: Kitchen
    relay02:
    command_on: ‘echo -n RELAY-SET-1,2,1 | nc IP PORT’
    command_off: ‘echo -n RELAY-SET-1,2,0 | nc IP PORT’
    value_template: ‘{{ “1,OK” in value }}’
    friendly_name: Hall

And so all 32 relays
It remains only to correct the error when all the relays are turned on at the same time (only one relay is turned on).

If anyone is interested, all the commands are described here.

This is not complete code. There is another question with feedback and initialization.
Colleagues, please help to solve this problem.

The relay unit in the local network can be controlled in three ways, manually using the buttons on the keyboard, the command line and via HA.

With this code, the first two control methods do not change the status of the icon in HA.

Through the command line, you can send commands through the utility NetCat.
$ echo -n RELAY-SET-1,1,1 | nc IP PORT

Commands are described here.

Where did you manage to buy one of these ?

Couldn’t find prices or a ‘shop’ on the KinCony site and no eBay or Amazon presence - maybe GearBest or Ali ?

Found on Ali and Amazon.com

They will soon be available for sale module RS232 combining 3 devices at the same time.

Now, without it, you can connect only one device on the RS232 bus to the relay module.

This is their store in which a lot of useful for home automation. Do not consider this an advertisement.

https://www.aliexpress.com/store/5021175?spm=a2g0o.detail.1000061.1.24bb641bd4RCjG

KC868-H32 you can write code control relay or read input sensor from Ethernet or RS232 port. The voice module based on ESP8266, you can write code download to ESP8266, then send command by RS232 port.it’s very useful. some fans have connect with many kinds of smart home system:)

Welcome to the forum representative of the manufacturer of equipment !!!
The issue of equipment integration has remained open.
Help the community with the module integrating your equipment into the system Home Assistant.
Here you see the enormous potential of this market. There is also a community for Reddit and a russian-speaking community.
Help enthusiasts with integration and they will help you with sales.
The best solution would be to write an integration module. But as a workaround, the correct command code for feedback work.

1 Like

Hello. Now what’s problem with your when you integrating the smart relay module?
There are two way to integrating KC868 Smart Controller:
1.LAN 2.WAN.

1: LAN is work in local network, not need internet. You can send command to controller directly by network.

2: WAN is use KinCony’s cloud server. You can send command to KinCony’s cloud server by account user name and password to get information from server and send command turn ON/OFF relays.

If you want to use in LAN, also have two way:

A.Controller as a server, your PC or Phone or arduino or Raspberry PI or any device as a client use socket connect with controller by IP and Port.

B.Controller as a client, you can use your own cloud server or one computer as a server, set the server IP and Port for controller, then after controller power on, it will auto connect with your own server by socket. When socket communication connection is established, you can send command to turn ON/OFF relays.

Controller use for server or client , it can set by you on network tool. So you can use any third party integration to KinCony’s controller.Now we are developing the wireless controller(RF+ZigBee), it also open protocol, support write code to send command, I have take some video uploaded to KinCony’s youtube channel.

I am trying to find commands to control this module.
So far I only managed to send commands. It looks like this:

switch:

platform: command_line
switches:
relay01:
command_on: ‘echo -n RELAY-SET-1,1,1 | nc IP PORT’
command_off: ‘echo -n RELAY-SET-1,1,0 | nc IP PORT’
value_template: ‘{{ “1,OK” in value }}’
friendly_name: Kitchen
relay02:
command_on: ‘echo -n RELAY-SET-1,2,1 | nc IP PORT’
command_off: ‘echo -n RELAY-SET-1,2,0 | nc IP PORT’
value_template: ‘{{ “1,OK” in value }}’
friendly_name: Hall
…

Now I have a question in feedback. If I press a button on the keyboard or send a command through the command line, the HA controller does not see the relay status.

1 Like

Because you have not send the Initialization commmand. When controller power on , you need send :

1
Send: RELAY-SCAN_DEVICE-NOW
Return: RELAY-SCAN_DEVICE-CHANNEL_8/CHANNEL_32, OK/ERROR

2
Send: RELAY-TEST-NOW
Return: HOST-TEST-START

When you received HOST-TEST-START, then you send all command, all command will have feedback.

If you think sending initialization command is too troublesome, OK, you can send all command use 255 for first byte data instead of 1.

such as RELAY-SET-255,1,1 Turn ON relay1

such as RELAY-SET-255,1,0 Turn OFF relay1

such as RELAY-SET-255,2,1 Turn ON relay2

such as RELAY-SET-255,2,0 Turn OFF relay2

always use 255 for first byte, then you not need to send RELAY-SCAN_DEVICE-NOW and RELAY-TEST-NOW for controller Initialization.

1 Like

Now , we have write the new fireware that when press keyboard’s key , it will have feedback that which key number have pressed. I have a video, i think that is you needed. But i don’t know how to upload the video or images to this forum.

1 Like

Here you can place links to your video tutorials.

In this topic, a colleague solves a similar problem. But with a different module.

This VB demo tool for development control relay, you can see the command how to send and it’s feedback.

I want to figure out how to apply this knowledge to the Home Assistant.

Your means: Google home assistant?