CTO and TechLead at BraveBits/PageFly
- Software Engineer
- Hardware Engineer
- Graphic Designer
ESPHome custom components for Tuya curtain includes feedback and position support
Hi,
I have the newest version with homekit option. There is no ESP anymore inside, but what looks like a custom Tuya chip. I did not try to flash this onboard chip, but I doubt wether that would work.
So I got a ESP8266 of the shelf and programmed it with this ESPHome code. Sadly it not work, I cut the power to the Tuya onboard Wifi chip and used the TX en RX pin of that wifi chip (note, dont use the pin header with Tx Rx writing, it is a different interface) to connect the UART of the ESP to.
In the end I ended up sniffing al the traffic on that interface when te motor was connected to the Tuya app and came up with these codes below (decimal, not hex).
Surely everthing can be more clean coded, but these are the working values I would like to share to others as a start to get the motor working. Works for days now and looks very stable.
if (call.get_stop()) { //stop
crc = 0;
writeByte(85);
writeByte(170);
writeByte(0);
writeByte(6);
writeByte(0);
writeByte(5);
writeByte(1);
writeByte(4);
writeByte(0);
writeByte(1);
writeByte(1);
writeByte(17);
}
```
if (call.get_position().has_value()) {
crc = 0;
uint8_t pos = *call.get_position() * 100.0f;
if (pos == 100) { //close
writeByte(85);
writeByte(170);
writeByte(0);
writeByte(6);
writeByte(0);
writeByte(5);
writeByte(1);
writeByte(4);
writeByte(0);
writeByte(1);
writeByte(0);
writeByte(16);
} else if (pos == 0) { //open
writeByte(85);
writeByte(170);
writeByte(0);
writeByte(6);
writeByte(0);
writeByte(5);
writeByte(1);
writeByte(4);
writeByte(0);
writeByte(1);
writeByte(2);
writeByte(18);
} else { //position
writeByte(85);
writeByte(170);
writeByte(0);
writeByte(6);
writeByte(0);
writeByte(8);
writeByte(2);
writeByte(2);
writeByte(0);
writeByte(4);
writeByte(0);
writeByte(0);
writeByte(0);
writeByte(pos);
writeByte(crc);
}
}
}
` void setMotorNormal() {
writeByte(85);
writeByte(170);
writeByte(0);
writeByte(6);
writeByte(0);
writeByte(5);
writeByte(5);
writeByte(4);
writeByte(0);
writeByte(1);
writeByte(1);
writeByte(21);
}
void setMotorReversed() {
writeByte(85);
writeByte(170);
writeByte(0);
writeByte(6);
writeByte(0);
writeByte(5);
writeByte(5);
writeByte(4);
writeByte(0);
writeByte(1);
writeByte(1);
writeByte(20);
}`
//And the position I read from (only basic info at the start and the end of a run by filtering on buffer[10]==67 only as the rest required me too much time to find out and I never need the position during motor running.
if (sum == crc and buffer[10] == 67 ) {
position = buffer[17] / 100.0f;
Hello there, @iphong !
The following issues were encountered:
GPIO13
and GPIO15
(connected to U1TX
/ U1RX
, not U0TX
/ U0RX
as stated in YAML).0x66
, not 0x65
.COVER_OPERATION_IDLE
and COVER_OPERATION_OPENING
felt swapped.0x68
was never encountered during operation.Unfortunately, it is not yet possible for me to contribute with code update as the device is no longer in my posession.
The device was purchased in February 2022.
Following is the log for several actions (output injected before appending new byte to the buffer array, with numbers in square brackets indicating indices of the buffer array):
[19:20:10][D][custom_curtain:059]: read[0]: 55
[19:20:10][D][custom_curtain:059]: read[1]: AA
[19:20:10][D][custom_curtain:059]: read[2]: 00
[19:20:10][D][custom_curtain:059]: read[3]: 07
[19:20:10][D][custom_curtain:059]: read[4]: 00
[19:20:10][D][custom_curtain:059]: read[5]: 08
[19:20:10][D][custom_curtain:059]: read[6]: 65
[19:20:10][D][custom_curtain:059]: read[7]: 02
[19:20:10][D][custom_curtain:059]: read[8]: 00
[19:20:10][D][custom_curtain:059]: read[9]: 04
[19:20:10][D][custom_curtain:059]: read[10]: 00
[19:20:10][D][custom_curtain:059]: read[11]: 00
[19:20:10][D][custom_curtain:059]: read[12]: 00
[19:20:10][D][custom_curtain:059]: read[13]: 48
[19:20:10][D][custom_curtain:059]: read[14]: C1
[19:20:10][D][custom_curtain:059]: read[0]: 55
[19:20:10][D][custom_curtain:059]: read[1]: AA
[19:20:10][D][custom_curtain:059]: read[2]: 00
[19:20:10][D][custom_curtain:059]: read[3]: 07
[19:20:10][D][custom_curtain:059]: read[4]: 00
[19:20:10][D][custom_curtain:059]: read[5]: 05
[19:20:10][D][custom_curtain:059]: read[6]: 66
[19:20:10][D][custom_curtain:059]: read[7]: 04
[19:20:10][D][custom_curtain:059]: read[8]: 00
[19:20:10][D][custom_curtain:059]: read[9]: 01
[19:20:10][D][custom_curtain:059]: read[10]: 01
[19:20:10][D][custom_curtain:059]: read[11]: 77
[19:20:12][D][custom_curtain:059]: read[0]: 55
[19:20:12][D][custom_curtain:059]: read[1]: AA
[19:20:12][D][custom_curtain:059]: read[2]: 00
[19:20:12][D][custom_curtain:059]: read[3]: 07
[19:20:12][D][custom_curtain:059]: read[4]: 00
[19:20:12][D][custom_curtain:059]: read[5]: 08
[19:20:12][D][custom_curtain:059]: read[6]: 65
[19:20:12][D][custom_curtain:059]: read[7]: 02
[19:20:12][D][custom_curtain:059]: read[8]: 00
[19:20:12][D][custom_curtain:059]: read[9]: 04
[19:20:12][D][custom_curtain:059]: read[10]: 00
[19:20:12][D][custom_curtain:059]: read[11]: 00
[19:20:12][D][custom_curtain:059]: read[12]: 00
[19:20:12][D][custom_curtain:059]: read[13]: 3A
[19:20:12][D][custom_curtain:059]: read[14]: B3
[19:20:12][D][custom_curtain:059]: read[0]: 55
[19:20:12][D][custom_curtain:059]: read[1]: AA
[19:20:12][D][custom_curtain:059]: read[2]: 00
[19:20:12][D][custom_curtain:059]: read[3]: 07
[19:20:12][D][custom_curtain:059]: read[4]: 00
[19:20:12][D][custom_curtain:059]: read[5]: 05
[19:20:12][D][custom_curtain:059]: read[6]: 66
[19:20:12][D][custom_curtain:059]: read[7]: 04
[19:20:12][D][custom_curtain:059]: read[8]: 00
[19:20:12][D][custom_curtain:059]: read[9]: 01
[19:20:12][D][custom_curtain:059]: read[10]: 02
[19:20:12][D][custom_curtain:059]: read[11]: 78
Unfortunately, I cannot fully recite the order of operations presented within the log.
It, however, looks like either:
Operations were triggered using bundled remote.
Do you have a guide on how to add this to Home Assistant?
Where does your yaml and .h files go and how do you set this up in 'integrations' or configuration.yaml?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.