Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 9,626
» Latest member: jack1620
» Forum threads: 4,194
» Forum posts: 20,841

Full Statistics

Online Users
There are currently 24 online users.
» 0 Member(s) | 12 Guest(s)
Amazonbot, PetalBot, Semrush, bot

Latest Threads
KC868-AGv3
Forum: Getting Started with ESPHome and Home Assistant
Last Post: admin
1 hour ago
» Replies: 3
» Views: 12
[arduino code examples fo...
Forum: KC868-A32/A32 Pro
Last Post: huanmarie
Yesterday, 07:09 AM
» Replies: 2
» Views: 1,572
KC868-H32B V5.08 firmware
Forum: News
Last Post: meoowu77
08-18-2026, 11:46 AM
» Replies: 24
» Views: 8,296
KinCony B2 Smart Controll...
Forum: News
Last Post: admin
08-17-2026, 01:07 PM
» Replies: 0
» Views: 28
KC868-A8v3 PCB layout CAD...
Forum: Schematic & diagram & Dimensions of KinCony PCB layout CAD file
Last Post: admin
08-17-2026, 08:44 AM
» Replies: 0
» Views: 31
CT Clamp Compatibility
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
08-16-2026, 11:08 PM
» Replies: 12
» Views: 1,896
N60 Sensor channel label
Forum: N60
Last Post: marekd1
08-14-2026, 09:14 PM
» Replies: 18
» Views: 2,346
solar production and cons...
Forum: N30
Last Post: admin
08-14-2026, 01:46 AM
» Replies: 3
» Views: 81
Current direction detecti...
Forum: N30
Last Post: admin
08-14-2026, 01:44 AM
» Replies: 3
» Views: 82
MQTT Discovery: missing s...
Forum: N30
Last Post: admin
08-13-2026, 02:48 PM
» Replies: 1
» Views: 50

  how to control 16 relay using Python code
Posted by: admin - 10-15-2024, 12:16 AM - Forum: KinCony Server-Mini / Server-16 Raspberry Pi4 relay module - No Replies

Here’s a Python code that runs on Ubuntu and controls 16 relays connected to MCP23017 via I2C. This code uses the smbus2 library, so make sure to install it first (pip install smbus2).

Code:
import smbus2
import time

# MCP23017 Register definitions
IODIRA = 0x00  # Direction register for Port A
IODIRB = 0x01  # Direction register for Port B
OLATA = 0x14   # Output latch register for Port A
OLATB = 0x15   # Output latch register for Port B

# I2C Device Address
MCP23017_ADDRESS = 0x22

# Initialize I2C bus
bus = smbus2.SMBus(1)  # Raspberry Pi CM4 typically uses I2C bus 1

def setup_mcp23017():
    # Set Port A and Port B to output mode
    bus.write_byte_data(MCP23017_ADDRESS, IODIRA, 0x00)  # Set Port A to output
    bus.write_byte_data(MCP23017_ADDRESS, IODIRB, 0x00)  # Set Port B to output

    # Turn off all relays initially
    bus.write_byte_data(MCP23017_ADDRESS, OLATA, 0x00)  # Turn off all relays on Port A
    bus.write_byte_data(MCP23017_ADDRESS, OLATB, 0x00)  # Turn off all relays on Port B

def set_relay(relay_num, state):
    """
    Controls a specific relay
    relay_num: 1-16, corresponding to the 16 relays
    state: 1 to turn on, 0 to turn off
    """
    if relay_num < 1 or relay_num > 16:
        raise ValueError("Relay number must be between 1 and 16")

    if relay_num <= 8:
        # Control relays 1-8 on Port A
        current_state = bus.read_byte_data(MCP23017_ADDRESS, OLATA)
        if state == 1:
            current_state |= (1 << (relay_num - 1))  # Turn on the relay
        else:
            current_state &= ~(1 << (relay_num - 1))  # Turn off the relay
        bus.write_byte_data(MCP23017_ADDRESS, OLATA, current_state)
    else:
        # Control relays 9-16 on Port B
        relay_num -= 8
        current_state = bus.read_byte_data(MCP23017_ADDRESS, OLATB)
        if state == 1:
            current_state |= (1 << (relay_num - 1))  # Turn on the relay
        else:
            current_state &= ~(1 << (relay_num - 1))  # Turn off the relay
        bus.write_byte_data(MCP23017_ADDRESS, OLATB, current_state)

def test_relays():
    # Sequentially turn on and off each relay with a 1-second delay
    for i in range(1, 17):
        print(f"Turning on relay {i}")
        set_relay(i, 1)
        time.sleep(1)
        print(f"Turning off relay {i}")
        set_relay(i, 0)
        time.sleep(1)

if __name__ == "__main__":
    setup_mcp23017()
    test_relays()  # Test relays
Before running the script, install the smbus2 library:
pip install smbus2

Print this item

  Server 16 Raspberry Specs
Posted by: LandOfMosfet - 10-14-2024, 08:18 PM - Forum: KinCony Server-Mini / Server-16 Raspberry Pi4 relay module - Replies (3)

I have trouble finding the specifications for this unit.

Just basic stuff like:

What is the DC voltage and current requirements?
Voltage rating for digital input

I have the unit in front of me but before I get started I would like to have all the

Thanks!

Print this item

  "KCS" v2.2.5 firmware BIN file download
Posted by: admin - 10-13-2024, 11:12 AM - Forum: "KCS" v2 firmware system - Replies (6)

Here is "KCS" firmware for KinCony KC868-A series (ESP32) board.
How to download and use, online guide: https://www.kincony.com/esp32-kcsv2-firmware.html

v2.2.5 improment:
1. fixed bug: "INPUT" webpage have error items listed in "INTERLOCK GROUP" and OUTPUT count error.



Attached Files
.zip   KCS_KC868_A32M_V2.2.5.zip (Size: 794.81 KB / Downloads: 746)
.zip   KCS_KC868_A64_V2.2.5.zip (Size: 776.69 KB / Downloads: 709)
.zip   KCS_KC868_A128_V2.2.5.zip (Size: 776.58 KB / Downloads: 747)
.zip   KCS_KC868_AG_V2.2.5.zip (Size: 755.25 KB / Downloads: 668)
.zip   KCS_KC868_AI_V2.2.5.zip (Size: 779.44 KB / Downloads: 688)
.zip   KCS_KC868_AIO_V2.2.5.zip (Size: 796.55 KB / Downloads: 711)
.zip   KCS_KC868_AK_V2.2.5.zip (Size: 757.94 KB / Downloads: 705)
.zip   KCS_KC868_AM_V2.2.5.zip (Size: 772.41 KB / Downloads: 743)
.zip   KCS_KC868_AP_V2.2.5.zip (Size: 774.76 KB / Downloads: 713)
.zip   KCS_KC868_ASR_V2.2.5.zip (Size: 751.99 KB / Downloads: 651)
.zip   KCS_KC868_E16S_V2.2.5.zip (Size: 781.16 KB / Downloads: 696)
.zip   KCS_KC868_UAIR_V2.2.5.zip (Size: 758.66 KB / Downloads: 723)
.zip   KCS_KC868_A2_V2.2.5.zip (Size: 785.06 KB / Downloads: 767)
.zip   KCS_KC868_A4_V2.2.5.zip (Size: 772.34 KB / Downloads: 766)
.zip   KCS_KC868_A4S_V2.2.5.zip (Size: 795.99 KB / Downloads: 711)
.zip   KCS_KC868_A6_V2.2.5.zip (Size: 771.04 KB / Downloads: 743)
.zip   KCS_KC868_A8_V2.2.5.zip (Size: 779.1 KB / Downloads: 712)
.zip   KCS_KC868_A8M_V2.2.5.zip (Size: 795.66 KB / Downloads: 698)
.zip   KCS_KC868_A8S_V2.2.5.zip (Size: 797.1 KB / Downloads: 744)
.zip   KCS_KC868_A16_V2.2.5.zip (Size: 786.38 KB / Downloads: 828)
.zip   KCS_KC868_A16S_V2.2.5.zip (Size: 797.22 KB / Downloads: 728)
.zip   KCS_KC868_A32_V2.2.5.zip (Size: 776.62 KB / Downloads: 684)
Print this item

Information Retain Switch status ESPHome after reboot and update / Ethernet setup
Posted by: S.Krans - 10-13-2024, 10:15 AM - Forum: Getting Started with ESPHome and Home Assistant - Replies (5)

Hi  

if i update the boards A64 / A128 the outputs does not retain their status so if i have switch-1 on and reboot the switch-1 goes off




i run ESPHome true Home Assistant and run the automations true node-red is there a possibility to have it retain the previous state before reboot or update



Also i want to use my ethernet but it wont connect 


Code:
esphome:
  name: kincony-kc868-a64-rk
  friendly_name: Kincony KC868-A64-RK

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "xxxx"

ota:
  password: "xxx"
  platform: esphome

#wifi:
#  ssid: !secret wifi_ssid
#  password: !secret wifi_password

#  # Enable fallback hotspot (captive portal) in case wifi connection fails
#  ap:
#    ssid: "Kincony-Kc868-A64-Rk"
#    password: !secret wifi_ap

#captive_portal:




# Example configuration entry
i2c:
  - id: bus_a
    sda: 5
    scl: 16
    scan: true
    frequency: 400kHz
  - id: bus_b
    sda: 15
    scl: 4
    scan: true
    frequency: 400kHz
   

# Example configuration entry
ethernet:
  type: LAN8720
  mdc_pin: GPIO23
  mdio_pin: GPIO18
  clk_mode: GPIO17_OUT
  phy_addr: 0

  # Optional manual IP
  manual_ip:
    static_ip: 20.20.20.192
    gateway: 20.20.20.1
    subnet: 255.255.255.0



Thanks in advance
Sijmen

Print this item

Question Ghost trigger
Posted by: kbo - 10-12-2024, 10:40 AM - Forum: KC868-A64 - Replies (4)

Hi,

I have implemented a kc-868-a64 in my home. It works great. It is integrated with Home Assistant to do some automation but the kc-868-a64 works on itself (see config below)

But I have a problem. Sometime when a push button is pressed, the configured light goes on BUT an other, not configured light sometimes also goes on.
I have this for some push buttons, not all. 

I tried to troubleshoot it but I can't find the issue.
Is there any way to troubleshoot this issue or is this a known issue ?

I have impulse relays so most of the outputs will turn off again.

My ESP HOME config is attached (I have redacted some fields)



Attached Files
.txt   a64.txt (Size: 37.25 KB / Downloads: 499)
Print this item

Photo rs485 port with kc868-a16s.
Posted by: Alfred - 10-11-2024, 10:16 AM - Forum: KC868-A16S - Replies (3)

i want to receive 16 bytes data through rs485 port with kc868-a16s.
but the received value is strange.
please le me know what should i check.


#define A16S_RS485_RX  32
#define A16S_RS485_TX  33

void setup() {
  Serial.begin(115200);
  Serial2.begin(19200,SERIAL_8N1,A16S_RS485_RX,A16S_RS485_TX); //A16S
  Serial.println("A16S RS485 OK");
}
void loop() {
  if (Serial2.available() > 0) {
    Serial.print("rs485 received value : ");
    Serial.println(Serial2.read());         
  }
  delay(1000);
}


18:57:15.956 -> rs485 received value : 1
18:57:16.936 -> rs485 received value : 134
18:57:17.966 -> rs485 received value : 160
18:57:19.011 -> rs485 received value : 255
18:57:19.932 -> rs485 received value : 255
18:57:20.964 -> rs485 received value : 255
18:57:21.944 -> rs485 received value : 240
18:57:22.973 -> rs485 received value : 0
18:57:23.950 -> rs485 received value : 0
18:57:24.938 -> rs485 received value : 0
18:57:25.967 -> rs485 received value : 30
18:57:26.948 -> rs485 received value : 165




sending data attached.



Attached Files Thumbnail(s)
   
Print this item

Information How to Add an Extra Module for SD Card on the KC868-A6 Board?
Posted by: iagomendes - 10-10-2024, 09:48 PM - Forum: KC868-A6 - Replies (1)

I'm looking for information on how to add an extra module for an SD card to my KC868-A6 board. What are the necessary steps to connect the module and program it properly? Is there any specific code I should use to ensure that data recording works correctly? I appreciate any guidance or resources that can assist me in this process.

Print this item

  KC868-AI - input as output HomeAssistant
Posted by: fbuffolo - 10-10-2024, 12:39 PM - Forum: KC868-AI - Replies (1)

Good morning,

in order to upgrade my home allarm system, I want to buy a KC868-AI. I have a question: I read that the dry contacts inputs can work as output with a KCS firmware; but can I use the input ad output also in Home Assistant?

I need one input as output in order to turn on the siren when one input is in allarm mode.

Thanks in advance.
Fausto

Print this item

  [Arduino source code for KC868-A2]-05 RS485 modbus temperature humidity sensor
Posted by: admin - 10-09-2024, 07:44 AM - Forum: KC868-A2 - No Replies

Code:
/*
  RS485 Modbus Temperature and Humidity Sensor Reader
  Made by KinCony: https://www.kincony.com
 
  This program reads temperature and humidity data from a Modbus RS485 sensor
  and prints the values via the Serial monitor.

  Hardware configuration:
  - RS485 communication using GPIO TX (32) and RX (35)
  - Modbus RTU protocol
  - Temperature and humidity values are stored in separate registers

  You must install the ModbusMaster library in Arduino IDE.
*/

#include <ModbusMaster.h>  // Include the ModbusMaster library for Modbus communication

// Define GPIO pins for RS485 communication (TX and RX)
#define TXD_PIN 32  // Transmit pin for RS485
#define RXD_PIN 35  // Receive pin for RS485

// Define the Modbus slave ID (this should match the sensor's address)
#define SLAVE_ID 1

// Create a ModbusMaster object to handle Modbus communication
ModbusMaster node;

/*
  This function is called before starting a Modbus transmission.
  If your hardware needs control of RS485 DE/RE pins, configure them here.
*/
void preTransmission()
{
  // Optional: Control DE/RE pins for RS485 if necessary
}

/*
  This function is called after completing a Modbus transmission.
  If your hardware needs to reset DE/RE pins, configure them here.
*/
void postTransmission()
{
  // Optional: Control DE/RE pins for RS485 if necessary
}

void setup()
{
  // Start the Serial communication for debugging at 9600 baud rate
  Serial.begin(9600);
 
  // Start Serial2 for RS485 communication using GPIO 32 (TX) and GPIO 35 (RX) at 9600 baud rate
  Serial2.begin(9600, SERIAL_8N1, RXD_PIN, TXD_PIN);

  // Initialize the Modbus communication with the slave ID and associate it with Serial2
  node.begin(SLAVE_ID, Serial2);

  // Set the pre- and post-transmission handlers for controlling RS485 hardware if needed
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);

  // Print an initial message to Serial monitor
  Serial.println("RS485 Modbus Sensor Example - Reading Temperature and Humidity");
}

