localtuya icon indicating copy to clipboard operation
localtuya copied to clipboard

localtuya/number.py: Number set to correct DP but comes back as set to 0. Issue with int vs float?

Open ingoratsdorf opened this issue 2 years ago • 5 comments

May be related to #https://github.com/rospogrigio/localtuya/issues/710 ?

The problem

Move a slider for a number entity to any number other than 0, comes back as set to 0 (zero)

Environment

  • Localtuya version: v4.0.1
  • Home Assistant Core version: Home Assistant Core 2022.6.7
  • [] Are you using the Home Assistant Tuya Cloud component ?
  • [] Are you using the Tuya App in parallel ?

Steps to reproduce

LocalTuya defined for a PIR sensor. It’s DPS config represents the following:

- 101 - Mode: mode_auto/mode_on/mode_off <Select>
- 102 - Light State: true/false <Binary Sensor Only>
- 103 - Motion Sensitivity: 0=sensitive, 4=no sensitivity [0-4] <Number>
- 104 - Light Timeout when in Auto mode (secs) [10-900] <Number>
- 105 - Light Cutout Threshold 0=bright, 981=darkness [0-981] <Number>
- 106 - Reset to Auto after 1 hr in Manual On: True/False <Switch>

When I move the slider for DP103 to any number in Home Asiistant, it comes back as set to 0 (zero) Same for DP104 and DP105. Comes back as zero. If I call a service as below

  - service: localtuya.set_dp
    data:
      device_id: 21463430e098061daaed
      dp: 103
      value: 2

The value is correctly set to what it is supposed to be.

Configuration configuration.yaml or config_flow

config_flow

Provide Home Assistant taceback/logs

2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Sending command set (device type: type_0a)
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Send payload: b'{"devId":"xxxxxxxxxx","uid":"xxxxxxxxxxxxx","t":"1656833437","**dps":{"103":4.0}}'**
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Waiting for sequence number 72
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Dispatching message TuyaMessage(seqno=72, cmd=7, retcode=0, payload=b'', crc=2669490775)
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Dispatching sequence number 72
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Decrypted payload: {}
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Dispatching message TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b"3.3\x00\x00\x00\x00\x00\x00\x00\x9b\x00\x00\x00\x01\xab\x98d\xbd\xfa,\x83'\xf8\x9e\xfe\xb9\xc6\x99}G?\x08N\x1b\x0c\xd4\xc4*\x06\x1f\xb2\x90\x19\xed\x92JL\x14.\x07l\xb3\xddR\xc1\x1e\xe0L{\x84\xe8\xc5\xc53S\x82m\xb4\xe2\xe7&\xfc0$[\xf5LG", crc=233730411)
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Got status update
2022-07-03 19:30:37 DEBUG (MainThread) [custom_components.localtuya.pytuya] [214...533] Decrypted payload: {"devId":"xxxxxxxxxxxxx","**dps":{"103":0}**,"t":1656833436}

Additional information

As noted above, when manually calling the setDP service, all is working. I noticed in the trace above that the number is sent as 4.0 (float) and comes back as 0 (int). Can it be that tuya (or this device) does not support floats (4.0) but expects just an integer (4)? Can localtuya use integer only to send?

ingoratsdorf avatar Jul 03 '22 09:07 ingoratsdorf