rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.85k stars 546 forks source link

Tuya Fan can not set the speed #710

Open vampywiz17 opened 2 years ago

vampywiz17 commented 2 years ago

The problem

i can not set the tuya fan speed,only read the value

Environment

Steps to reproduce

  1. Set the correct DPS
  2. Open Fan entity
  3. Move Slide

Configuration configuration.yaml or config_flow

image

DP dump

    "status": [
      {
        "code": "switch_fan",
        "dp_id": 1,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "countdown_fan",
        "dp_id": 2,
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      },
      {
        "code": "fan_speed_enum",
        "dp_id": 3,
        "type": "Enum",
        "values": "{\"range\":[\"level_1\",\"level_2\",\"level_3\",\"level_4\",\"level_5\"]}"
      },
      {
        "code": "fan_speed",
        "dp_id": 4,
        "type": "Integer",
        "values": "{\"unit\":\"%\",\"min\":1,\"max\":100,\"scale\":0,\"step\":1}"
      }
    ]
  },
  "success": true,
  "t": 1643059090409
}

Provide Home Assistant taceback/logs

2022-01-24 22:20:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Sending command heartbeat (device type: type_0a)
2022-01-24 22:20:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Send payload: b'{}'
2022-01-24 22:20:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Waiting for sequence number -100
2022-01-24 22:20:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Dispatching message TuyaMessage(seqno=0, cmd=9, retcode=0, payload=b'', crc=2958142211)
2022-01-24 22:20:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Got heartbeat response
2022-01-24 22:20:02 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Decrypted payload: {}
2022-01-24 22:20:03 DEBUG (MainThread) [custom_components.localtuya.discovery] Discovered device: {'ip': '192.168.31.223', 'gwId': '******************', 'active': 2, 'ability': 0, 'mode': 0, 'encrypt': True, 'productKey': '******************', 'version': '3.3'}
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.fan] Fan async_set_percentage: 67
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Sending command set (device type: type_0a)
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Send payload: b'{"devId":"bf774d69bdd41812c191au","uid":"******************","t":"1643059204","dps":{"4":"67"}}'
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Waiting for sequence number 4
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Dispatching message TuyaMessage(seqno=4, cmd=7, retcode=0, payload=b'', crc=3089766919)
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Dispatching sequence number 4
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bf7...1au] Decrypted payload: {}
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.fan] Fan async_set_percentage: 67 > 67.0
2022-01-24 22:20:04 DEBUG (MainThread) [custom_components.localtuya.fan] Fan speed_count: 100

Additional information

Device link: https://www.aliexpress.com/item/1005002941694177.html

Other info:

If i set the speed value in Tuya app, it show correctly in HA. Only the "writing" side is not working.

vampywiz17 commented 2 years ago

If i see it correctly, in today release this commit is approved, right?

https://github.com/rospogrigio/localtuya/pull/542

fbloemhof commented 2 years ago

There is a bug in the code, the speed is sent as an string but should be an integer.

When changing str to int on this line, setting of the speed works.

I'm nog sure how contributing to this project work but if I can find out I will do this.

deese commented 2 years ago

FYI, This PR fixes this: https://github.com/rospogrigio/localtuya/pull/942

vampywiz17 commented 2 years ago

@deese

It fixed! I hope add it to next release.

fbloemhof commented 2 years ago

How can we get this in a future release? My workaround was gone with the last update.