diff --git a/README.md b/README.md index 7404fe9..16347b6 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,19 @@ A Home Assistant custom Integration for local handling of Tuya-based devices. This custom integration updates device status via push updates instead of polling, so status updates are fast (even when manually operated). +The integration also supports the Tuya IoT Cloud APIs, for the retrieval of info and of the local_keys of the devices. + + +**NOTE: The Cloud API account configuration is not mandatory (LocalTuya can work also without it) but is strongly suggested for easy retrieval (and auto-update after re-pairing a device) of local_keys. Cloud API calls are performed only at startup, and when a local_key update is needed.** + The following Tuya device types are currently supported: -* 1 and multiple gang switches -* Wi-Fi smart plugs (including those with additional USB plugs) +* Switches * Lights * Covers * Fans -* Climates (soon) +* Climates +* Vacuums Energy monitoring (voltage, current, watts, etc.) is supported for compatible devices. @@ -19,112 +24,68 @@ This repository's development began as code from [@NameLessJedi](https://github. # Installation: -Copy the localtuya folder and all of its contents into your Home Assistant's custom_components folder. This folder is usually inside your `/config` folder. If you are running Hass.io, use SAMBA to copy the folder over. If you are running Home Assistant Supervised, the custom_components folder might be located at `/usr/share/hassio/homeassistant`. You may need to create the `custom_components` folder and then copy the localtuya folder and all of its contents into it +The easiest way, if you are using [HACS](https://hacs.xyz/), is to install localtuya through HACS. -Alternatively, you can install localtuya through [HACS](https://hacs.xyz/) by adding this repository. +For manual installation, copy the localtuya folder and all of its contents into your Home Assistant's custom_components folder. This folder is usually inside your `/config` folder. If you are running Hass.io, use SAMBA to copy the folder over. If you are running Home Assistant Supervised, the custom_components folder might be located at `/usr/share/hassio/homeassistant`. You may need to create the `custom_components` folder and then copy the localtuya folder and all of its contents into it. # Usage: -**NOTE: You must have your Tuya device's Key and ID in order to use localtuya. There are several ways to obtain the localKey depending on your environment and the devices you own. A good place to start getting info is https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md .** +**NOTE: You must have your Tuya device's Key and ID in order to use localtuya. The easiest way is to configure the Cloud API account in the integration. If you choose not to do it, there are several ways to obtain the local_keys depending on your environment and the devices you own. A good place to start getting info is https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md .** **NOTE - Nov 2020: If you plan to integrate these devices on a network that has internet and blocking their internet access, you must also block DNS requests (to the local DNS server, e.g. 192.168.1.1). If you only block outbound internet, then the device will sit in a zombie state; it will refuse / not respond to any connections with the localkey. Therefore, you must first connect the devices with an active internet connection, grab each device localkey, and implement the block.** -Devices can be configured in two ways: -# Option one: YAML config files - -Add the proper entry to your configuration.yaml file. Several example configurations for different device types are provided below. Make sure to save when you are finished editing configuration.yaml. - -```yaml -localtuya: - - host: 192.168.1.x - device_id: xxxxx - local_key: xxxxx - friendly_name: Tuya Device - protocol_version: "3.3" - scan_interval: # optional, only needed if energy monitoring values are not updating - seconds: 30 # Values less than 10 seconds may cause stability issues - entities: - - platform: binary_sensor - friendly_name: Plug Status - id: 1 - device_class: power - state_on: "true" # Optional - state_off: "false" # Optional - - - platform: cover - friendly_name: Device Cover - id: 2 - open_close_cmds: ["on_off","open_close"] # Optional, default: "on_off" - positioning_mode: ["none","position","timed"] # Optional, default: "none" - currpos_dps: 3 # Optional, required only for "position" mode - setpos_dps: 4 # Optional, required only for "position" mode - span_time: 25 # Full movement time: Optional, required only for "timed" mode - - - platform: fan - friendly_name: Device Fan - id: 3 # dps for on/off state - fan_direction: 4 # Optional, dps for fan direction - fan_direction_fwd: forward # String for the forward direction - fan_direction_rev: reverse # String for the reverse direction - fan_ordered_list: low,medium,high,auto # Optional, If this is used it will not use the min and max integers. - fan_oscilating_control: 4 # Optional, dps for fan osciallation - fan_speed_control: 3 # Optional, if ordered list not used, dps for speed control - fan_speed_min: 1 # Optional, if ordered list not used, minimum integer for speed range - fan_speed_max: 10 # Optional, if ordered list not used, maximum integer for speed range +# Adding the Integration - - platform: light - friendly_name: Device Light - id: 4 # Usually 1 or 20 - color_mode: 21 # Optional, usually 2 or 21, default: "none" - brightness: 22 # Optional, usually 3 or 22, default: "none" - color_temp: 23 # Optional, usually 4 or 23, default: "none" - color_temp_reverse: false # Optional, default: false - color: 24 # Optional, usually 5 (RGB_HSV) or 24 (HSV), default: "none" - brightness_lower: 29 # Optional, usually 0 or 29, default: 29 - brightness_upper: 1000 # Optional, usually 255 or 1000, default: 1000 - color_temp_min_kelvin: 2700 # Optional, default: 2700 - color_temp_max_kelvin: 6500 # Optional, default: 6500 - scene: 25 # Optional, usually 6 (RGB_HSV) or 25 (HSV), default: "none" - music_mode: False # Optional, some use internal mic, others, phone mic. Only internal mic is supported, default: "False" +**NOTE: starting from v.4.0.0, configuration using YAML files is no longer supported. The integration can be configured only using the config flow.** - - platform: sensor - friendly_name: Plug Voltage - id: 20 - scaling: 0.1 # Optional - device_class: voltage # Optional - unit_of_measurement: "V" # Optional - - platform: switch - friendly_name: Plug - id: 1 - current: 18 # Optional - current_consumption: 19 # Optional - voltage: 20 # Optional -``` +To start configuring the integration, just press the "+ADD INTEGRATION" button in the Settings - Integrations page, and select localtuya from the drop-down menu. +The Cloud API configuration page will appear, requesting to input your Tuya IoT Platform account credentials: -Note that a single device can contain several different entities. Some examples: -- a cover device might have 1 (or many) cover entities, plus a switch to control backlight -- a multi-gang switch will contain several switch entities, one for each gang controlled +![cloud_setup](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/9-cloud_setup.png) -Restart Home Assistant when finished editing. +To setup a Tuya IoT Platform account and setup a project in it, refer to the instructions for the official Tuya integration: +https://www.home-assistant.io/integrations/tuya/ -# Option two: Using config flow +> **Note: as stated in the above page, if you already have an account and an IoT project, make sure that it was created after May 25, 2021 (due to changes introduced in the cloud for Tuya 2.0). Otherwise, you need to create a new project. See the following screenshot for where to check your project creation date:** -Start by going to Configuration - Integration and pressing the "+" button to create a new Integration, then select LocalTuya in the drop-down menu. -Wait for 6 seconds for the scanning of the devices in your LAN. Then, a drop-down menu will appear containing the list of detected devices: you can -select one of these, or manually input all the parameters. +![project_date](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/6-project_date.png) + +After pressing the Submit button, the first setup is complete and the Integration will be added. + +> **Note: it is not mandatory to configure the Cloud API account: you can choose to leave the default "xxx" values, and the Integration will be added anyway.** + +After the Integration has been set up, devices can be added and configured pressing the Configure button in the Integrations page: + +![integration_configure](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/10-integration_configure.png) + + +# Integration Configuration menu + +The configuration menu is the following: + +![config_menu](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/11-config_menu.png) + +From this menu, you can select the "Reconfigure Cloud API account" to edit your Tuya Cloud credentials and settings, in case they have changed or if the integration was migrated from v.3.x.x versions. + +You can then proceed Adding or Editing your Tuya devices. + +# Adding/editing a device + +If you select to "Add or Edit a device", a drop-down menu will appear containing the list of detected devices (using auto-discovery if adding was selected, or the list of already configured devices if editing was selected): you can select one of these, or manually input all the parameters selecting the "..." option. > **Note: The tuya app on your device must be closed for the following steps to work reliably.** + ![discovery](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/1-discovery.png) -If you have selected one entry, you only need to input the device's Friendly Name and the localKey. +If you have selected one entry, you only need to input the device's Friendly Name and localKey. These values will be automatically retrieved if you have configured your Cloud API account, otherwise you will need to input them manually. -Setting the scan interval is optional, only needed if energy/power values are not updating frequently enough by default. Values less than 10 seconds may cause stability issues. +Setting the scan interval is optional, it is only needed if energy/power values are not updating frequently enough by default. Values less than 10 seconds may cause stability issues. Once you press "Submit", the connection is tested to check that everything works. @@ -147,6 +108,10 @@ Once you configure the entities, the procedure is complete. You can now associat ![success](https://github.com/rospogrigio/localtuya-homeassistant/blob/master/img/5-success.png) +# Migration from LocalTuya v.3.x.x + +Automatically migrates... you can delete... + # Energy monitoring values You can obtain Energy monitoring (voltage, current) in two different ways: