I’ve uploaded the guide for ESP-IDF and Arduino using an ESP32-C3 chip but you can make sure incompatible values have been corrected before flashing your chip i.e. platform and chip/board variant to esp8266 either modwifi or wroom_02 for 2mb flash
So I checked your code and noticed that you used baud rate of 115200 while I used 9600, which looks like that was the main reason it did not appear to work.
Just changing my code to the correct baud rate (115200) made it communicate.
I now used your code and did a change on the lambda code in the text_sensor Self Check Result and changed the single equal with a double, so that it would validate the state and not trying to set it.
It did report a warning on that while compiling.
Also the Tuya MCU integration does report a error when using other baudrate then 9600
[02:04:10][E][uart:015]: Invalid baud_rate: Integration requested baud_rate 9600 but you have 115200!
How did you know to use 115200 baud rate?
I was looking on the Tuya documentation, probably not deep enough, but did not find anything.
Hi,
i just bought this sensor, tried to compile your esp-idf example, but esphome compiler gives these errors:
/config/esphome/presence-klet2.yaml:118:28: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
if (id(selfcheck).state = 0) {
~~~~~~~~~~~~~~~~~^~~
/config/esphome/presence-klet2.yaml:121:33: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
else if (id(selfcheck).state = 1) {
~~~~~~~~~~~~~~~~~^~~
/config/esphome/presence-klet2.yaml:124:33: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
else if (id(selfcheck).state = 2) {
~~~~~~~~~~~~~~~~~^~~
/config/esphome/presence-klet2.yaml:127:33: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
else if (id(selfcheck).state = 3) {
~~~~~~~~~~~~~~~~~^~~
/config/esphome/presence-klet2.yaml:130:33: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
else if (id(selfcheck).state = 4) {
~~~~~~~~~~~~~~~~~^~~
/config/esphome/presence-klet2.yaml:133:33: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
else if (id(selfcheck).state = 5) {
Do you have any clue why? ESPHome addon is latest available, HA also.
Yes, the example code is incorrect with the validation.
id(selfcheck).state = 2
has to change to id(selfcheck).state == 2
one equal sign = will assign a value to a variable and two == will check the value of the variable to equals the value.
so id(selfcheck).state = 2 will assign the value of 2 to id(selfcheck).state
id(selfcheck).state == 2 will se if the value of id(selfcheck).state equals 2 and that will return true or false and the if statement expects true boolean to execute the code within the { }
So change all the
id(selfcheck).state = 1 to id(selfcheck).state == 1
id(selfcheck).state = 2 to id(selfcheck).state == 2
etc… in the lambda of the text_sensor and you should be fine.
Great, thanks a lot! Now compile is succesfull.
What can i say…i’m not an experienced programmer, so i didn’t notice this error. Now when you told me i know that there should be “==”… so thanks again!
I spent whole afternoon learning and configuring this sensor via Tuya integration, and… i can’t emphasize enough how much i hate tuya and it’s complicated learning process… I didn’t manage to get “local tuya” running, only official version, so it’s one reason more for esphome, since it runs locally. Hopefully it will work perfect. Main thing is that i have a working esphome file now. I have a couple of esp32-C3 modules lying in the drawer, i’ll try it out tomorrow, it’s getting late here.
Just to let you guys know… above code works PERFECTLY! Many thanks again!
A small warning: first time code must be uploaded via esphome’s browser install page on esp32-c3. Installing bin file with esp32 flasher doesn’t work! All other updates are then made via wifi.
I love it compared to original tuya… i managed to make local tuya to work, but esphome is better, faster, and, above all: it’s totally local, which i prefer.
Hi @ashp, I’ve transplanted ESP32 C3 12F to this sensor. However, MCU module doesn’t seem to work for me. I pretty much took your configuration on ESPHome. I’m getting this error:
21:41:54][C][tuya:041]: Tuya:
[21:41:54][C][tuya:044]: Initialization failed. Current init_state: 0
[21:41:54][C][tuya:049]: If no further output is received, confirm that this is a supported Tuya device.
[21:41:57][E][tuya:433]: Initialization failed at init_state 0
Please provide your yaml so we can help debugging.
But looks like you have the same issue I had and that was the baud_rate was incorrect.
So either it’s set to the wrong rate ( maybe tuya has made an update? ) or you have hardware issue on the TX / RX lines, maybe check soldering?
I don’t think there is issue with TX/RX line. The soldering looks good to me. I transplanted another sensor and it also has the same issue :(. Tuya might have changed their code?
Ok… is that the roof mounted sensor? … never mind you answered that in your post
maybe the connections are not the same as you had same issue on two.
So if you are sure that the TX and RX are correct, try setting baud_rate: 9600 under uart.
Maybe this sensor uses that baud and not the 115200 the wall mounted one used.
I am waiting for my modules to arrive to do the transplant. I am wondering if you mange to get it working.
Just looking at your jump wire it seemed to be attaching to Gpio5 rather than EN. I guess that didn’t cause problem since you were still able to get the chip booted.
Did you manage to get it working? I have tried with two of my sensors and they don’t work with log output just like yours. I have the wall mounted ones.
I have a couple ceiling version but they take mains power. I wanted to solder wires on to the pads to test it out before I solder the chip on since it’s a pain to take them off. I wanted to try because it is very unlikely that my heat gun would have damaged the ceiling version since I just used solder wick to take the pcb off then use heat gun to take the zigbee chip off.