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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 10,168
» Latest member: 789winosakaa
» Forum threads: 4,260
» Forum posts: 21,114

Full Statistics

Online Users
There are currently 471 online users.
» 0 Member(s) | 458 Guest(s)
Amazonbot, Applebot, Baidu, Bytespider, Crawl, Google, PetalBot, bot

Latest Threads
KC868-A8 on Heat Pump for...
Forum: KC868-HxB series Smart Controller
Last Post: marktuan
2 hours ago
» Replies: 2
» Views: 615
B32M maximum voltage
Forum: DIY Project
Last Post: felixandrea
2 hours ago
» Replies: 5
» Views: 578
remember relay state
Forum: KC868-E16T
Last Post: admin
3 hours ago
» Replies: 7
» Views: 381
Bricked KC868-A16
Forum: KC868-A series and Uair Smart Controller
Last Post: admin
5 hours ago
» Replies: 5
» Views: 33
It looks like it's broken...
Forum: KinCony Server-Mini / Server-16 Raspberry Pi4 relay module
Last Post: admin
10-07-2026, 08:36 AM
» Replies: 5
» Views: 104
Bidirectional reading
Forum: N10
Last Post: admin
10-05-2026, 11:35 PM
» Replies: 1
» Views: 32
Update to latest esphome
Forum: KC868-A16
Last Post: admin
10-05-2026, 12:05 PM
» Replies: 6
» Views: 164
KC868-A16 ethernet work w...
Forum: KC868-A16
Last Post: admin
10-04-2026, 11:43 PM
» Replies: 31
» Views: 26,400
m16v2 energy meter - cali...
Forum: KC868-M16 / M1 / MB / M30
Last Post: admin
10-02-2026, 11:50 AM
» Replies: 15
» Views: 2,538
oCBot: KC868-A6/A16 as a ...
Forum: DIY Project
Last Post: oCBot
10-01-2026, 01:32 PM
» Replies: 0
» Views: 330

  [arduino code examples for CO16]-07 how to DS3231 RTC clock
Posted by: admin - 08-31-2026, 12:08 AM - Forum: CO16 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* DS3231 RTC with Arduino
*
* This program demonstrates how to use the DS3231 RTC (Real-Time Clock) module with the Arduino.
* It includes functionality to:
* - Initialize the DS3231 RTC module
* - Read the current date and time from the RTC
* - Set the RTC time based on a serial command:Command format: DYYYY-MM-DDTHH:MM:SS
*    Set date and time command example: D2024-09-19T11:50:22
*    print current date and time command: current time
*
*
* Hardware Connections:
* - SDA: GPIO 8
* - SCL: GPIO 18
*/

#include <DS3231.h>
#include <Wire.h>

String serial_cmd_rcv = ""; // Serial port receiver

typedef struct
{
  byte year;    // Last two digits of the year, library adds 2000.
  byte month;
  byte day;
  byte hour;
  byte minute;
  byte second;
} MY_DATE_STR;

MY_DATE_STR my_date_str = {0};

// Define constants for relay control
#define OPEN_RLY_DATA    26
#define OPEN_RLY_MONTH   4
#define CLOSE_RLY_DATA   2
#define CLOSE_RLY_MONTH  5

// Define pin connections
#define SDA_PIN   8
#define SCL_PIN   18

DS3231 rtc; // Create an instance of the DS3231 RTC
bool h12Flag;
bool pmFlag;
static bool bCentury = false;
static bool old_level_high = false;
static bool old_level_low = false;


/**
* @brief Print the current time from the RTC to the Serial Monitor.
*/
static void PrintfCurTime()
{
  Serial.print("Current time is: ");
  int year = rtc.getYear() + 2000;
  Serial.print(year);
  Serial.print("-");

  Serial.print(rtc.getMonth(bCentury), DEC);
  Serial.print("-");

  Serial.print(rtc.getDate(), DEC);
  Serial.print(" ");

  Serial.print(rtc.getHour(h12Flag, pmFlag), DEC);
  Serial.print(":");
  Serial.print(rtc.getMinute(), DEC);
  Serial.print(":");
  Serial.println(rtc.getSecond(), DEC);
}

/**
* @brief Process serial commands to set the RTC time.
* Command format: DYYYY-MM-DDTHH:MM:SS
*/
static void GetSerialCmd()
{
  if (Serial.available() > 0)
  {
    delay(100);
    int num_read = Serial.available();
    while (num_read--)
      serial_cmd_rcv += char(Serial.read());
  }
  else return;

  serial_cmd_rcv.trim();

  if (serial_cmd_rcv == "current time")
  {
    PrintfCurTime();
    serial_cmd_rcv = "";
    return;
  }

  Serial.print("Received length: ");
  Serial.println(serial_cmd_rcv.length());

  int indexof_d = serial_cmd_rcv.indexOf('D');
  int indexof_t = serial_cmd_rcv.indexOf('T');

  Serial.print("D index: ");
  Serial.print(indexof_d);
  Serial.print(" T index: ");
  Serial.println(indexof_t);

  if (serial_cmd_rcv.length() != 20 ||
      serial_cmd_rcv.substring(0, 1) != "D" ||
      serial_cmd_rcv.substring(11, 12) != "T") 
  {
    Serial.println(serial_cmd_rcv);
    serial_cmd_rcv = "";
    return;
  }

  Serial.println("Setting time...");

  my_date_str.year = (byte)serial_cmd_rcv.substring(3, 5).toInt();
  my_date_str.month = (byte)serial_cmd_rcv.substring(6, 8).toInt();
  my_date_str.day = (byte)serial_cmd_rcv.substring(9, 11).toInt();
  my_date_str.hour = (byte)serial_cmd_rcv.substring(12, 14).toInt();
  my_date_str.minute = (byte)serial_cmd_rcv.substring(15, 17).toInt();
  my_date_str.second = (byte)serial_cmd_rcv.substring(18).toInt();

  rtc.setYear(my_date_str.year);
  rtc.setMonth(my_date_str.month);
  rtc.setDate(my_date_str.day);
  rtc.setHour(my_date_str.hour);
  rtc.setMinute(my_date_str.minute);
  rtc.setSecond(my_date_str.second);

  serial_cmd_rcv = "";

  Serial.println("Time set.");
}

