arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.26k stars 4.82k forks source link

TuyaMCU actions no commands when MQTT Broker is connected #20608

Closed JustH4ppy closed 5 months ago

JustH4ppy commented 10 months ago

PROBLEM DESCRIPTION

A clear and concise description of what the problem is. I have a Sichler dehumidifier, which is currently not a supported device. It has a TYWE1S chip, which I flashed successfully. I was able to successfully assign TuyaRx and TuyaTx and was able to assign the fnids to dpids. I was able to toggle the relays I need successfully via the webinterface. As soon as I configure MQTT the device does not turn on/off anymore when toggeling the relays. No matter if actioned via Webinterface or MQTT. When I remove the Host from the MQTT configuration it starts working again. When MQTT is enabled but the MQTT Broker is stopped, it is working too.

REQUESTED INFORMATION

Make sure your have performed every step and checked the applicable boxes before submitting your issue. Thank you!

- [X] If using rules, provide the output of this command: `Backlog Rule1; Rule2; Rule3`:
```lua
  Rules output here:
- [X] Set `weblog` to 4 and then, when you experience your issue, provide the output of the Console log:
```lua
  Console output here:
With MQTT configured -> not working
13:22:54.458 APP: Boot Count 23
13:22:54.567 CFG: Saved to flash at F8, Count 132, Bytes 4096
13:22:55.430 TYA: Send "55aa00000000ff"
13:22:55.440 DMP: 55 AA 00 00 00 01 01 01
13:22:55.443 {"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}
13:22:55.445 TYA: Heartbeat
13:22:58.433 MQT: tasmota/discovery/84F3EB3FED59/config = {"ip":"192.168.178.44","dn":"Luftentfeuchter","fn":["Luftentfeuchter","",null,null,null,null,null,null],"hn":"Luftentfeuchter-3417","mac":"84F3EB3FED59","md":"Tuya MCU","ty":1,"if":0,"ofln":"Offline","onln":"Online","state":["OFF","ON","TOGGLE","HOLD"],"sw":"13.3.0","t":"Luftentfeuchter","ft":"%prefix%/%topic%/","tp":["cmnd","stat","tele"],"rl":[1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"swc":[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],"swn":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"btn":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"so":{"4":0,"11":0,"13":0,"17":0,"20":0,"30":0,"68":0,"73":0,"82":0,"114":0,"117":0},"lk":0,"lt_st":0,"bat":0,"dslp":0,"sho":[],"sht":[],"ver":1} (retained)
13:22:58.442 MQT: tasmota/discovery/84F3EB3FED59/sensors = {"sn":{"Time":"2024-01-28T13:22:58"},"ver":1} (retained)
13:23:06.427 TYA: Send "55aa00000000ff"
13:23:06.436 DMP: 55 AA 00 00 00 01 01 01
13:23:06.438 {"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}
13:23:06.440 TYA: Heartbeat
13:23:07.797 WIF: Checking connection...
13:23:12.081 SRC: WebGui from 192.168.178.148
13:23:12.097 TYA: Send "55aa00060005650100010071"
13:23:12.122 MQT: stat/Luftentfeuchter/RESULT = {"POWER1":"OFF"}
13:23:12.126 MQT: stat/Luftentfeuchter/POWER1 = OFF
13:23:12.202 DMP: 55 AA 00 07 00 05 65 01 00 01 00 72
13:23:12.205 {"TuyaReceived":{"Data":"55AA00070005650100010072","Cmnd":7,"CmndData":"6501000100","DpType1Id101":0,"101":{"DpId":101,"DpIdType":1,"DpIdData":"00"}}}
13:23:12.208 TYA: fnId=11 is set for dpId=101
13:23:12.210 TYA: RX Relay-1 --> MCU State: Off Current State:Off
13:23:12.577 CFG: Saved to flash at F7, Count 133, Bytes 4096
13:23:17.432 TYA: Send "55aa00000000ff"
13:23:17.442 DMP: 55 AA 00 00 00 01 01 01
13:23:17.444 {"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}
13:23:17.446 TYA: Heartbeat
13:23:21.462 SRC: WebGui from 192.168.178.148
13:23:21.477 TYA: Send "55aa00060005650100010172"
13:23:21.501 MQT: stat/Luftentfeuchter/RESULT = {"POWER1":"ON"}
13:23:21.504 MQT: stat/Luftentfeuchter/POWER1 = ON
13:23:21.579 DMP: 55 AA 00 07 00 05 65 01 00 01 01 73
13:23:21.581 {"TuyaReceived":{"Data":"55AA00070005650100010173","Cmnd":7,"CmndData":"6501000101","DpType1Id101":1,"101":{"DpId":101,"DpIdType":1,"DpIdData":"01"}}}
13:23:21.584 TYA: fnId=11 is set for dpId=101
13:23:21.586 TYA: RX Relay-1 --> MCU State: On Current State:On
13:23:21.648 CFG: Saved to flash at F6, Count 134, Bytes 4096
13:23:25.149 SRC: WebGui from 192.168.178.148
13:23:25.164 TYA: Send "55aa00060005650100010071"
13:23:25.189 MQT: stat/Luftentfeuchter/RESULT = {"POWER1":"OFF"}
13:23:25.194 MQT: stat/Luftentfeuchter/POWER1 = OFF
13:23:25.269 DMP: 55 AA 00 07 00 05 65 01 00 01 00 72
13:23:25.272 {"TuyaReceived":{"Data":"55AA00070005650100010072","Cmnd":7,"CmndData":"6501000100","DpType1Id101":0,"101":{"DpId":101,"DpIdType":1,"DpIdData":"00"}}}
13:23:25.274 TYA: fnId=11 is set for dpId=101
13:23:25.276 TYA: RX Relay-1 --> MCU State: Off Current State:Off
13:23:25.590 CFG: Saved to flash at F5, Count 135, Bytes 4096
13:23:27.758 WIF: Checking connection...
13:23:28.192 HTP: Console

With MQTT not configured -> working
00:00:00.001 HDW: ESP8266EX
00:00:00.054 CFG: Loaded from flash at F4, Count 136
00:00:00.060 QPC: Count 1
00:00:00.061 CFG: CR 386/699, Busy 0
00:00:00.065 TYA: Active=1
00:00:00.077 ROT: Mode 1
00:00:00.111 SNS: Hardware Serial
00:00:00.112 TYA: Request MCU configuration at 9600 bps
00:00:00.113 SRC: Restart
00:00:00.126 TYA: Send "55aa00060005650100010071"
00:00:00.147 Project tasmota - Luftentfeuchter Version 13.3.0(tasmota)-2_7_4_9(2023-12-12T14:29:05)
00:00:00.149 DMP: 55 AA 00 07 00 05 65 01 00 01 00 72
00:00:00.151 {"TuyaReceived":{"Data":"55AA00070005650100010072","Cmnd":7,"CmndData":"6501000100","DpType1Id101":0,"101":{"DpId":101,"DpIdType":1,"DpIdData":"00"}}}
00:00:00.152 TYA: fnId=11 is set for dpId=101
00:00:00.152 TYA: RX Relay-1 --> MCU State: Off Current State:Off
00:00:00.159 TYA: Set WiFi LED 2 (-1)
00:00:00.168 TYA: Send "55aa000300010205"
00:00:00.176 DMP: 55 AA 00 03 00 00 02
00:00:00.177 {"TuyaReceived":{"Data":"55AA0003000002","Cmnd":3}}
00:00:00.178 TYA: RX WiFi LED set ACK
00:00:00.227 WIF: Checking connection...
00:00:00.227 WIF: Attempting connection...
00:00:00.564 WIF: Connecting to AP1 Verbinden... Channel 6 BSSId 44:4E:6D:EE:B3:D6 in mode 11n as Luftentfeuchter-3417...
00:00:01.755 WIF: Checking connection...
00:00:01.756 WIF: Connected
00:00:02.007 HTP: Web server active on Luftentfeuchter-3417 with IP address 192.168.178.44
00:00:02.402 WIF: Sending Gratuitous ARP
00:00:02.403 NTP: Sync time...
00:00:02.464 WIF: DNS resolved '2.pool.ntp.org' (129.250.35.250) in 59 ms
00:00:02.507 RTC: UTC 2024-01-28T12:24:56, DST 2024-03-31T02:00:00, STD 2024-10-27T03:00:00
13:24:56.000 RTC: Synced by NTP
13:24:56.002 TYA: Set WiFi LED 3 (0)
13:24:56.011 TYA: Send "55aa000300010306"
13:24:56.020 DMP: 55 AA 00 03 00 00 02
13:24:56.021 {"TuyaReceived":{"Data":"55AA0003000002","Cmnd":3}}
13:24:56.022 TYA: RX WiFi LED set ACK
13:24:56.427 HTP: Console
13:24:56.032 RSL: INFO1 = {"Info1":{"Module":"Tuya MCU","Version":"13.3.0(tasmota)","FallbackTopic":"cmnd/Luftentfeuchter_fb/","GroupTopic":"cmnd/tasmotas/"}}
13:24:56.034 RSL: INFO2 = {"Info2":{"WebServerMode":"Admin","Hostname":"Luftentfeuchter-3417","IPAddress":"192.168.178.44"}}
13:24:56.036 RSL: INFO3 = {"Info3":{"RestartReason":"Software/System restart","BootCount":24}}
13:24:56.038 RSL: RESULT = {"POWER1":"OFF"}
13:24:56.040 RSL: POWER1 = OFF
13:24:56.041 RSL: RESULT = {"POWER2":"OFF"}
13:24:56.043 RSL: POWER2 = OFF
13:24:56.052 TYA: Send "55aa0001000000"
13:24:56.083 DMP: 55 AA 00 01 00 15 49 43 61 34 55 52 37 6F 56 68 78 70 43 6C 63 67 31 2E 30 2E 30 8F
13:24:56.084 {"TuyaReceived":{"Data":"55AA00010015494361345552376F56687870436C6367312E302E308F","Cmnd":1,"CmndData":"494361345552376F56687870436C6367312E302E30"}}
13:24:56.086 TYA: MCU Product ID: ICa4UR7oVhxpClcg1.0.0
13:24:56.094 TYA: Send "55aa0002000001"
13:24:56.102 DMP: 55 AA 00 02 00 00 01
13:24:56.103 {"TuyaReceived":{"Data":"55AA0002000001","Cmnd":2}}
13:24:56.105 TYA: RX MCU configuration Mode=0
13:24:56.106 TYA: Read MCU state
13:24:56.115 TYA: Send "55aa0008000007"
13:24:56.128 DMP: 55 AA 00 07 00 05 02 04 00 01 01 13
13:24:56.130 {"TuyaReceived":{"Data":"55AA00070005020400010113","Cmnd":7,"CmndData":"0204000101","DpType4Id2":1,"2":{"DpId":2,"DpIdType":4,"DpIdData":"01"}}}
13:24:56.131 TYA: fnId=0 is set for dpId=2

TO REPRODUCE

Steps to reproduce the behavior: Add/Remove MQTT Host IP. Toggle Power1 via Webinterface

EXPECTED BEHAVIOUR

A clear and concise description of what you expected to happen. Device turning On/Off when toggling DpID 101 which is working when MQTT is not configured

SCREENSHOTS

If applicable, add screenshots to help explain your problem.

ADDITIONAL CONTEXT

Add any other context about the problem here. MQTT Broker used: eclipse-mosquiotto and emqx. With both the same problem

(Please, remember to close the issue when the problem has been addressed)

barbudor commented 10 months ago

I'm not sure to follow

In the 1st log block where you say "MQTT connect => Not working, I can clearly see:

13:23:12.122 MQT: stat/Luftentfeuchter/RESULT = {"POWER1":"OFF"}
13:23:12.126 MQT: stat/Luftentfeuchter/POWER1 = OFF
13:23:12.202 DMP: 55 AA 00 07 00 05 65 01 00 01 00 72
13:23:12.205 {"TuyaReceived":{"Data":"55AA00070005650100010072","Cmnd":7,"CmndData":"6501000100","DpType1Id101":0,"101":{"DpId":101,"DpIdType":1,"DpIdData":"00"}}}
13:23:12.208 TYA: fnId=11 is set for dpId=101
13:23:12.210 TYA: RX Relay-1 --> MCU State: Off Current State:Off

That I can translate by

And right after the same dialog with value 0 for OFF

So it looks like it is working as expected

The 2nd block of logs with MQTT not connected doesn't show a valid exchange on dpId 101

JustH4ppy commented 10 months ago

Hey,

sorry, maybe the second logs with MQTT not configured were not complete. Here again with MQTT not configured and device turning On/Off correctly:

17:35:32.940 SRC: WebGui from 192.168.178.148
17:35:32.955 TYA: Send "55aa00060005650100010172"
17:35:32.979 RSL: RESULT = {"POWER1":"ON"}
17:35:32.981 RSL: POWER1 = ON
17:35:33.049 DMP: 55 AA 00 07 00 05 65 01 00 01 01 73
17:35:33.051 {"TuyaReceived":{"Data":"55AA00070005650100010173","Cmnd":7,"CmndData":"6501000101","DpType1Id101":1,"101":{"DpId":101,"DpIdType":1,"DpIdData":"01"}}}
17:35:33.054 TYA: fnId=11 is set for dpId=101
17:35:33.056 TYA: RX Relay-1 --> MCU State: On Current State:On
17:35:33.059 DMP: 55 AA 00 07 00 05 02 04 00 01 01 13
17:35:33.061 {"TuyaReceived":{"Data":"55AA00070005020400010113","Cmnd":7,"CmndData":"0204000101","DpType4Id2":1,"2":{"DpId":2,"DpIdType":4,"DpIdData":"01"}}}
17:35:33.064 TYA: fnId=0 is set for dpId=2
17:35:33.066 DMP: 55 AA 00 07 00 05 0C 05 00 01 00 1D
17:35:33.068 {"TuyaReceived":{"Data":"55AA000700050C050001001D","Cmnd":7,"CmndData":"0C05000100","DpType5Id12":"0x00","12":{"DpId":12,"DpIdType":5,"DpIdData":"00"}}}
17:35:33.070 TYA: fnId=0 is set for dpId=12
17:35:33.072 DMP: 55 AA 00 07 00 05 65 01 00 01 01 73
17:35:33.074 {"TuyaReceived":{"Data":"55AA00070005650100010173","Cmnd":7,"CmndData":"6501000101","DpType1Id101":1,"101":{"DpId":101,"DpIdType":1,"DpIdData":"01"}}}
17:35:33.077 TYA: fnId=11 is set for dpId=101
17:35:33.078 TYA: RX Relay-1 --> MCU State: On Current State:On
17:35:33.080 DMP: 55 AA 00 07 00 05 66 01 00 01 00 73
17:35:33.083 {"TuyaReceived":{"Data":"55AA00070005660100010073","Cmnd":7,"CmndData":"6601000100","DpType1Id102":0,"102":{"DpId":102,"DpIdType":1,"DpIdData":"00"}}}
17:35:33.086 TYA: fnId=12 is set for dpId=102
17:35:33.088 TYA: RX Relay-2 --> MCU State: Off Current State:Off
17:35:33.092 DMP: 55 AA 00 07 00 05 67 01 00 01 01 75
17:35:33.094 {"TuyaReceived":{"Data":"55AA00070005670100010175","Cmnd":7,"CmndData":"6701000101","DpType1Id103":1,"103":{"DpId":103,"DpIdType":1,"DpIdData":"01"}}}
17:35:33.097 TYA: fnId=0 is set for dpId=103
17:35:33.315 CFG: Saved to flash at F6, Count 166, Bytes 4096
17:35:36.252 HTP: Console
17:35:40.453 TYA: Send "55aa00000000ff"
17:35:40.462 DMP: 55 AA 00 00 00 01 01 01
17:35:40.464 {"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}
17:35:40.466 TYA: Heartbeat
17:35:51.456 TYA: Send "55aa00000000ff"
17:35:51.466 DMP: 55 AA 00 00 00 01 01 01
17:35:51.468 {"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}
17:35:51.471 TYA: Heartbeat
17:35:52.518 WIF: Checking connection...
17:36:02.447 TYA: Send "55aa00000000ff"
17:36:02.456 DMP: 55 AA 00 00 00 01 01 01
17:36:02.459 {"TuyaReceived":{"Data":"55AA000000010101","Cmnd":0,"CmndData":"01"}}
17:36:02.461 TYA: Heartbeat

That I can translate by

MQTT command to set Power OFF Tasmota send a command (opcode 6) to dpId 101 with value 0 MCU replies with a status (opcode 7) where dpId 101 has value 0 And right after the same dialog with value 0 for OFF

So it looks like it is working as expected

The MCU responds correctly, but the device does not. When MQTT is configured I can Send/Receive commands and status from the MCU, but the device itself does nothing at all. As soon as I unconfigure MQTT the device works fine when toggeling both Relays. If this somehow helps, I can also make a video about it. I'm happy about any help!

Thanks!

benjaminnestler commented 10 months ago

Hey @JustH4ppy

After a thorough analysis, I would claim that the standard Tuya Wifi Serial Protocol is not implemented in your Tuya MCU. It could be the Wifi for Low Power Protocol or a Bluetooth Serial Protocol (which would, of course, not be compatible with the TYWE1S).

As I interpret it, Tasmota supports the standard Wifi Serial Protocol (@barbudor, would you agree with me on this?)

The following observations led me to this assumption:

Tasmota reports the Network State in several stages. When Wifi is activated, Tasmota sends Network State 3 (0x02 = The Wi-Fi network is set up, but the device is not connected to the router).

00:00:00.168 TYA: Send "55aa000300010205"

When Tasmota is connected to Wifi, it sends an incremented Network State 4 (0x03 = The Wi-Fi network is set up, and the device is connected to the router).

13:24:56.011 TYA: Send "55aa000300010306"

The next stage would be a connection with MQTT. Then Tasmota would send Network State 5 (0x04 = The device is connected to the cloud). I would have liked to see this in your first LOG (with MQTT enabled).

Regardless of which Network State Tasmota sends, your TuyaMCU always responds with 55 AA 00 03 00 00 02.

In the normal Wifi Serial Protocol, this response does not exist. It is invalid!

However, assuming that your Tuya MCU responds to the Wifi Low Power Protocol, it would repeatedly signal the Wifi Reset command in its response.

Check here: https://developer.tuya.com/en/docs/iot/wifie1smodulemcu?id=K9hhi0xp301u1 and here: https://developer.tuya.com/en/docs/iot/tuyacloudlowpoweruniversalserialaccessprotocol?id=K95afs9h4tjjh

JustH4ppy commented 9 months ago

Hey @benjaminnestler,

thank you very much for your deep research! That would totally make sense! What would be your suggestion on solving that? Can I somehow suppress sending the network state? Or is there a way to program the MCU to adjust the firmware?

Meanwhile I quickly want to post my workaround, how I currently managed to get the device controlled by Home Assistant without MQTT. Maybe it's useful for somebody dealing with the same.

command_line:
  - switch:
      name: Luftentfeuchter Reinigung
      command_on: >
        curl -X POST "http://192.168.178.44/cm?cmnd=Power1%20On"
      command_off: >
        curl -X POST "http://192.168.178.44/cm?cmnd=Power1%20Off"
      command_state: curl -X GET "http://192.168.178.44/cm?cmnd=Power1"
      value_template: >
        {{value_json.POWER1 == "ON" }}
  - switch:
      name: Luftentfeuchter Entfeuchtung
      command_on: >
        curl -X POST "http://192.168.178.44/cm?cmnd=Power2%20On"
      command_off: >
        curl -X POST "http://192.168.178.44/cm?cmnd=Power2%20Off"
      command_state: curl -X GET "http://192.168.178.44/cm?cmnd=Power2"
      value_template: >
        {{value_json.POWER2 == "ON" }}
barbudor commented 9 months ago

Great analysis @benjaminnestler

Actually I always refer to the "Tuya Wifi Serial Protocol" documentation and I even didn't noticed that "Wifi for Low Power Protocol"

At least we see possibility for improvements as it should be possible to indentify which of those 2 protocols the MCU is using and adapt the dialog accordingly. But some more work and I don't have any of such devices in hand

JustH4ppy commented 9 months ago

Hey @barbudor,

I don't know if this is helpful, but I would like to provide any help remotely needed if this somehow helps. I can do photos of the pcb and also could set up a notebook in my network connected to the system, which you can remotely access if this somehow helps. Just let me know :)

benjaminnestler commented 9 months ago

Hi @JustH4ppy,

Can I somehow suppress sending the network state?

Currently, there is no SetOption or similar functionality to prevent reporting the network state. For the standard Tuya serial protocol, suppressing it does not seem practical.

Or is there a way to program the MCU to adjust the firmware?

Flashing the firmware of the TuyaMCU is not feasible unless you know the manufacturer of the firmware/device and have contact with them.

Tasmota is designed to adhere to the protocol by reporting the network state. The following lines are extracted from the Tuya serial protocol description:

  • When the module detects that the MCU is restarted or reconnected, it will proactively send the current Wi-Fi status to the MCU.
  • When the Wi-Fi status changes, the module will proactively send the current status to the MCU.

Perhaps we could consider implementing a configuration option to allow users to switch between different Tuya protocols, enabling them to decide which one to use.

@barbudor, I'm not sure if we can identify which of the tuya protocols is used by the TuyaMCU. The only difference lies in the third byte of the protocol versions (in some cases, 0x00 is used, and in others, 0x03), as well as in the available commands.

github-actions[bot] commented 9 months ago

This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

JustH4ppy commented 9 months ago

Issue still exists, please keep it open.

github-actions[bot] commented 8 months ago

This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

JustH4ppy commented 8 months ago

Please keep issue open.

github-actions[bot] commented 7 months ago

This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

JustH4ppy commented 7 months ago

Please keep open

github-actions[bot] commented 6 months ago

This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

JustH4ppy commented 6 months ago

please keep open

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it hasn't any activity in last few weeks. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 5 months ago

This issue was automatically closed because of being stale. Feel free to open a new one if you still experience this problem.