make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.34k stars 520 forks source link

AirCon is seen as switch #29

Closed jorgenDK closed 3 years ago

jorgenDK commented 3 years ago

When installing this integration via hacs airCon is seen as a switch - and I can turn it on and off.

From tuya developer site I can pull info, as below: How to make tuya-local use it? I think "kt" is tuya's device type for air con. How does that relate to "dps id" ?

{
  "result": {
    "active_time": 1599833600,
    "biz_type": 18,
    "category": "kt",
    "create_time": 1599833600,
    "icon": "smart/product_icon2/kt_1.png",
    "id": "*******************",
    "ip": "***************",
    "lat": "**********",
    "local_key": "*******************'",
    "lon": "****************",
    "name": "Air conditioner-bb77",
    "online": true,
    "owner_id": "********",
    "product_id": "*******",
    "product_name": "Air conditioner",
    "status": [
      {
        "code": "switch",
        "value": false
      },
      {
        "code": "temp_set",
        "value": 260
      },
      {
        "code": "temp_current",
        "value": 25
      },
      {
        "code": "mode",
        "value": "wind"
      },
      {
        "code": "humidity_current",
        "value": 0
      },
      {
        "code": "temp_set_f",
        "value": 61
      }
    ],
    "sub": false,
    "time_zone": "+01:00",
    "uid": "***************",
    "update_time": 1625975770,
    "uuid": "****************"
  },
  "success": true,
  "t": 1625995061287
}
Getting devices
Got devices
{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'current_temperature': 25,
    'max_temper': 880,
    'min_temper': 160,
    'mode': 'wind',
    'online': True,
    'state': 'false',
    'support_mode': [   'cold',
                        'hot',
                        'wind',
                        'auto'],
                        'temp_unit': 'CELSIUS',
                        'temperature': 260},
                        'dev_type': 'climate',
                        'ha_type': 'climate',
                        'icon': 'https://images.tuyaeu.com/smart/product_icon2/kt_1.png',
                        'id': '*******',
                        'name': 'Air conditioner-bb77'}],
                        'scenes': []
                        }}
make-all commented 3 years ago

That information is for the web API. The web API may be standardized for the "kt" type, but the local API is not. To work with this integration, I need the information about which dps each of the functions above is connected to. The above information does help, as the supported modes and temperature range is available without having to find out by experimentation, but capturing the dps from the Home Assistant log when you try to add it will give the local dps information.

jorgenDK commented 3 years ago

How is the device found - is it pattern matching on the numbers and text? I have this from home-assistant.log:

