Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fan Speed Control, device expect integer but fan integration send string instead for fan control #1036

Open
remlei opened this issue Sep 16, 2022 · 9 comments
Labels
bug Something isn't working

Comments

@remlei
Copy link

remlei commented Sep 16, 2022

The problem

Environment

  • Localtuya version: 4.0.1 and 4.1.0
  • Last working localtuya version (if known and relevant):
  • Home Assistant Core version: 2022.07.07 and 2022.09.04
  • [] Are you using the Home Assistant Tuya Cloud component ?
  • [] Are you using the Tuya App in parallel ?

Steps to reproduce

  1. usual steps to add a new tuya device to the integration
  2. choose fan on selection
  3. set the DPS for related setting
  4. done, now attempt to control the fan speed and it turns off

Configuration configuration.yaml or config_flow

DP dump

  "dps_strings": [
    "1 (value: True)",  # Power State
    "2 (value: 0)", # Timer setting in seconds
    "3 (value: level_1)", #setting for fan speed? doesnt seem to do anything regardless of level
    "4 (value: 100)" #setting for fan speed, this one that actually controls the fan speed, value 1-100 (integer)
  ],

Provide Home Assistant taceback/logs

Additional information

workaround:
https://community.home-assistant.io/t/local-tuya-fan-controller/306985/45

basically edit the fan.py and remove the string function. save changes and restart HA, now everything works.

@remlei remlei added the bug Something isn't working label Sep 16, 2022
@jedimdan
Copy link

Good news! After coming across your issue and trying the suggested fix, I discovered they fixed it in 4.1.1! After updating to 4.1.1, I edited the fan (LocalTuya > Configure > Edit a device), and when it comes to the page where you configure the DPs, right at the bottom is a new option "int or str". If your fan was having issues previously, just set it to "int" and it should work now. I guess some fans required a string value rather than integer, and we just happened to have fans that used the other. Now with this new setting, it satisfies all types of Tuya fans!

@rossco555
Copy link

Good news! After coming across your issue and trying the suggested fix, I discovered they fixed it in 4.1.1! After updating to 4.1.1, I edited the fan (LocalTuya > Configure > Edit a device), and when it comes to the page where you configure the DPs, right at the bottom is a new option "int or str". If your fan was having issues previously, just set it to "int" and it should work now. I guess some fans required a string value rather than integer, and we just happened to have fans that used the other. Now with this new setting, it satisfies all types of Tuya fans!

Yeah? I'm on 4.1.1 too, and HA latest Nov release in a Docker container, but I can't see that unfortunately. Anything else you might have done to get this option maybe?

@rossco555
Copy link

I realise now, this has actually gone backwards for me. I had employed the workaround mods to fan.py but have updated to 4.1.1 and this is now not working. Looking at fan.py now, I can see it implies a configuration option as described above for CONF_FAN_DPS_TYPE, but this is missing in the HA integration UI for me and so the code assumes str type.

I've reversed the logic as a workaround that suits my situation:

Changed...

self._dps_type = int if self._config.get(CONF_FAN_DPS_TYPE) == "int" else str

To...

self._dps_type = str if self._config.get(CONF_FAN_DPS_TYPE) == "str" else int

@jedimdan
Copy link

jedimdan commented Nov 4, 2022

@rossco555 it's possible that the UI only shows up when you add a new device as I did that a few times while troubleshooting this. Have you tried deleting the device and adding it again via localtuya?

@rossco555
Copy link

@rossco555 it's possible that the UI only shows up when you add a new device as I did that a few times while troubleshooting this. Have you tried deleting the device and adding it again via localtuya?

Thanks for the suggestion. I'll give that a try but may not get to it immediately. Will revert.

@rossco555
Copy link

@jedimdan I gave that a try just now but failed trying to remove a device: Settings > Integrations > localTuya Configure > Edit a Device > unchecked the entity name at bottom and clicked Submit, but I get:

An unknown error occurred. See log for details.
Traceback (most recent call last):
File "/config/custom_components/localtuya/config_flow.py", line 580, in async_step_configure_device
self.dps_strings = await validate_input(self.hass, user_input)
File "/config/custom_components/localtuya/config_flow.py", line 247, in validate_input
data[CONF_DEVICE_ID],
KeyError: 'device_id'

@jedimdan
Copy link

jedimdan commented Nov 5, 2022

@rossco555 You have to delete the device from HA, not localtuya. Open the device in HA, click on the 3 dots in the Device info card, and click on "Delete".

@vishalchaudhary
Copy link

The problem

Environment

  • Localtuya version: 4.0.1 and 4.1.0
  • Last working localtuya version (if known and relevant):
  • Home Assistant Core version: 2022.07.07 and 2022.09.04
  • [] Are you using the Home Assistant Tuya Cloud component ?
  • [] Are you using the Tuya App in parallel ?

Steps to reproduce

  1. usual steps to add a new tuya device to the integration
  2. choose fan on selection
  3. set the DPS for related setting
  4. done, now attempt to control the fan speed and it turns off

Configuration configuration.yaml or config_flow

DP dump

  "dps_strings": [
    "1 (value: True)",  # Power State
    "2 (value: 0)", # Timer setting in seconds
    "3 (value: level_1)", #setting for fan speed? doesnt seem to do anything regardless of level
    "4 (value: 100)" #setting for fan speed, this one that actually controls the fan speed, value 1-100 (integer)
  ],

Provide Home Assistant taceback/logs

Additional information

workaround: https://community.home-assistant.io/t/local-tuya-fan-controller/306985/45

basically edit the fan.py and remove the string function. save changes and restart HA, now everything works.

How did you take the dump of the DP settings? Cant figure out what DP is for what. Help appreciated.

@remlei
Copy link
Author

remlei commented Mar 23, 2023

I used the iot.tuya.com via API Explorer to dump the DPs at least back then but for some odd reason they removed it so, the only possible way to dump this is via tinytuya. it list all the possible DP ID numbers, its all up to you to find out which one DP correspond to but usually you can get each DP number funtions via API explorer on iot tuya website, look for the "Get Device Specification" under "General Device Management", each function corresponds to the DPs you have dumped using tinytuya all in sequntial, the first DP correspond to the first function, 2nd... 3rd... until you get to the last DP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants