|
Hello, Can you correct the code for me to integrate the Tuya app by ESPHome in KC868-A16S ?
external_components:
- source:
type: git
url: https://github.com/hzkincony/esphome-tuya-iot
ref: v1.2.0
time:
- platform: homeassistant
id: homeassistant_time
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);
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);
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);
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);
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);
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);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output7", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output7", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output8", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output8", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output9", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output9", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output10", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output10", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output11", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output11", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output12", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output12", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output13", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output13", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output14", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output14", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output15", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output15", false);
on_turn_on:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output16", true);
on_turn_off:
- lambda: !lambda |-
id(tuya_iot_component).property_report("output16", false);
tuya_iot:
id: tuya_iot_component
product_id: pxdb.........................
device_id: 263..............................
device_secret: Fw9..........................
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(a16s-output1) },
{ 2, id(a16s-output2) },
{ 3, id(a16s-output3) },
{ 4, id(a16s-output4) },
{ 5, id(a16s-output5) },
{ 6, id(a16s-output6) },
{ 7, id(a16s-output7) },
{ 8, id(a16s-output8) },
{ 9, id(a16s-output9) },
{ 10, id(a16s-output10) },
{ 11, id(a16s-output11) },
{ 12, id(a16s-output12) },
{ 13, id(a16s-output13) },
{ 14, id(a16s-output14) },
{ 15, id(a16s-output15) },
{ 16, id(a16s-output16) },
};
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 <= 16; 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();
}
}
}
|