2021-07-11 16:02:13 INFO (MainThread) [custom_components.tuya_local.device] Setting protocol version for Test to 3.3.
2021-07-11 16:02:13 INFO (MainThread) [custom_components.tuya_local.device] Deleting device: ****************************
2021-07-11 16:02:13 INFO (MainThread) [custom_components.tuya_local.device] Creating device: ****************************
2021-07-11 16:02:13 INFO (MainThread) [custom_components.tuya_local.device] Setting protocol version for Simple Switch to 3.3.
2021-07-11 16:02:59 INFO (MainThread) [custom_components.tuya_local.device] Deleting device: ****************************
2021-07-11 16:04:07 INFO (MainThread) [custom_components.tuya_local.device] Setting protocol version for Test to 3.3.
2021-07-11 16:04:11 WARNING (MainThread) [custom_components.tuya_local.config_flow] Device matches simple_switch with quality of 4%. DPS: {'1': False, '2': 260, '3': 26, '4': 'wet', '5': 'lo
w', '18': 0, '20': 0, '105': 'off', '110': 131644, '113': '0', '114': '0', '119': '0', '120': 'off', '123': '0010', '126': '0', '127': '0', '128': '0', '129': '1', '130': 26, '131': False, '
132': False, '133': '0', '134': '{"t":1624086077,"s":false,"clr":true}', 'updated_at': 1626012247.8275397}
2021-07-11 16:04:11 WARNING (MainThread) [custom_components.tuya_local.config_flow] Report this to https://github.com/make-all/tuya-local/issues/
make-all commented 3 years ago

Not quite pattern matching, but it is matching the types of each dps. If a config is a matching subset of what the device returns, there is a chance it could work, so it is offered in the UI. The simple switch is offered for all devices with a boolean at DPS index 1, as that generally works as a fallback for minimal control.

I'll try to match as many of those as I can to the first list you posted from the web interface. Do you have a link to the manual, or a web page listing the features? It looks like there are more DPS there than the web API accounts for, so possibly there are other features like swing modes - a couple of your dps are showing "off" as their values. There are also two 26, and one 260. Maybe 260 is the current temperature, as it makes sense to have more precision for the sensor than can be set. And current temperature on DPS '2' and target temperature on '3' is quite a common combination, so I'll probably go with that for a first attempt.

jorgenDK commented 3 years ago

The "Smart Life" app offers lots of settings. 8 settings for "wind speed" and 2 *8 settings for air flow direction (up/down - left/right), timers, eco mode, self test and several other functions. Some of these settings must be part of the app / cloud - e.g. timers. The IR remote is more simple.

I think 26 deg is measuered temp and 260 is desired temp - based on the info pulled from Tuya dev site. "4" is mode - "wet" must dehumidfier. Item "5" - guessing - maybe fan speed. The rest I have no clue about.

The A/C was cheap, I bought it for a small vacation house. I have not found any online manual: https://www.tronitechnik.de/split-klimageraet-klimaanlage-hellnar-12000-btu/a-541 https://cdn02.plentymarkets.com/epm1wafxx218/frontend/Produktdatenblatt/Produktdatenblatt_Hellnar.pdf

make-all commented 3 years ago

OK, I'll make a basic config so you can at least observe those other values as you change from the remote. Then once you have collected the info on which values correspond to which functions and what values they can take, I may be able to add ability to control them. HomeAssistant only supports off, vertical, horizontal, both for swing mode, so you may not be able to set the angle of the air flow from HA (except maybe by timing the off if they remain in the location you turn them off in).

make-all commented 3 years ago

I have made a basic config in 0.8.7. Probably you can control the main hvac modes and maybe temperature. Others will be visible in the Developer UI so you can experiment with changing settings using the IR Remote and see what changes. You may also be able to control it with the official app, but most Tuya devices don't handle having two local connections at once, so you may need to force quit the app to get Home Assistant to update. The developer UI also requires a manual update in the latest version of HA, there is a little circular update icon to the left under the selected entity display.

If 0.8.7 is not showing up in HACS yet, you can do a manual check by clicking the menu button on the Tuya Local box in HACS, and select "Update information" (the exact text may be translated)

jorgenDK commented 3 years ago

It works partly. I can try to tinker with the device configuration. And I try to install and use the dev UI. Thanks for the work!

Modes can be selected - fan, dry, heat, cool - also switches device on. Cannot switch off. Temperature cannot be set.

make-all commented 3 years ago

OK, I've made some adjustments to the config. Please select "Reinstall" from the Tuya Local component within HACS, and select "main" from the dropdown to test the changes.

jorgenDK commented 3 years ago

It works partly. I can try to tinker with the device configuration. And I try to install and use the dev UI. Thanks for the work!

Modes can be selected - fan, dry, heat, cool - also switches device on. Cannot switch off.

jorgenDK commented 3 years ago

Thanks for your work, so far! I have installed update 8.8

I am not able to turn off the A/C. On the ha gui there are no off button. Preset modes does not include 'off' and 'Operation' is grey - cannot be selected.

Using Developer Tools - Services. Service: climate: Turn off Targets - Enitity tronitechnik No reaction from A/C (and no beep)

log show: 2021-07-14 10:36:26 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script 2021-07-14 10:36:26 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service

Service: climate: Set preset mode Targets - Enitity tronitechnik Preset mode: off (I write - no preset options)

A/C beeps a few times but is still on Same log messages as above

Service: climate: Set HVAC mode Targets - Enitity tronitechnik HVAC mode - off (all usual modes are listed in the drop down - off, fan_only, cool etc)

No reaction from A/C and the error below in the log:

2021-07-14 10:44:37 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Running websocket_api script 2021-07-14 10:44:37 INFO (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Executing step call service 2021-07-14 10:44:37 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 368, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 568, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service await handler.job.target(service_call) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service await self.hass.helpers.service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 760, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call await result File "/config/custom_components/tuya_local/generic/climate.py", line 280, in async_set_hvac_mode raise NotImplementedError() NotImplementedError 2021-07-14 10:44:37 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [1853592480] Error handling message: Unknown error Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 25, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 525, in handle_execute_script await script_obj.async_run(msg.get("variables"), context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1216, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 350, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 368, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 568, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1491, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1526, in _execute_service await handler.job.target(service_call) File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service await self.hass.helpers.service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 658, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 760, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 695, in _handle_entity_call await result File "/config/custom_components/tuya_local/generic/climate.py", line 280, in async_set_hvac_mode raise NotImplementedError() NotImplementedError

make-all commented 3 years ago

Sorry, I made those changes after releasing 0.8.8.

You need to select Reinstall rather than Update to get the option to install "main". Don't worry, although it is called reinstall, you will not lose any config.

I didn't want to make a new release so soon after the next one when the changes aren't going to be final, just a small improvement to allow further exploration.

jorgenDK commented 3 years ago

I reinstalled and selected "main". It added "false" to the preselect options. But selecting false does not turn the device off. Also now the temperature display is changed, so that current temp is 260 C not 26 and selected temp is eg. 2.3. In your latest update, you swap current temp and temp - I assume that is why.

make-all commented 3 years ago

Maybe I should have waited until I'd written some tests to pick up errors like this. off is treated specially in yaml, and gets converted to False. I needed quotes around it to make it the string "off". And I did swap the temperatures after you said setting it was not working, but I kept the scaling with the target temperature instead of swapping it over together with the 260.

jorgenDK commented 3 years ago

A/C can now be turned off - great! target_temp can be set when using the ha gui! Temp info is sometimes missing in the ha gui. I am not able to set target temp using developer tools - service - climate set temperature - New target temperature for HVAC. I enter an integer - e.g. 24 Do you have any suggestions for how I can set target temp w/o the ha gui? I plan to use the a/c in automation.

Thanks for your work! it's been great to get this far!

make-all commented 3 years ago

OK, this is good progress. The developer tools gui doesn't give you any feedback when it is successful. The only way I know my attempts to set the temperature on my heaters are successful is from the display on the heater flashing when it receives a command. Did you also set the entity to send the command to? There is no specific API for this, it uses the same entry point in the integration as setting from the Lovelace GUI, so if the GUI is working I expect commands should as well.

In yaml mode, this is what a working command in Developer Tools looks like for me:

service: climate.set_temperature
target:
  entity_id: climate.bedroom_heater
data:
  temperature: 18
jorgenDK commented 3 years ago

It's progressing well, I can now turn on, off, set mode and target temp!

In dev. tools, I tried to add area_id to the target and then target temperature can be set. To turn off, I use area - HVAC mode - off. The HA log show errors but the state is set to off:

Error executing script. Unexpected error for call_service at pos 1: ...

Question: when I look at States, the modes are shown as preset_modes. The tuya entity show the modes without preset_modes - what is the difference?


Entity: tronitechnik

State: auto

hvac_modes: []
min_temp: 7
max_temp: 35
target_temp_step: 1
preset_modes:
  - 'off'
  - dry
  - cool
  - auto
  - heat
  - fan_only
Entity: Tuya 1.3.x (api from Tuya that only function when I have a developer account - and it does not work correct)
State: off

hvac_modes:
  - 'off'
  - heat
  - cool
  - dry
  - fan_only
  - auto
make-all commented 3 years ago

I mislabelled the dps. I have just changed it from preset_mode to hvac_mode. If you made any automations that set preset_mode, you will have to change them to hvac_mode instead. It will also change the lovelace UI. Instead of selecting a preset from the more details popup, you will get some icons below the temperature setting.

jorgenDK commented 3 years ago

The ha ui looks fine now, after your update. I have swapped dps 2 and 3, moved scale: 10 to target_temp, now the temperatures are shown correct. I'll play with it for a few days and see how it work. Appear fully functional now.

Here is my change:

   - id: 2                        
      name: temperature            
      type: integer                
      mapping:                     
        - scale: 10                
      constraint: hvac_mode        
      conditions:                  
        - dps_val: cold            
          range:                   
            min: 17                
            max: 30                
        - dps_val: auto            
          range:                   
            min: 17                
        - dps_val: hot             
          range:                   
            min: 0                 
            max: 30                
        - dps_val: wet             
          invalid: true            
        - dps_val: wind            
          invalid: true            
    - id: 3                        
      name: current_temperature    
      type: integer
make-all commented 3 years ago

Nice to know the basics are fully functional. The HA climate does also support swing_mode, so it would be nice to also look at what effect those have on the "unknown" attributes. And if there are any modes like ECO, Turbo etc, we could use preset_mode for those.

jorgenDK commented 3 years ago

It's easy to set e.g. air flow direction in the a/c app and then use dev. tools state to see what values are changed. But I can't just assign a new value to e.g. unknown_123 and then call the service.

service: climate.unknown_123
target:
  entity_id: climate.tronitechnik_hellnar_klimagerat
data:
  unknown_123: '0018'

That gives a fail. I assume that unknown_123 has to be mapped to an existing attribute, e.g. set_swing_mode? How to use "preset_mode" ? I try to google some useful info, More than one of the "unknown_nnn" have to be changed when setting a mode such as wind direction.

make-all commented 3 years ago

If you change the name of unknown_123 to swing_mode, you might be able to set it from call service. Normally swing_mode needs also a list of valid modes, but that might only be for the UI.

I guess this magic value is "00HV", where H and V are one of the 8 positions for the vanes? And maybe the first two can also change to 1 (or something else) to indicate that the vanes are oscillating?

make-all commented 3 years ago

In this case, the standard swing modes should be available by something like (guessing wildly that 0 in the 3rd and 4th position leaves the vane where it is):

mapping:
   - dps_val: "0000"
     value: "off"  
   - dps_val: "1000"
     value: horizontal
   - dps_val: "0100"
     value: vertical
   - dps_val: "1100"
     value: both