void loop()
{
  uint8_t result;  // Variable to store the result of Modbus operations
  uint16_t data[2];  // Array to store the raw temperature and humidity data from the sensor

  // Read two input registers starting from address 0x0000, where temperature and humidity are stored
  result = node.readInputRegisters(0x0000, 2);  // Read 2 registers (temperature and humidity)

  // Check if the read operation was successful
  if (result == node.ku8MBSuccess)
  {
    // Retrieve raw temperature and humidity data from Modbus response buffer
    uint16_t temperatureRaw = node.getResponseBuffer(0);  // Temperature is in the first register
    uint16_t humidityRaw = node.getResponseBuffer(1);     // Humidity is in the second register

    // Parse temperature value
    float temperature;
    if (temperatureRaw < 10000)  // Check if the value represents a positive temperature
      temperature = temperatureRaw * 0.1;  // Positive temperature
    else
      temperature = -1 * (temperatureRaw - 10000) * 0.1;  // Negative temperature

    // Parse humidity value (always positive)
    float humidity = humidityRaw * 0.1;

    // Print the parsed temperature value to the Serial monitor
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" °C");

    // Print the parsed humidity value to the Serial monitor
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %RH");
  }
  else
  {
    // If the read operation failed, print the error code to the Serial monitor
    Serial.print("Failed to read from sensor, error: ");
    Serial.println(result);
  }

  // Wait for 5 seconds before reading the sensor again
  delay(5000);
}
   
   
arduino ino file download:
.zip   rs485-sensor.zip (Size: 1.47 KB / Downloads: 769)
BIN file (you can use esp32 download tool download to ESP32 with address 0x0 then directly to use) download:
.zip   rs485-sensor.ino.merged.zip (Size: 172.69 KB / Downloads: 756)

Print this item

  B16M vS A16
Posted by: admin - 10-08-2024, 11:38 AM - Forum: KC868-A16 - No Replies

   

Print this item