Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Custom ESPHome firmware and Tuya integration
#31
that need to use tuya license.
Reply
#32
(10-13-2025, 10:18 AM)admin Wrote: that need to use tuya license.

I have license for KC868-A6 
I use example in  GitHub - hzkincony/esphome-tuya-iot 
change   ref: v1.2.0 to  ref: v1.2.1
external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-iot
      ref: v1.2.1


and get error in 

src/esphome/components/tuya_iot/tuya_iot_component.cpp: In member function 'virtual void esphome::tuya_iot::TuyaIotComponent::update()':
src/esphome/components/tuya_iot/tuya_iot_component.cpp:292:19: error: 'esp_mqtt_client_config_t' {aka 'struct esp_mqtt_client_config_t'} has no member named 'username'
292 | mqtt_cfg_.username = username;


my mqtt correct
mqtt:
  broker: !secret mqtt_host
  username: !secret mqtt_username
  password: !secret mqtt_password
  id: mqtt_client
 
Reply
#33
есть какие-то идеи, как исправить ошибку?
Reply
#34
post your yaml file at here.
Reply
#35
(02-20-2026, 02:10 AM)admin Wrote: post your yaml file at here.

Code:
# Basic Config
esphome:
  name: kc868-a6-test
  friendly_name: KC868_A6_Test
#  platform: ESP32
#  board: esp32dev

external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-iot
      ref: v1.2.1

esp32:
  board: esp32dev
  framework:
#    type: esp-idf
#    type: arduino
    type: arduino  # Важно изменить на arduino
    version: latest

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "mdhQnkxHuyHBBOp3c+vVZw1mijHvK6GlGVDXbwhzSMM="

mqtt:
  broker: !secret mqtt_host
  username: !secret mqtt_username
  password: !secret mqtt_password
  id: mqtt_client
 
ota:
  - platform: esphome
#    password: "5992f85d33c321fdc84443dbf6d1eab2"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Kc868-A6-Test Fallback Hotspot"
    password: "iuUkzi7OQNef"

captive_portal:
   

time:
  - platform: homeassistant
    id: homeassistant_time

# Example configuration entry for ESP32
i2c:
  sda: 4
  scl: 15
  scan: true
  id: bus_a

# Example configuration entry
pcf8574:
  - id: 'pcf8574_hub_out_1'  # for output channel 1-8
    address: 0x24

  - id: 'pcf8574_hub_in_1'  # for input channel 1-8
    address: 0x22

# Individual outputs
switch:
  - platform: gpio
    name: "a6-light1"
    id: light1
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output1", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output1", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 0
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: "a6-light2"
    id: light2
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output2", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output2", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 1
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light3"
    id: light3
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output3", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output3", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 2
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light4"
    id: light4
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output4", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output4", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 3
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light5"
    id: light5
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output5", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output5", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 4
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light6"
    id: light6
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output6", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output6", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 5
      mode: OUTPUT
      inverted: true
     

binary_sensor:
  - platform: gpio
    name: "a6-input1"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input2"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input3"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input4"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input5"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input6"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 5
      mode: INPUT
      inverted: true
#switch:
#  - platform: gpio
#    pin: 25
#    name: "switch test 1"
#    id: switch_test_1
#    on_turn_on:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output1", true);
#    on_turn_off:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output1", false);
#  - platform: gpio
#    pin: 26
#    name: "switch test 2"
#    id: switch_test_2
#    on_turn_on:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output2", true);
#    on_turn_off:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output2", false);


