You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+66-91
Original file line number
Diff line number
Diff line change
@@ -2,129 +2,95 @@
2
2
3
3
A Home Assistant custom Integration for local handling of Tuya-based devices.
4
4
5
-
This custom integration updates device status via push updates instead of polling, so status updates are fast (even when manually operated).
5
+
This custom integration updates device status via pushing updates instead of polling, so status updates are fast (even when manually operated).
6
+
The integration also supports the Tuya IoT Cloud APIs, for the retrieval of info and of the local_keys of the devices.
7
+
8
+
9
+
**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.**
10
+
6
11
7
12
The following Tuya device types are currently supported:
8
-
* 1 and multiple gang switches
9
-
* Wi-Fi smart plugs (including those with additional USB plugs)
13
+
* Switches
10
14
* Lights
11
15
* Covers
12
16
* Fans
13
-
* Climates (soon)
17
+
* Climates
18
+
* Vacuums
14
19
15
20
Energy monitoring (voltage, current, watts, etc.) is supported for compatible devices.
16
21
22
+
> **Currently, only Tuya protocols 3.1 and 3.3 are supported (3.4 is not).**
23
+
17
24
This repository's development began as code from [@NameLessJedi](https://github.com/NameLessJedi), [@mileperhour](https://github.com/mileperhour) and [@TradeFace](https://github.com/TradeFace). Their code was then deeply refactored to provide proper integration with Home Assistant environment, adding config flow and other features. Refer to the "Thanks to" section below.
18
25
19
26
20
27
# Installation:
21
28
22
-
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
29
+
The easiest way, if you are using [HACS](https://hacs.xyz/), is to install LocalTuya through HACS.
23
30
24
-
Alternatively, you can install localtuya through [HACS](https://hacs.xyz/) by adding this repository.
31
+
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.
25
32
26
33
27
34
# Usage:
28
35
29
-
**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 .**
36
+
**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 .**
30
37
31
38
32
-
**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.**
39
+
**NOTE 2: 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.**
33
40
34
-
Devices can be configured in two ways:
35
41
36
-
# Option one: YAML config files
42
+
# Adding the Integration
37
43
38
-
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.
39
44
40
-
```yaml
41
-
localtuya:
42
-
- host: 192.168.1.x
43
-
device_id: xxxxx
44
-
local_key: xxxxx
45
-
friendly_name: Tuya Device
46
-
protocol_version: "3.3"
47
-
scan_interval: # optional, only needed if energy monitoring values are not updating
48
-
seconds: 30# Values less than 10 seconds may cause stability issues
scene: 25# Optional, usually 6 (RGB_HSV) or 25 (HSV), default: "none"
92
-
music_mode: False # Optional, some use internal mic, others, phone mic. Only internal mic is supported, default: "False"
93
-
94
-
- platform: sensor
95
-
friendly_name: Plug Voltage
96
-
id: 20
97
-
scaling: 0.1# Optional
98
-
device_class: voltage # Optional
99
-
unit_of_measurement: "V"# Optional
100
-
101
-
- platform: switch
102
-
friendly_name: Plug
103
-
id: 1
104
-
current: 18# Optional
105
-
current_consumption: 19# Optional
106
-
voltage: 20# Optional
107
-
```
45
+
**NOTE: starting from v4.0.0, configuration using YAML files is no longer supported. The integration can only be configured using the config flow.**
46
+
47
+
48
+
To start configuring the integration, just press the "+ADD INTEGRATION" button in the Settings - Integrations page, and select LocalTuya from the drop-down menu.
49
+
The Cloud API configuration page will appear, requesting to input your Tuya IoT Platform account credentials:
To setup a Tuya IoT Platform account and setup a project in it, refer to the instructions for the official Tuya integration:
54
+
https://www.home-assistant.io/integrations/tuya/
55
+
The place to find the Client ID and Secret is described in this link (in the ["Get Authorization Key"](https://www.home-assistant.io/integrations/tuya/#get-authorization-key) paragraph), while the User ID can be found in the "Link Tuya App Account" subtab within the Cloud project:
> **Note: as stated in the above link, 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:**
After pressing the Submit button, the first setup is complete and the Integration will be added.
108
64
109
-
Note that a single device can contain several different entities. Some examples:
110
-
- a cover device might have 1 (or many) cover entities, plus a switch to control backlight
111
-
- a multi-gang switch will contain several switch entities, one for each gang controlled
65
+
> **Note: it is not mandatory to input the Cloud API credentials: you can choose to tick the "Do not configure a Cloud API account" button, and the Integration will be added anyway.**
112
66
113
-
Restart Home Assistant when finished editing.
67
+
After the Integration has been set up, devices can be added and configured pressing the Configure button in the Integrations page:
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.
79
+
80
+
You can then proceed Adding or Editing your Tuya devices.
81
+
82
+
# Adding/editing a device
83
+
84
+
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.
120
85
121
86
> **Note: The tuya app on your device must be closed for the following steps to work reliably.**
If you have selected one entry, you only need to input the device's Friendly Name and the localKey.
91
+
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.
126
92
127
-
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.
93
+
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.
128
94
129
95
Once you press "Submit", the connection is tested to check that everything works.
130
96
@@ -147,15 +113,22 @@ Once you configure the entities, the procedure is complete. You can now associat
If you upgrade LocalTuya from v3.x.x or older, the config entry will automatically be migrated to the new setup. Everything should work as it did before the upgrade, apart from the fact that in the Integration tab you will see just one LocalTuya integration (showing the number of devices and entities configured) instead of several Integrations grouped within the LocalTuya Box. This will happen both if the old configuration was done using YAML files and with the config flow. Once migrated, you can just input your Tuya IoT account credentials to enable the support for the Cloud API (and benefit from the local_key retrieval and auto-update): see [Configuration menu](https://github.com/rospogrigio/localtuya#integration-configuration-menu).
119
+
120
+
If you had configured LocalTuya using YAML files, you can delete all its references from within the YAML files because they will no longer be considered so they might bring confusion (only the logger configuration part needs to be kept, of course, see [Debugging](https://github.com/rospogrigio/localtuya#debugging) ).
121
+
122
+
150
123
# Energy monitoring values
151
124
152
125
You can obtain Energy monitoring (voltage, current) in two different ways:
153
126
154
127
1) Creating individual sensors, each one with the desired name.
155
128
Note: Voltage and Consumption usually include the first decimal. You will need to scale the parament by 0.1 to get the correct values.
156
-
1) Access the voltage/current/current_consumption attributes of a switch, and define template sensors
129
+
2) Access the voltage/current/current_consumption attributes of a switch, and define template sensors
157
130
Note: these values are already divided by 10 for Voltage and Consumption
158
-
1) On some devices, you may find that the energy values are not updating frequently enough by default. If so, set the scan interval (see above) to an appropriate value. Settings below 10 seconds may cause stability issues, 30 seconds is recommended.
131
+
3) On some devices, you may find that the energy values are not updating frequently enough by default. If so, set the scan interval (see above) to an appropriate value. Settings below 10 seconds may cause stability issues, 30 seconds is recommended.
159
132
160
133
```
161
134
sensor:
@@ -197,6 +170,8 @@ logger:
197
170
198
171
* Everything listed in https://github.com/rospogrigio/localtuya-homeassistant/issues/15
199
172
173
+
* Support devices that use Tuya protocol v.3.4
174
+
200
175
# Thanks to:
201
176
202
177
NameLessJedi https://github.com/NameLessJedi/localtuya-homeassistant and mileperhour https://github.com/mileperhour/localtuya-homeassistant being the major sources of inspiration, and whose code for switches is substantially unchanged.
0 commit comments