void setup() {
  // Initialize the I2C interface
  Wire.begin(SDA_PIN, SCL_PIN, 40000);
 
  // Initialize Serial communication
  Serial.begin(115200);
   
  // Set the RTC to 24-hour mode
  rtc.setClockMode(false); // 24-hour format

  // Print current time to Serial Monitor
  PrintfCurTime();

  // Clear any remaining serial data
  while (Serial.read() >= 0) {}
}

void loop() {
  // Process incoming serial commands
  GetSerialCmd();
  delay(1000); // Delay for 1 second
}
arduino ino file download: 

.zip   7-DS3231-RTC.zip (Size: 1.56 KB / Downloads: 104)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   7-DS3231-RTC.ino.merged.zip (Size: 191.08 KB / Downloads: 113)

Print this item

  [arduino code examples for CO16]-06 How to use SD Card
Posted by: admin - 08-31-2026, 12:06 AM - Forum: CO16 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* SD Card File Operations
*
* This program demonstrates basic file operations on an SD card using the ESP32.
* It includes functionality to:
* - Initialize and test the SD card
* - Read from, write to, append to, and delete files on the SD card
* - Measure file read and write performance
*
* Hardware Connections:
* - SCK: GPIO 11
* - MISO: GPIO 12
* - MOSI: GPIO 10
* - CS: GPIO 9
*/

#include "FS.h"
#include "SD.h"
#include "SPI.h"

// Pin definitions for SD card
#define SCK  11
#define MISO 12
#define MOSI 10
#define CS   9

/**
* @brief Reads the contents of a file from the SD card and prints it to the serial monitor.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to read.
*/
void readFile(fs::FS &fs, const char * path) {
  Serial.printf("Reading file: %s\n", path);

  File file = fs.open(path);
  if (!file) {
    Serial.println("Failed to open file for reading");
    return;
  }

  Serial.print("Read from file: ");
  while (file.available()) {
    Serial.print((char)file.read());
  }
  file.close();
}

/**
* @brief Writes a message to a file on the SD card.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to write.
* @param message Message to write to the file.
*/
void writeFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }
  if (file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
  file.close();
}