tuya_iot:
  id: tuya_iot_component
  product_id: xp***lm
  device_id: 26***3j
  device_secret: H***w
  region: eu # eu, us, eus, weu, in, cn
  # eu: Central Europe Data Center
  # us: US West Data Center
  # eus: US East Data Center
  # weu: Western Europe Data Center
  # in: India Data Center
  # cn: Chinese Data Center



  on_event:
    - event_name: property/set
      then:
        - lambda: !lambda |-
              // Append the required switch in switch_map to respond to commands issued by Tuya.
              static std::map<float, switch_::Switch*> switch_map {
                { 1, id(light1) },
                { 2, id(light2) },
                { 3, id(light3) },
                { 4, id(light4) },
                { 5, id(light5) },
                { 6, id(light6) },
              };

              bool is_target_output = false;
              bool output_state = false;
              int output_number = 0;
              // Modify this number 2 to match the number of switches in the above switch_map.
              for (int i = 1; i <= 6; i++) {
                String key = "output" + String(i);
                if (x.containsKey("data") && x["data"].containsKey(key.c_str())) {
                  is_target_output = true;
                  output_state = x["data"][key.c_str()];
                  output_number = i;
                  break;
                }
              }

              if (is_target_output) {
                auto iterator = switch_map.find(output_number);
                if (iterator != switch_map.end()) {
                  auto sw = iterator->second;
                  if (output_state) {
                    sw->turn_on();
                  } else {
                    sw->turn_off();
                  }
                }
              }

              bool is_target_all_on = false;
              bool all_on_state = false;

              if (x.containsKey("data") && x["data"].containsKey("all_on")) {
                is_target_all_on = true;
                all_on_state = x["data"]["all_on"];
              }

              if (is_target_all_on) {
                if (all_on_state) {
                  for(const auto& pair : switch_map) {
                    auto sw = pair.second;
                    sw->turn_on();
                  }
                }
              }

              bool is_target_all_off = false;
              bool all_off_state = false;

              if (x.containsKey("data") && x["data"].containsKey("all_off")) {
                is_target_all_off = true;
                all_off_state = x["data"]["all_off"];
              }

              if (is_target_all_off) {
                if (all_off_state) {
                  for(const auto& pair : switch_map) {
                    auto sw = pair.second;
                    sw->turn_off();
                  }
                }
              }
Reply
#36
i have updated esphome-tuya-iot plugin to 1.2.2  so need to modify yaml:
1: esp32 framework MUST use esp-idf
2. on_event lambda changed.

you can test with this new yaml modified.
Code:
# Basic Config
esphome:
  name: kc868-a6-test
  friendly_name: KC868_A6_Test
#  platform: ESP32
#  board: esp32dev

external_components:
  - source:
      type: git
      url: https://github.com/hzkincony/esphome-tuya-iot
      ref: v1.2.2

esp32:
  board: esp32dev
  framework:
#    type: esp-idf
#    type: arduino
    type: esp-idf  # Важно изменить на arduino
    version: latest

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "mdhQnkxHuyHBBOp3c+vVZw1mijHvK6GlGVDXbwhzSMM="

mqtt:
  broker: !secret mqtt_host
  username: !secret mqtt_username
  password: !secret mqtt_password
  id: mqtt_client

ota:
  - platform: esphome
#    password: "5992f85d33c321fdc84443dbf6d1eab2"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Kc868-A6-Test Fallback Hotspot"
    password: "iuUkzi7OQNef"

captive_portal:
   

time:
  - platform: homeassistant
    id: homeassistant_time

# Example configuration entry for ESP32
i2c:
  sda: 4
  scl: 15
  scan: true
  id: bus_a

# Example configuration entry
pcf8574:
  - id: 'pcf8574_hub_out_1'  # for output channel 1-8
    address: 0x24

  - id: 'pcf8574_hub_in_1'  # for input channel 1-8
    address: 0x22

# Individual outputs
switch:
  - platform: gpio
    name: "a6-light1"
    id: light1
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output1", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output1", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 0
      mode: OUTPUT
      inverted: true

  - platform: gpio
    name: "a6-light2"
    id: light2
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output2", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output2", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 1
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light3"
    id: light3
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output3", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output3", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 2
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light4"
    id: light4
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output4", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output4", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 3
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light5"
    id: light5
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output5", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output5", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 4
      mode: OUTPUT
      inverted: true
     
  - platform: gpio
    name: "a6-light6"
    id: light6
    on_turn_on:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output6", true);
    on_turn_off:
      - lambda: !lambda |-
          id(tuya_iot_component).property_report("output6", false);
    pin:
      pcf8574: pcf8574_hub_out_1
      number: 5
      mode: OUTPUT
      inverted: true
     

