2020-07-11 22:50:17 +02:00
Tuya MCU
========
.. seo ::
:description: Instructions for setting up the Tuya component.
:image: tuya.png
The `` tuya `` component creates a serial connection to the Tuya MCU for platforms to use.
.. figure :: /images/tuya.png
:align: center
:width: 40%
The `` tuya `` serial component requires a :ref: `UART bus <uart>` to be configured.
Put the `` tuya `` component in the config and it will list the possible devices for you in the config log.
.. code-block :: yaml
# Register the Tuya MCU connection
tuya:
2024-05-07 07:40:12 +02:00
2020-07-11 22:50:17 +02:00
Here is an example output for a Tuya fan controller:
.. code-block :: text
[12:39:45][C][tuya:023]: Tuya:
[12:39:45][C][tuya:032]: Datapoint 1: switch (value: ON)
[12:39:45][C][tuya:036]: Datapoint 3: enum (value: 1)
[12:39:45][C][tuya:036]: Datapoint 6: enum (value: 0)
[12:39:45][C][tuya:034]: Datapoint 7: int value (value: 0)
[12:39:45][C][tuya:032]: Datapoint 9: switch (value: OFF)
[12:39:45][C][tuya:046]: Product: '{"p":"hqq73kftvzh8c92u","v":"1.0.0","m":0}'
2022-05-15 21:44:18 +02:00
Here is another example output for a Tuya ME-81H thermostat:
.. code-block :: text
[08:51:09][C][tuya:032]: Tuya:
[08:51:09][C][tuya:043]: Datapoint 1: switch (value: ON)
[08:51:09][C][tuya:045]: Datapoint 24: int value (value: 220)
[08:51:09][C][tuya:045]: Datapoint 16: int value (value: 22)
[08:51:09][C][tuya:049]: Datapoint 2: enum (value: 1)
[08:51:09][C][tuya:045]: Datapoint 19: int value (value: 40)
[08:51:09][C][tuya:045]: Datapoint 101: int value (value: 1)
[08:51:09][C][tuya:045]: Datapoint 27: int value (value: -2)
[08:51:09][C][tuya:049]: Datapoint 43: enum (value: 1)
[08:51:09][C][tuya:049]: Datapoint 102: enum (value: 1)
[08:51:09][C][tuya:051]: Datapoint 45: bitmask (value: 0)
[08:51:09][C][tuya:043]: Datapoint 10: switch (value: ON)
[08:51:09][C][tuya:041]: Datapoint 38: raw (value: 06.00.14.08.00.0F.0B.1E.0F.0C.1E.0F.11.00.16.16.00.0F.08.00.16.17.00.0F (24))
[08:51:09][C][tuya:049]: Datapoint 36: enum (value: 1)
[08:51:09][C][tuya:057]: GPIO Configuration: status: pin 14, reset: pin 0 (not supported)
[08:51:09][C][tuya:061]: Status Pin: GPIO14
[08:51:09][C][tuya:063]: Product: '{"p":"gogb05wrtredz3bs","v":"1.0.0","m":0}'
2020-11-10 23:32:33 +01:00
Configuration variables:
------------------------
2022-02-10 23:10:43 +01:00
- **time_id** (*Optional* , :ref: `config-id` ): Some Tuya devices support obtaining local time from ESPHome.
2022-12-22 23:57:01 +01:00
Specify the ID of the :doc: `time/index` which will be used.
2020-11-10 23:32:33 +01:00
2022-05-15 21:44:18 +02:00
- **status_pin** (*Optional* , :ref: `Pin Schema <config-pin_schema>` ): Some Tuya devices support WiFi status reporting ONLY through gpio pin.
Specify the pin reported in the config dump or leave empty otherwise.
More about this `here <https://developer.tuya.com/en/docs/iot/tuya-cloud-universal-serial-port-access-protocol?id=K9hhi0xxtn9cb#title-6-Query%20working%20mode> `__ .
2020-12-03 19:17:36 +01:00
- **ignore_mcu_update_on_datapoints** (*Optional* , list): A list of datapoints to ignore MCU updates for. Useful for certain broken/erratic hardware and debugging.
2020-11-10 23:32:33 +01:00
2021-11-29 20:08:56 +01:00
Automations:
2022-04-03 09:30:25 +02:00
- **on_datapoint_update** (*Optional* ): An automation to perform when a Tuya datapoint update is received. See :ref: `tuya-on_datapoint_update` .
2021-11-29 20:08:56 +01:00
Tuya Automation
---------------
.. _tuya-on_datapoint_update:
`` on_datapoint_update ``
***** ***** ***** ***** ***
2022-02-10 23:10:43 +01:00
This automation will be triggered when a a Tuya datapoint update is received.
A variable `` x `` is passed to the automation for use in lambdas.
2021-11-29 20:08:56 +01:00
The type of `` x `` variable is depending on `` datapoint_type `` configuration variable:
- *raw* : `` x `` is `` std::vector<uint8_t> ``
- *string* : `` x `` is `` std::string ``
- *bool* : `` x `` is `` bool ``
- *int* : `` x `` is `` int ``
- *uint* : `` x `` is `` uint32_t ``
- *enum* : `` x `` is `` uint8_t ``
- *bitmask* : `` x `` is `` uint32_t ``
- *any* : `` x `` is :apistruct: `tuya::TuyaDatapoint`
.. code-block :: yaml
tuya:
on_datapoint_update:
- sensor_datapoint: 6
datapoint_type: raw
then:
- lambda: |-
2022-10-25 01:06:07 +02:00
ESP_LOGD("main", "on_datapoint_update %s", format_hex_pretty(x).c_str());
2021-11-29 20:08:56 +01:00
id(voltage).publish_state((x[0] << 8 | x[1]) * 0.1);
id(current).publish_state((x[3] << 8 | x[4]) * 0.001);
id(power).publish_state((x[6] << 8 | x[7]) * 0.1);
- sensor_datapoint: 7 # sample dp
datapoint_type: string
then:
- lambda: |-
ESP_LOGD("main", "on_datapoint_update %s", x.c_str());
- sensor_datapoint: 8 # sample dp
datapoint_type: bool
then:
- lambda: |-
2022-02-10 23:10:43 +01:00
ESP_LOGD("main", "on_datapoint_update %s", ONOFF(x));
2021-11-29 20:08:56 +01:00
- sensor_datapoint: 6
datapoint_type: any # this is optional
then:
- lambda: |-
if (x.type == tuya::TuyaDatapointType::RAW) {
2022-10-25 01:06:07 +02:00
ESP_LOGD("main", "on_datapoint_update %s", format_hex_pretty(x.value_raw).c_str());
2021-11-29 20:08:56 +01:00
} else {
ESP_LOGD("main", "on_datapoint_update %hhu", x.type);
}
Configuration variables:
2022-04-03 09:30:25 +02:00
- **sensor_datapoint** (**Required** , int): The datapoint id number of the sensor.
- **datapoint_type** (**Required** , string): The datapoint type one of *raw* , *string* , *bool* , *int* , *uint* , *enum* , *bitmask* or *any* .
2021-11-29 20:08:56 +01:00
- See :ref: `Automation <automation>` .
2020-07-11 22:50:17 +02:00
See Also
--------
- :doc: `/components/fan/tuya`
- :doc: `/components/light/tuya`
2021-08-03 13:34:13 +02:00
- :doc: `/components/switch/tuya`
- :doc: `/components/climate/tuya`
- :doc: `/components/binary_sensor/tuya`
2021-11-03 19:59:09 +01:00
- :doc: `/components/sensor/tuya`
2021-11-29 20:08:56 +01:00
- :doc: `/components/text_sensor/tuya`
2024-08-22 02:59:38 +02:00
- :doc: `/components/number/tuya`
2020-07-11 22:50:17 +02:00
- :apiref: `tuya/tuya.h`
- :ghedit: `Edit`