/**
* @brief Appends a message to a file on the SD card.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to append.
* @param message Message to append to the file.
*/
void appendFile(fs::FS &fs, const char * path, const char * message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if (!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if (file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
  file.close();
}

/**
* @brief Deletes a file from the SD card.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to delete.
*/
void deleteFile(fs::FS &fs, const char * path) {
  Serial.printf("Deleting file: %s\n", path);
  if (fs.remove(path)) {
    Serial.println("File deleted");
  } else {
    Serial.println("Delete failed");
  }
}

/**
* @brief Tests file read and write performance.
*
* @param fs File system to use (in this case, SD).
* @param path Path of the file to test.
*/
void testFileIO(fs::FS &fs, const char * path) {
  File file = fs.open(path);
  static uint8_t buf[512];
  size_t len = 0;
  uint32_t start = millis();
  uint32_t end = start;

  if (file) {
    len = file.size();
    size_t flen = len;
    start = millis();
    while (len) {
      size_t toRead = len;
      if (toRead > 512) {
        toRead = 512;
      }
      file.read(buf, toRead);
      len -= toRead;
    }
    end = millis() - start;
    Serial.printf("%u bytes read for %u ms\n", flen, end);
    file.close();
  } else {
    Serial.println("Failed to open file for reading");
  }

  file = fs.open(path, FILE_WRITE);
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }

  size_t i;
  start = millis();
  for (i = 0; i < 2048; i++) {
    file.write(buf, 512);
  }
  end = millis() - start;
  Serial.printf("%u bytes written for %u ms\n", 2048 * 512, end);
  file.close();
}

void setup() {
  // Initialize serial communication
  Serial.begin(115200);
 
  // Initialize SPI and SD card
  SPIClass spi = SPIClass(HSPI);
  spi.begin(SCK, MISO, MOSI, CS);

  if (!SD.begin(CS, spi, 80000000)) {
    Serial.println("Card Mount Failed");
    return;
  }

  uint8_t cardType = SD.cardType();

  if (cardType == CARD_NONE) {
    Serial.println("No SD card attached");
    return;
  }

  Serial.print("SD Card Type: ");
  if (cardType == CARD_MMC) {
    Serial.println("MMC");
  } else if (cardType == CARD_SD) {
    Serial.println("SDSC");
  } else if (cardType == CARD_SDHC) {
    Serial.println("SDHC");
  } else {
    Serial.println("UNKNOWN");
  }

  uint64_t cardSize = SD.cardSize() / (1024 * 1024);
  Serial.printf("SD Card Size: %lluMB\n", cardSize);
  delay(2000);

  // Perform file operations
  deleteFile(SD, "/hello.txt");
  writeFile(SD, "/hello.txt", "Hello ");
  appendFile(SD, "/hello.txt", "World!\n");
  readFile(SD, "/hello.txt");
  testFileIO(SD, "/test.txt");
  Serial.printf("Total space: %lluMB\n", SD.totalBytes() / (1024 * 1024));
  Serial.printf("Used space: %lluMB\n", SD.usedBytes() / (1024 * 1024));
}

void loop() {
  // No operation in loop
}
arduino ino file download: 

.zip   6-SD.zip (Size: 1.53 KB / Downloads: 99)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   6-SD.ino.merged.zip (Size: 221.25 KB / Downloads: 105)

Print this item

  [arduino code examples for CO16]-05 Read PT100 temperature sensor
Posted by: admin - 08-31-2026, 12:04 AM - Forum: CO16 - No Replies

Code:
#include <Adafruit_MAX31865.h>

namespace {

// CO16 MAX31865 software-SPI pins.
constexpr int kPt100Sclk = 11;
constexpr int kPt100Mosi = 10;
constexpr int kPt100Miso = 12;
constexpr int kPt100Cs = 14;

// NX3L4051PW channel select pins. S3 is fixed LOW on CO16.
constexpr int kMuxS1 = 7;
constexpr int kMuxS2 = 21;
constexpr uint8_t kPt100ChannelCount = 4;
constexpr uint32_t kMuxSettlingTimeMs = 20;

constexpr float kRtdNominalOhms = 100.0F;
constexpr float kReferenceResistorOhms = 400.0F;

Adafruit_MAX31865 pt100(kPt100Cs, kPt100Mosi, kPt100Miso, kPt100Sclk);

void selectPt100Channel(uint8_t channel) {
  const uint8_t muxAddress = channel - 1;

  // S3 is fixed LOW, so S2/S1 select PT100 channels 1-4.
  digitalWrite(kMuxS1, muxAddress & 0x01);
  digitalWrite(kMuxS2, (muxAddress >> 1) & 0x01);
  delay(kMuxSettlingTimeMs);
}

void printFault(uint8_t fault) {
  Serial.printf(" fault=0x%02X", fault);
  if (fault & MAX31865_FAULT_HIGHTHRESH) {
    Serial.print(" RTD_HIGH_THRESHOLD");
  }
  if (fault & MAX31865_FAULT_LOWTHRESH) {
    Serial.print(" RTD_LOW_THRESHOLD");
  }
  if (fault & MAX31865_FAULT_REFINLOW) {
    Serial.print(" REFIN_HIGH");
  }
  if (fault & MAX31865_FAULT_REFINHIGH) {
    Serial.print(" REFIN_LOW_OR_FORCE_OPEN");
  }
  if (fault & MAX31865_FAULT_RTDINLOW) {
    Serial.print(" RTDIN_LOW_OR_FORCE_OPEN");
  }
  if (fault & MAX31865_FAULT_OVUV) {
    Serial.print(" OVER_UNDERVOLTAGE");
  }
}

}  // namespace

void setup() {
  Serial.begin(115200);
  delay(1000);

  pinMode(kMuxS1, OUTPUT);
  pinMode(kMuxS2, OUTPUT);
  selectPt100Channel(1);

  Serial.println();
  Serial.println("KinCony CO16 four-channel PT100 example");
  Serial.printf("MUX S3=LOW S2=%d S1=%d; SPI SCLK=%d MOSI=%d MISO=%d CS=%d\n",
                kMuxS2, kMuxS1, kPt100Sclk, kPt100Mosi, kPt100Miso,
                kPt100Cs);

  pt100.begin(MAX31865_3WIRE);
  pt100.enable50Hz(true);
}

void loop() {
  for (uint8_t channel = 1; channel <= kPt100ChannelCount; ++channel) {
    selectPt100Channel(channel);

    const uint16_t raw = pt100.readRTD();
    const float resistance =
        static_cast<float>(raw) * kReferenceResistorOhms / 32768.0F;
    const float temperature = pt100.calculateTemperature(
        raw, kRtdNominalOhms, kReferenceResistorOhms);
    const uint8_t fault = pt100.readFault(MAX31865_FAULT_NONE);

    Serial.printf("CH%u raw=%u resistance=%.3f ohm temperature=%.2f C",
                  channel, raw, resistance, temperature);
    if (fault != 0) {
      printFault(fault);
      pt100.clearFault();
    } else {
      Serial.print(" fault=0x00");
    }
    Serial.println();
  }

  Serial.println();
  delay(1000);
}
arduino ino file download: 

.zip   5-PT100.zip (Size: 1.11 KB / Downloads: 104)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   5-PT100.ino.merged.zip (Size: 198.5 KB / Downloads: 103)
before run code , need install max31865 arduino library
   
   

Print this item

  [arduino code examples for CO16]-04 RS485 communication test
Posted by: admin - 08-31-2026, 12:02 AM - Forum: CO16 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* RS485 Communication Test
*
* This program is a simple test for RS485 communication using ESP32-S3.
* It will send a message over RS485 and then read incoming messages.
* The TXD pin is defined as GPIO 18 and RXD pin is defined as GPIO 8.
*/

#include <HardwareSerial.h>

// Define RS485 pins
#define RS485_RXD 38
#define RS485_TXD 39

// Create a hardware serial object
HardwareSerial rs485Serial(1);

void setup() {
  // Start serial communication for debugging
  Serial.begin(115200);
  while (!Serial);

  // Initialize RS485 Serial communication
  rs485Serial.begin(9600, SERIAL_8N1, RS485_RXD, RS485_TXD);
 
  Serial.println("RS485 Test Start");
}

void loop() {
  // Send a test message
  rs485Serial.println("Hello from KinCony!");

  // Wait for a short period
  delay(1000);

  // Check if data is available to read
  if (rs485Serial.available()) {
    String receivedMessage = "";
    while (rs485Serial.available()) {
      char c = rs485Serial.read();
      receivedMessage += c;
    }
    // Print the received message
    Serial.print("Received: ");
    Serial.println(receivedMessage);
  }

  // Wait before sending the next message
  delay(2000);
}
arduino ino file download: 

.zip   4-RS485-Test.zip (Size: 760 bytes / Downloads: 102)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   4-RS485-Test.ino.merged.zip (Size: 190.1 KB / Downloads: 86)

Print this item

  [arduino code examples for CO16]-03 Read analog input ports value
Posted by: admin - 08-31-2026, 12:00 AM - Forum: CO16 - No Replies

Code:
/*
* KinCony 16-Channel Analog Input Monitor
*
* Four ADS1115 ADC modules are used:
*
* ADS1115-1 (U35): CH1-CH4   I2C address: 0x48
* ADS1115-2 (U7):  CH5-CH8   I2C address: 0x49
* ADS1115-3 (U15): CH9-CH12  I2C address: 0x4B
* ADS1115-4 (U19): CH13-CH16 I2C address: 0x4A
*
* ESPHome equivalent configuration:
*
* gain: 4.096
* filters:
*   - lambda: 'return x <= 0.0025f ? 0.0f : x;'
*   - multiply: 5.16696
*   - clamp:
*       min_value: 0.0
*       max_value: 10.0
*
* Only channels with an input voltage greater than 0.5V
* will be printed.
*
* Copyright: Made by KinCony IoT: https://www.kincony.com
*/

#include <Wire.h>
#include <DFRobot_ADS1115.h>

// I2C pins
#define SDA_PIN 8
#define SCL_PIN 18

// ADS1115 I2C addresses
#define ADS1115_1_ADDR 0x48
#define ADS1115_2_ADDR 0x49
#define ADS1115_3_ADDR 0x4B
#define ADS1115_4_ADDR 0x4A

// ESPHome calibration multiplier
#define VOLTAGE_MULTIPLIER 5.16696f

// ESPHome zero threshold
#define ADC_ZERO_THRESHOLD 0.0025f

// Print threshold
#define PRINT_THRESHOLD 0.5f

// Maximum input voltage
#define MAX_INPUT_VOLTAGE 10.0f


// Create ADS1115 objects
DFRobot_ADS1115 ads1(&Wire);
DFRobot_ADS1115 ads2(&Wire);
DFRobot_ADS1115 ads3(&Wire);
DFRobot_ADS1115 ads4(&Wire);


/*
* Read ADS1115 channel and convert to actual input voltage.
*
* DFRobot readVoltage() returns voltage in mV.
*
* ESPHome:
*     x <= 0.0025V -> 0V
*     x * 5.16696
*     clamp 0~10V
*/
float readInputVoltage(DFRobot_ADS1115 &ads, uint8_t channel)
{
    // Read ADC voltage in mV
    uint16_t adc_mV = ads.readVoltage(channel);

    // Convert mV to V
    float adcVoltage = adc_mV / 1000.0f;

    // ESPHome lambda filter
    if (adcVoltage <= ADC_ZERO_THRESHOLD)
    {
        return 0.0f;
    }

    // ESPHome multiply filter
    float inputVoltage = adcVoltage * VOLTAGE_MULTIPLIER;

    // ESPHome clamp filter
    if (inputVoltage < 0.0f)
    {
        inputVoltage = 0.0f;
    }

    if (inputVoltage > MAX_INPUT_VOLTAGE)
    {
        inputVoltage = MAX_INPUT_VOLTAGE;
    }

    return inputVoltage;
}


/*
* Check one analog channel.
*
* If the actual input voltage is greater than 0.5V,
* print the channel number and voltage.
*/
void checkChannel(
    DFRobot_ADS1115 &ads,
    uint8_t adcChannel,
    uint8_t channelNumber)
{
    float voltage = readInputVoltage(ads, adcChannel);

    if (voltage > PRINT_THRESHOLD)
    {
        Serial.print("CH");
        Serial.print(channelNumber);
        Serial.print(": ");

        Serial.print(voltage, 2);

        Serial.println(" V");
    }
}


void setup(void)
{
    // Initialize serial communication
    Serial.begin(115200);

    // Initialize I2C
    Wire.begin(SDA_PIN, SCL_PIN);

    /*
     * ADS1115 gain = 4.096V
     *
     * This corresponds to ESPHome:
     *
     * gain: 4.096
     *
     * DFRobot library:
     * eGAIN_ONE = 4.096V
     */

    // ADS1115-1
    ads1.setAddr_ADS1115(ADS1115_1_ADDR);
    ads1.setGain(eGAIN_ONE);
    ads1.setMode(eMODE_SINGLE);
    ads1.setRate(eRATE_128);
    ads1.setOSMode(eOSMODE_SINGLE);
    ads1.init();

    // ADS1115-2
    ads2.setAddr_ADS1115(ADS1115_2_ADDR);
    ads2.setGain(eGAIN_ONE);
    ads2.setMode(eMODE_SINGLE);
    ads2.setRate(eRATE_128);
    ads2.setOSMode(eOSMODE_SINGLE);
    ads2.init();

    // ADS1115-3
    ads3.setAddr_ADS1115(ADS1115_3_ADDR);
    ads3.setGain(eGAIN_ONE);
    ads3.setMode(eMODE_SINGLE);
    ads3.setRate(eRATE_128);
    ads3.setOSMode(eOSMODE_SINGLE);
    ads3.init();

    // ADS1115-4
    ads4.setAddr_ADS1115(ADS1115_4_ADDR);
    ads4.setGain(eGAIN_ONE);
    ads4.setMode(eMODE_SINGLE);
    ads4.setRate(eRATE_128);
    ads4.setOSMode(eOSMODE_SINGLE);
    ads4.init();

    Serial.println();
    Serial.println("KinCony 16-Channel Analog Input Test");
    Serial.println("--------------------------------------");
    Serial.println("ADS1115 Gain: 4.096V");
    Serial.println("Multiplier: 5.16696");
    Serial.println("Print threshold: 0.50V");
    Serial.println();
}


void loop(void)
{
    // ADS1115-1: CH1 ~ CH4
    if (ads1.checkADS1115())
    {
        checkChannel(ads1, 0, 1);
        checkChannel(ads1, 1, 2);
        checkChannel(ads1, 2, 3);
        checkChannel(ads1, 3, 4);
    }
    else
    {
        Serial.println("ADS1115-1 (0x48) Disconnected!");
    }


    // ADS1115-2: CH5 ~ CH8
    if (ads2.checkADS1115())
    {
        checkChannel(ads2, 0, 5);
        checkChannel(ads2, 1, 6);
        checkChannel(ads2, 2, 7);
        checkChannel(ads2, 3, 8);
    }
    else
    {
        Serial.println("ADS1115-2 (0x49) Disconnected!");
    }


    // ADS1115-3: CH9 ~ CH12
    if (ads3.checkADS1115())
    {
        checkChannel(ads3, 0, 9);
        checkChannel(ads3, 1, 10);
        checkChannel(ads3, 2, 11);
        checkChannel(ads3, 3, 12);
    }
    else
    {
        Serial.println("ADS1115-3 (0x4B) Disconnected!");
    }


    // ADS1115-4: CH13 ~ CH16
    if (ads4.checkADS1115())
    {
        checkChannel(ads4, 0, 13);
        checkChannel(ads4, 1, 14);
        checkChannel(ads4, 2, 15);
        checkChannel(ads4, 3, 16);
    }
    else
    {
        Serial.println("ADS1115-4 (0x4A) Disconnected!");
    }


    // Scan every 1 second
    delay(1000);
}
arduino ino file download:

.zip   3-ads1115_adc.zip (Size: 1.68 KB / Downloads: 87)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   3-ads1115_adc.ino.merged.zip (Size: 195.04 KB / Downloads: 92)

Print this item

  [arduino code examples for CO16]-02 Read digital input ports state
Posted by: admin - 08-30-2026, 11:58 PM - Forum: CO16 - No Replies

Code:
/*
  Made by KinCony IoT: https://www.kincony.com

  Program functionality:
  This program uses an ESP32-S3 to read inputs from an XL9535 I/O expander chip
  (I2C address 0x24) via I2C. The XL9535 chip handles channels 1-16.
  The program reads the state of all these inputs and prints them in binary format
  to the serial monitor.

  Key points:
  - The I2C bus is initialized on GPIO pins 8 (SDA) and 18 (SCL) with a frequency of 40kHz.
  - The XL9535 chip reads the state of input pins for channels 1-16.
  - The state of the inputs is printed to the serial monitor in binary format every second.
  - Note: The original description mentioned three expander chips, but this implementation
    currently uses only one XL9535 (PCA9555 compatible) at address 0x24.
*/

#include <PCA95x5.h>
#include <Wire.h>

// Initialize the PCA9555 object for XL9535 chip (channels 1-16)
PCA9555 ioex1;  // XL9535 I/O expander at I2C address 0x24, handles channels 1-16

void setup() {
    // Start serial communication for debugging
    Serial.begin(115200);
    delay(2000);  // Wait for 2 seconds to ensure serial monitor is ready

    // Initialize the I2C bus with GPIO 8 as SDA and GPIO 18 as SCL, 40kHz frequency
    Wire.begin(8, 18, 40000);

    // Attach the PCA9555 device at I2C address 0x24
    ioex1.attach(Wire, 0x24);
   
    // Set polarity to original (no inversion)
    ioex1.polarity(PCA95x5::Polarity::ORIGINAL_ALL);
   
    // Configure all 16 pins as inputs
    ioex1.direction(PCA95x5::Direction::IN_ALL);
}

void loop() {
    // Read and print the state of inputs from the XL9535 (channels 1-16)
    Serial.print("1-16 input states: ");
    // Read all 16 pins and print as 16-bit binary value
    Serial.println(ioex1.read(), BIN);

    delay(1000);  // Wait for 1 second before the next reading
}
arduino ino file download:

.zip   2-digital-input.zip (Size: 1,013 bytes / Downloads: 99)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   2-digital-input.ino.merged.zip (Size: 197.84 KB / Downloads: 106)

Print this item

  [arduino code examples for CO16]-01 Turn ON/OFF relay
Posted by: admin - 08-30-2026, 11:56 PM - Forum: CO16 - No Replies

Code:
/*
* Made by KinCony IoT: https://www.kincony.com
*
* This program controls a 16-channel relay board via a PCF8575 I/O expander.
* It sequentially turns on each relay and then turns them off in a loop.
*
* Pin Definitions:
* - SDA: GPIO 8
* - SCL: GPIO 18
*
* Delay Time:
* - 200 milliseconds between switching relays
*/

#include <Wire.h>        // Include the Wire library for I2C communication
#include <PCF8575.h>     // Include the PCF8575 library to control the I/O expander

#define SDA 8           // Define the SDA pin
#define SCL 18           // Define the SCL pin
#define DELAY_TIME 200   // Define the delay time in milliseconds

// Set I2C address of the PCF8575 module
#define I2C_ADDRESS 0x22 // I2C address of the PCF8575 module

PCF8575 pcf8575_R1(I2C_ADDRESS); // Create a PCF8575 object with the specified I2C address

void setup() {
  // Initialize I2C communication
  Wire.begin(SDA, SCL); // SDA on GPIO 8, SCL on GPIO 18 (according to your board's configuration)
 
  // Initialize serial communication for debugging (optional)
  Serial.begin(115200);
  Serial.println("PCF8575 Relay Control: Starting...");

  // Initialize the PCF8575 module
  pcf8575_R1.begin();

  // Turn off all relays initially (set all pins HIGH)
  for (int i = 0; i < 16; i++) {
    pcf8575_R1.write(i, HIGH); // Set all relays to OFF (assuming HIGH means OFF for relays)
  }
}

void loop() {
  // Sequentially turn on each relay
  for (int i = 0; i < 16; i++) {
    pcf8575_R1.write(i, LOW);   // Turn on the relay at pin i (LOW means ON for the relay)
    delay(DELAY_TIME);          // Wait for DELAY_TIME milliseconds
  }

  // Sequentially turn off each relay
  for (int i = 0; i < 16; i++) {
    pcf8575_R1.write(i, HIGH);  // Turn off the relay at pin i (HIGH means OFF for the relay)
    delay(DELAY_TIME);          // Wait for DELAY_TIME milliseconds
  }
}
arduino ino file download:

.zip   1-output.zip (Size: 926 bytes / Downloads: 104)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   1-output.ino.merged.zip (Size: 197.66 KB / Downloads: 101)

Print this item

  CO16 Smart Controller ESP32 system block diagram
Posted by: admin - 08-30-2026, 11:52 PM - Forum: CO16 - No Replies

   

Print this item

  CO16 ESPHome yaml for home assistant with tuya
Posted by: admin - 08-30-2026, 11:50 PM - Forum: CO16 - No Replies

Code:
esphome:
  name: kincony-co16
  friendly_name: KinCony CO16
  name_add_mac_suffix: true
  min_version: 2026.5.3

esp32:
  variant: esp32s3
  flash_size: 16MB
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: y
      CONFIG_ESP32S3_DATA_CACHE_64KB: y
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: y
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: y
      CONFIG_SPIRAM_RODATA: y

psram:
  mode: octal
  speed: 80MHz

logger:
  hardware_uart: USB_SERIAL_JTAG

api:

ota:
  - platform: esphome

# ESPHome does not support Ethernet and Wi-Fi at the same time. Remove this
# block before adding a wifi: configuration.
ethernet:
  type: W5500
  clk_pin: GPIO1
  mosi_pin: GPIO2
  miso_pin: GPIO41
  cs_pin: GPIO42
  interrupt_pin: GPIO43
  reset_pin: GPIO44
  clock_speed: 16MHz
  interface: spi2

web_server:
  port: 80
 
external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-wifi-mcu
      ref: v1.4.0
    components:
      - nx3l4051
      - nx3l4051_max31865

  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-wifi-mcu
      ref: v1.3.1

i2c:
  sda: GPIO8
  scl: GPIO18
  frequency: 100kHz
  scan: true

pcf8574:
  - id: co16_relay_hub
    address: 0x22
    pcf8575: true

xl9535:
  - id: co16_input_hub
    address: 0x24

ads1115:
  - id: co16_adc_01_04
    address: 0x48
  - id: co16_adc_05_08
    address: 0x49
  - id: co16_adc_09_12
    address: 0x4B
  - id: co16_adc_13_16
    address: 0x4A

nx3l4051:
  - id: co16_pt100_mux
    pin_s1: GPIO7
    pin_s2: GPIO21
    pin_s3: LOW
    delay: 20ms

globals:
  - id: co16_pt100_channel
    type: uint8_t
    restore_value: false
    initial_value: "0"

uart:
  - id: uart_1    #RS485
    baud_rate: 9600
    debug:
      direction: BOTH
      dummy_receiver: true
      after:
        timeout: 10ms
    tx_pin: 16
    rx_pin: 17

  - id: tuya_mcu_uart
    tx_pin: GPIO39
    rx_pin: GPIO38
    baud_rate: 9600
   
tuya_wifi_mcu:
  # tuya mcu product id
  product_id: 8svouhd9lziyz5py
  uart_id: tuya_mcu_uart
  wifi_reset_pin: 28
  wifi_led_pin: 16

switch:
  - platform: gpio
    name: "CO16 Output 01"
    id: co16_output_01
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 0
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output1-tuya
    dp_id: 1
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_01"

  - platform: gpio
    name: "CO16 Output 02"
    id: co16_output_02
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 1
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output2-tuya
    dp_id: 2
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_02"

  - platform: gpio
    name: "CO16 Output 03"
    id: co16_output_03
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 2
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output3-tuya
    dp_id: 3
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_03"

  - platform: gpio
    name: "CO16 Output 04"
    id: co16_output_04
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 3
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output4-tuya
    dp_id: 4
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_04"

  - platform: gpio
    name: "CO16 Output 05"
    id: co16_output_05
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 4
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output5-tuya
    dp_id: 5
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_05"

  - platform: gpio
    name: "CO16 Output 06"
    id: co16_output_06
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 5
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output6-tuya
    dp_id: 6
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_06"

  - platform: gpio
    name: "CO16 Output 07"
    id: co16_output_07
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 6
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output7-tuya
    dp_id: 101
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_07"

  - platform: gpio
    name: "CO16 Output 08"
    id: co16_output_08
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 7
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output8-tuya
    dp_id: 102
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_08"

  - platform: gpio
    name: "CO16 Output 09"
    id: co16_output_09
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 8
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output9-tuya
    dp_id: 103
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_09"

  - platform: gpio
    name: "CO16 Output 10"
    id: co16_output_10
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 9
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output10-tuya
    dp_id: 104
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_10"

  - platform: gpio
    name: "CO16 Output 11"
    id: co16_output_11
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 10
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output11-tuya
    dp_id: 105
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_11"

  - platform: gpio
    name: "CO16 Output 12"
    id: co16_output_12
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 11
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output12-tuya
    dp_id: 106
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_12"

  - platform: gpio
    name: "CO16 Output 13"
    id: co16_output_13
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 12
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output13-tuya
    dp_id: 107
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_13"

  - platform: gpio
    name: "CO16 Output 14"
    id: co16_output_14
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 13
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output14-tuya
    dp_id: 108
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_14"

  - platform: gpio
    name: "CO16 Output 15"
    id: co16_output_15
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 14
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output15-tuya
    dp_id: 109
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_15"

  - platform: gpio
    name: "CO16 Output 16"
    id: co16_output_16
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 15
      mode: OUTPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-output16-tuya
    dp_id: 110
    # hide from homeassistant ui
    internal: true
    # bind other switch, sync state
    bind_switch_id: "co16_output_16"


binary_sensor:
  - platform: gpio
    name: "CO16 Input 01"
    id: co16_input_01
    pin:
      xl9535: co16_input_hub
      number: 0
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input1-tuya
    dp_id: 111
    bind_binary_sensor_id: co16_input_01
    internal: true

  - platform: gpio
    name: "CO16 Input 02"
    id: co16_input_02
    pin:
      xl9535: co16_input_hub
      number: 1
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input2-tuya
    dp_id: 112
    bind_binary_sensor_id: co16_input_02
    internal: true

  - platform: gpio
    name: "CO16 Input 03"
    id: co16_input_03
    pin:
      xl9535: co16_input_hub
      number: 2
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input3-tuya
    dp_id: 113
    bind_binary_sensor_id: co16_input_03
    internal: true

  - platform: gpio
    name: "CO16 Input 04"
    id: co16_input_04
    pin:
      xl9535: co16_input_hub
      number: 3
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input4-tuya
    dp_id: 114
    bind_binary_sensor_id: co16_input_04
    internal: true

  - platform: gpio
    name: "CO16 Input 05"
    id: co16_input_05
    pin:
      xl9535: co16_input_hub
      number: 4
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input5-tuya
    dp_id: 115
    bind_binary_sensor_id: co16_input_05
    internal: true

  - platform: gpio
    name: "CO16 Input 06"
    id: co16_input_06
    pin:
      xl9535: co16_input_hub
      number: 5
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input6-tuya
    dp_id: 116
    bind_binary_sensor_id: co16_input_06
    internal: true

  - platform: gpio
    name: "CO16 Input 07"
    id: co16_input_07
    pin:
      xl9535: co16_input_hub
      number: 6
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input7-tuya
    dp_id: 117
    bind_binary_sensor_id: co16_input_07
    internal: true

  - platform: gpio
    name: "CO16 Input 08"
    id: co16_input_08
    pin:
      xl9535: co16_input_hub
      number: 7
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input8-tuya
    dp_id: 118
    bind_binary_sensor_id: co16_input_08
    internal: true

  - platform: gpio
    name: "CO16 Input 09"
    id: co16_input_09
    pin:
      xl9535: co16_input_hub
      number: 10
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input9-tuya
    dp_id: 119
    bind_binary_sensor_id: co16_input_09
    internal: true

  - platform: gpio
    name: "CO16 Input 10"
    id: co16_input_10
    pin:
      xl9535: co16_input_hub
      number: 11
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input10-tuya
    dp_id: 120
    bind_binary_sensor_id: co16_input_10
    internal: true

  - platform: gpio
    name: "CO16 Input 11"
    id: co16_input_11
    pin:
      xl9535: co16_input_hub
      number: 12
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input11-tuya
    dp_id: 121
    bind_binary_sensor_id: co16_input_11
    internal: true

  - platform: gpio
    name: "CO16 Input 12"
    id: co16_input_12
    pin:
      xl9535: co16_input_hub
      number: 13
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input12-tuya
    dp_id: 122
    bind_binary_sensor_id: co16_input_12
    internal: true

  - platform: gpio
    name: "CO16 Input 13"
    id: co16_input_13
    pin:
      xl9535: co16_input_hub
      number: 14
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input13-tuya
    dp_id: 123
    bind_binary_sensor_id: co16_input_13
    internal: true

  - platform: gpio
    name: "CO16 Input 14"
    id: co16_input_14
    pin:
      xl9535: co16_input_hub
      number: 15
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input14-tuya
    dp_id: 124
    bind_binary_sensor_id: co16_input_14
    internal: true

  - platform: gpio
    name: "CO16 Input 15"
    id: co16_input_15
    pin:
      xl9535: co16_input_hub
      number: 16
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input15-tuya
    dp_id: 125
    bind_binary_sensor_id: co16_input_15
    internal: true

  - platform: gpio
    name: "CO16 Input 16"
    id: co16_input_16
    pin:
      xl9535: co16_input_hub
      number: 17
      mode: INPUT
      inverted: true
  - platform: tuya_wifi_mcu
    name: co16-input16-tuya
    dp_id: 126
    bind_binary_sensor_id: co16_input_16
    internal: true


sensor:
  # The default filters expose the terminal measurements as 0-10 V.
  # For a 4-20 mA channel, replace its filters with: [{multiply: 10.0}]
  # and change the unit/device class to mA/current.
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 01"
    id: co16_analog_input_01
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 02"
    id: co16_analog_input_02
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 03"
    id: co16_analog_input_03
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 04"
    id: co16_analog_input_04
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 05"
    id: co16_analog_input_05
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 06"
    id: co16_analog_input_06
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 07"
    id: co16_analog_input_07
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 08"
    id: co16_analog_input_08
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 09"
    id: co16_analog_input_09
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 10"
    id: co16_analog_input_10
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 11"
    id: co16_analog_input_11
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 12"
    id: co16_analog_input_12
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 13"
    id: co16_analog_input_13
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 14"
    id: co16_analog_input_14
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 15"
    id: co16_analog_input_15
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 16"
    id: co16_analog_input_16
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0

  - platform: nx3l4051_max31865
    id: co16_pt100_reader
    mux_id: co16_pt100_mux
    internal: true
    clk_pin: GPIO11
    mosi_pin: GPIO10
    miso_pin: GPIO12
    cs_pin: GPIO14
    reference_resistance: 400 ohm
    rtd_nominal_resistance: 100 ohm
    rtd_wires: 3
    mains_filter: 50 Hz
    update_interval: never

  - platform: template
    name: "CO16 PT100 01"
    id: co16_pt100_01
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never
  - platform: template
    name: "CO16 PT100 02"
    id: co16_pt100_02
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never
  - platform: template
    name: "CO16 PT100 03"
    id: co16_pt100_03
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never
  - platform: template
    name: "CO16 PT100 04"
    id: co16_pt100_04
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never

interval:
  - interval: 10s
    then:
      - repeat:
          count: 4
          then:
            - nx3l4051.select:
                id: co16_pt100_mux
                channel: !lambda return id(co16_pt100_channel);
            - component.update: co16_pt100_reader
            - delay: 70ms
            - lambda: |-
                const float value = id(co16_pt100_reader).state;
                switch (id(co16_pt100_channel)) {
                  case 0:
                    id(co16_pt100_01).publish_state(value);
                    break;
                  case 1:
                    id(co16_pt100_02).publish_state(value);
                    break;
                  case 2:
                    id(co16_pt100_03).publish_state(value);
                    break;
                  default:
                    id(co16_pt100_04).publish_state(value);
                    break;
                }
                id(co16_pt100_channel) = (id(co16_pt100_channel) + 1) % 4;
esphome yaml download:

.txt   CO16-HA-with-Tuya.txt (Size: 21.48 KB / Downloads: 42)

Print this item

  CO16 ESPHome yaml for home assistant without tuya
Posted by: admin - 08-30-2026, 11:47 PM - Forum: CO16 - No Replies

   

Code:
esphome:
  name: kincony-co16
  friendly_name: KinCony CO16
  name_add_mac_suffix: true
  min_version: 2026.5.3

esp32:
  variant: esp32s3
  flash_size: 16MB
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: y
      CONFIG_ESP32S3_DATA_CACHE_64KB: y
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: y
      CONFIG_SPIRAM_FETCH_INSTRUCTIONS: y
      CONFIG_SPIRAM_RODATA: y

psram:
  mode: octal
  speed: 80MHz

logger:
  hardware_uart: USB_SERIAL_JTAG

api:

ota:
  - platform: esphome

# ESPHome does not support Ethernet and Wi-Fi at the same time. Remove this
# block before adding a wifi: configuration.
ethernet:
  type: W5500
  clk_pin: GPIO1
  mosi_pin: GPIO2
  miso_pin: GPIO41
  cs_pin: GPIO42
  interrupt_pin: GPIO43
  reset_pin: GPIO44
  clock_speed: 16MHz
  interface: spi2

web_server:
  port: 80
 
external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-nx3l4051
      ref: c3b3d5fe6a23e43875dab20dce9ee517a67e95a1
    components:
      - nx3l4051
      - nx3l4051_max31865

i2c:
  sda: GPIO8
  scl: GPIO18
  frequency: 100kHz
  scan: true

pcf8574:
  - id: co16_relay_hub
    address: 0x22
    pcf8575: true

xl9535:
  - id: co16_input_hub
    address: 0x24

ads1115:
  - id: co16_adc_01_04
    address: 0x48
  - id: co16_adc_05_08
    address: 0x49
  - id: co16_adc_09_12
    address: 0x4B
  - id: co16_adc_13_16
    address: 0x4A

nx3l4051:
  - id: co16_pt100_mux
    pin_s1: GPIO7
    pin_s2: GPIO21
    pin_s3: LOW
    delay: 20ms

globals:
  - id: co16_pt100_channel
    type: uint8_t
    restore_value: false
    initial_value: "0"

switch:
  - platform: gpio
    name: "CO16 Output 01"
    id: co16_output_01
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 0
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 02"
    id: co16_output_02
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 1
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 03"
    id: co16_output_03
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 2
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 04"
    id: co16_output_04
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 3
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 05"
    id: co16_output_05
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 4
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 06"
    id: co16_output_06
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 5
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 07"
    id: co16_output_07
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 6
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 08"
    id: co16_output_08
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 7
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 09"
    id: co16_output_09
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 8
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 10"
    id: co16_output_10
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 9
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 11"
    id: co16_output_11
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 10
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 12"
    id: co16_output_12
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 11
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 13"
    id: co16_output_13
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 12
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 14"
    id: co16_output_14
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 13
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 15"
    id: co16_output_15
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 14
      mode: OUTPUT
      inverted: true
  - platform: gpio
    name: "CO16 Output 16"
    id: co16_output_16
    restore_mode: ALWAYS_OFF
    pin:
      pcf8574: co16_relay_hub
      number: 15
      mode: OUTPUT
      inverted: true

binary_sensor:
  - platform: gpio
    name: "CO16 Input 01"
    id: co16_input_01
    pin:
      xl9535: co16_input_hub
      number: 0
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 02"
    id: co16_input_02
    pin:
      xl9535: co16_input_hub
      number: 1
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 03"
    id: co16_input_03
    pin:
      xl9535: co16_input_hub
      number: 2
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 04"
    id: co16_input_04
    pin:
      xl9535: co16_input_hub
      number: 3
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 05"
    id: co16_input_05
    pin:
      xl9535: co16_input_hub
      number: 4
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 06"
    id: co16_input_06
    pin:
      xl9535: co16_input_hub
      number: 5
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 07"
    id: co16_input_07
    pin:
      xl9535: co16_input_hub
      number: 6
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 08"
    id: co16_input_08
    pin:
      xl9535: co16_input_hub
      number: 7
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 09"
    id: co16_input_09
    pin:
      xl9535: co16_input_hub
      number: 10
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 10"
    id: co16_input_10
    pin:
      xl9535: co16_input_hub
      number: 11
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 11"
    id: co16_input_11
    pin:
      xl9535: co16_input_hub
      number: 12
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 12"
    id: co16_input_12
    pin:
      xl9535: co16_input_hub
      number: 13
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 13"
    id: co16_input_13
    pin:
      xl9535: co16_input_hub
      number: 14
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 14"
    id: co16_input_14
    pin:
      xl9535: co16_input_hub
      number: 15
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 15"
    id: co16_input_15
    pin:
      xl9535: co16_input_hub
      number: 16
      mode: INPUT
      inverted: true
  - platform: gpio
    name: "CO16 Input 16"
    id: co16_input_16
    pin:
      xl9535: co16_input_hub
      number: 17
      mode: INPUT
      inverted: true

sensor:
  # The default filters expose the terminal measurements as 0-10 V.
  # For a 4-20 mA channel, replace its filters with: [{multiply: 10.0}]
  # and change the unit/device class to mA/current.
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 01"
    id: co16_analog_input_01
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 02"
    id: co16_analog_input_02
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 03"
    id: co16_analog_input_03
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_01_04
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 04"
    id: co16_analog_input_04
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 05"
    id: co16_analog_input_05
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 06"
    id: co16_analog_input_06
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 07"
    id: co16_analog_input_07
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_05_08
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 08"
    id: co16_analog_input_08
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 09"
    id: co16_analog_input_09
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 10"
    id: co16_analog_input_10
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 11"
    id: co16_analog_input_11
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_09_12
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 12"
    id: co16_analog_input_12
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A0_GND
    gain: 4.096
    name: "CO16 Analog Input 13"
    id: co16_analog_input_13
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A1_GND
    gain: 4.096
    name: "CO16 Analog Input 14"
    id: co16_analog_input_14
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A2_GND
    gain: 4.096
    name: "CO16 Analog Input 15"
    id: co16_analog_input_15
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0
  - platform: ads1115
    ads1115_id: co16_adc_13_16
    multiplexer: A3_GND
    gain: 4.096
    name: "CO16 Analog Input 16"
    id: co16_analog_input_16
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 2
    update_interval: 5s
    filters:
      - lambda: 'return x <= 0.0025f ? 0.0f : x;'
      - multiply: 5.16696
      - clamp:
          min_value: 0.0
          max_value: 10.0

  - platform: nx3l4051_max31865
    id: co16_pt100_reader
    mux_id: co16_pt100_mux
    internal: true
    clk_pin: GPIO11
    mosi_pin: GPIO10
    miso_pin: GPIO12
    cs_pin: GPIO14
    reference_resistance: 400 ohm
    rtd_nominal_resistance: 100 ohm
    rtd_wires: 3
    mains_filter: 50 Hz
    update_interval: never

  - platform: template
    name: "CO16 PT100 01"
    id: co16_pt100_01
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never
  - platform: template
    name: "CO16 PT100 02"
    id: co16_pt100_02
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never
  - platform: template
    name: "CO16 PT100 03"
    id: co16_pt100_03
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never
  - platform: template
    name: "CO16 PT100 04"
    id: co16_pt100_04
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement
    accuracy_decimals: 2
    update_interval: never

interval:
  - interval: 10s
    then:
      - repeat:
          count: 4
          then:
            - nx3l4051.select:
                id: co16_pt100_mux
                channel: !lambda return id(co16_pt100_channel);
            - component.update: co16_pt100_reader
            - delay: 70ms
            - lambda: |-
                const float value = id(co16_pt100_reader).state;
                switch (id(co16_pt100_channel)) {
                  case 0:
                    id(co16_pt100_01).publish_state(value);
                    break;
                  case 1:
                    id(co16_pt100_02).publish_state(value);
                    break;
                  case 2:
                    id(co16_pt100_03).publish_state(value);
                    break;
                  default:
                    id(co16_pt100_04).publish_state(value);
                    break;
                }
                id(co16_pt100_channel) = (id(co16_pt100_channel) + 1) % 4;
esphome yaml file download:

.txt   CO16-HA-without-Tuya.txt (Size: 17.05 KB / Downloads: 78)

Print this item