binary_sensor:
  - platform: gpio
    name: "a6-input1"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 0
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input2"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 1
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input3"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 2
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input4"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 3
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input5"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 4
      mode: INPUT
      inverted: true

  - platform: gpio
    name: "a6-input6"
    pin:
      pcf8574: pcf8574_hub_in_1
      number: 5
      mode: INPUT
      inverted: true
#switch:
#  - platform: gpio
#    pin: 25
#    name: "switch test 1"
#    id: switch_test_1
#    on_turn_on:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output1", true);
#    on_turn_off:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output1", false);
#  - platform: gpio
#    pin: 26
#    name: "switch test 2"
#    id: switch_test_2
#    on_turn_on:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output2", true);
#    on_turn_off:
#      - lambda: !lambda |-
#          id(tuya_iot_component).property_report("output2", false);


tuya_iot:
  id: tuya_iot_component
  product_id: xp***lm
  device_id: 26***3j
  device_secret: H***w
  region: eu # eu, us, eus, weu, in, cn
  # eu: Central Europe Data Center
  # us: US West Data Center
  # eus: US East Data Center
  # weu: Western Europe Data Center
  # in: India Data Center
  # cn: Chinese Data Center



  on_event:
    - event_name: property/set
      then:
        - lambda: !lambda |-
              // Append the required switch in switch_map to respond to commands issued by Tuya.
              static std::map<float, switch_::Switch*> switch_map {
                { 1, id(light1) },
                { 2, id(light2) },
                { 3, id(light3) },
                { 4, id(light4) },
                { 5, id(light5) },
                { 6, id(light6) },
              };

              bool is_target_output = false;
              bool output_state = false;
              int output_number = 0;
              // Modify this number 2 to match the number of switches in the above switch_map.
              for (int i = 1; i <= 6; i++) {
                std::string key = "output" + std::to_string(i);
                if (x["data"][key].is<bool>()) {
                  is_target_output = true;
                  output_state = x["data"][key].as<bool>();
                  output_number = i;
                  break;
                }
              }

              if (is_target_output) {
                auto iterator = switch_map.find(output_number);
                if (iterator != switch_map.end()) {
                  auto sw = iterator->second;
                  if (output_state) {
                    sw->turn_on();
                  } else {
                    sw->turn_off();
                  }
                }
              }

              bool is_target_all_on = false;
              bool all_on_state = false;

              if (x["data"]["all_on"].is<bool>()) {
                is_target_all_on = true;
                all_on_state = x["data"]["all_on"].as<bool>();
              }

              if (is_target_all_on) {
                if (all_on_state) {
                  for(const auto& pair : switch_map) {
                    auto sw = pair.second;
                    sw->turn_on();
                  }
                }
              }

              bool is_target_all_off = false;
              bool all_off_state = false;

              if (x["data"]["all_off"].is<bool>()) {
                is_target_all_off = true;
                all_off_state = x["data"]["all_off"].as<bool>();
              }

              if (is_target_all_off) {
                if (all_off_state) {
                  for(const auto& pair : switch_map) {
                    auto sw = pair.second;
                    sw->turn_off();
                  }
                }
              }
new yaml download:

.txt   a6-test-new.txt (Size: 8.04 KB / Downloads: 8)
Reply
#37
Спасибо. Теперь возник вопрос, как устройство добавить в SmartLife/Tuya приложение. Ранее добавлял через QR-код, который формировался в KCS прошивке.
А как получить QR-код для прошивки, написанной в ESPHome?
Reply
#38
do you have bought tuya license, we have send you "bind code" by email. you can use qrcode online guide, convert the "bind code" to qrcode. if you don't know how to make qrcode. you can send us your "bind code", we create qrcode for you.
Reply
#39
Send to web@kincony.com my license

"qrcode online guide" - post link?
Reply
#40
ok
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)