TuyaLocal - Match ID to sensor type etc

Hi folks,

After a bit of battle I have managed to get TuyaLocal to see my two circuit breakers, now the question, when adding it as a new integration you have to add each id separately, is there any way to determine which ID correspond to what?

So far all I could figure out was that ID1 = Power On/Off status, and to change state, so for that the binary sensor works just fine, and if I configure the others as sensor then I get values, but now trying to work out what each ID represent.

The other ID’s are 1, 9 , 18, 19, 20, 21, 22, 23, 24, 25

Found so far that
1 is on / off state of the switch
20 is voltage

Welcome!

I’ve had good success using Jason Cox’s tinytuya package to explore and control Tuya devices locally. Link and a short example for querying a Atomi Desktop Heater.

Tuya is a real wild west, tinytuya does a good job of mashing together the data from the Tuya developer cloud and the device to display somewhat useful names, types and ranges for those data points that the vendor has documented with Tuya. Unfortunately for some devices, this is incomplete. The Atomi Heater example below shows this. If I use the tinytuya functions to query the heater locally, there are three data points that are undocumented on the Tuya web site. So you now have to do you best reverse engineering / sherlock holmes work to figure out these additional entities. Often you can ‘operate’ the device using tinytuya with just the data points that are documented at the Tuya cloud. But the other ones can be useful. For example, the undocumented data points for the Atomi heater control/report: turn off count down (11) maybeswitching heat range between fahrenheit and celsius (12) , reporting that the heater had fallen over (103) and something I have yet to decode (102)…

Additionally, I have found that the reported data point values can be incomplete, so there may be more ‘setable’ values for a data point that is shown.

A bit of warning, I have yet to brick a Tuya device by setting a data point wrong, but that is not inconceivable to occur. So far the worst I have done is make it necessary to power cycle the Tuya device to get it back and happy after a incorrect setting of a dps value.

Good hunting!

Example of data points returned by a query to the device locally:

Received Payload: {'dps': {'1': False, '2': 83, '3': 58, '4': 'high', '8': False, '10': True, '11': '0h', '12': 0, '102': False, '103': False}}

-----
Example program to document data points know by the Tuya developer cloud:

#! /usr/bin/env python3
# or force unbuffered stdout output for piping to another program
####! /usr/bin/env -S python3 -u
# q.py
#

import tinytuya

import json
import pprint

c = tinytuya.Cloud(
        apiRegion="us",
        apiKey="aaaaaaaaaaaaa",
        apiSecret="bbbbbbbbbbb",
        apiDeviceID="cccccccccccc")  # any of your enabled devices

# Display list of devices
# devices = c.getdevices()
# print("Device List: %r" % devices)

# Select a Device ID to Test
id = "dddddddddddddddd"

# Display DPS IDs of Device
result = c.getdps(id)

print(json.dumps(result, sort_keys=False, indent=4))

----------
Output from above program for Atomi Desktop Heater :
https://www.amazon.com/Atomi-Smart-Portable-Tabletop-Heater/dp/B08B1W7ZY7/

[email protected]:~/tinytuya$ ./q.py
{
    "result": {
        "category": "qn",
        "functions": [
            {
                "code": "switch",
                "dp_id": 1,
                "type": "Boolean",
                "values": "{}"
            },
            {
                "code": "temp_set",
                "dp_id": 2,
                "type": "Integer",
                "values": "{\"unit\":\"\u2109\",\"min\":60,\"max\":86,\"scale\":0,\"step\":1}"
            },
            {
                "code": "mode",
                "dp_id": 4,
                "type": "Enum",
                "values": "{\"range\":[\"auto\"]}"
            },
            {
                "code": "shake",
                "dp_id": 8,
                "type": "Boolean",
                "values": "{}"
            },
            {
                "code": "light",
                "dp_id": 10,
                "type": "Boolean",
                "values": "{}"
            }
        ],
        "status": [
            {
                "code": "switch",
                "dp_id": 1,
                "type": "Boolean",
                "values": "{}"
            },
            {
                "code": "temp_set",
                "dp_id": 2,
                "type": "Integer",
                "values": "{\"unit\":\"\u2109\",\"min\":60,\"max\":86,\"scale\":0,\"step\":1}"
            },
            {
                "code": "temp_current",
                "dp_id": 3,
                "type": "Integer",
                "values": "{\"unit\":\"\u2109\",\"min\":32,\"max\":122,\"scale\":0,\"step\":1}"
            },
            {
                "code": "mode",
                "dp_id": 4,
                "type": "Enum",
                "values": "{\"range\":[\"auto\"]}"
            },
            {
                "code": "shake",
                "dp_id": 8,
                "type": "Boolean",
                "values": "{}"
            },
            {
                "code": "light",
                "dp_id": 10,
                "type": "Boolean",
                "values": "{}"
            },
            {
                "code": "countdown_left",
                "dp_id": 12,
                "type": "Integer",
                "values": "{\"unit\":\"h\",\"min\":0,\"max\":12,\"scale\":0,\"step\":1}"
            }
        ]
    },
    "success": true,
    "t": 1643664658906
}

1 Like

Thanks let me try that. From the initial look it should be easy to match the ID to what it is, but it appears that only the switch (ID1) and voltage (ID20) is updating. To me it looks like ID 22 should be power in watts, but it is stuck on the first value retrieved and does not update which makes life a lot more difficult.

I must still try the Python script, but using the API directly on iot.tuya.com, when you query the device status and paraments the following is returned.

{
“result”: [
{
“code”: “switch_1”,
“value”: true
},
{
“code”: “countdown_1”,
“value”: 0
},
{
“code”: “add_ele”,
“value”: 100
},
{
“code”: “cur_current”,
“value”: 12926
},
{
“code”: “cur_power”,
“value”: 30437
},
{
“code”: “cur_voltage”,
“value”: 2342
}

I have also played with switching the device on and off under load, on the API only the socket status changes constantly and in real time, the other values not, yet the app updates in realtime.

From the title of you post, I thought you were interested in controlling and reading from the Tuya device locally, not from the cloud. If you interest is local control, the read through tinytuya examples. And look at the key difference of what is returned by the python example I showed and what you got the developer cloud, again from the title of your post, thought you wanted to find the names, types and ranges for each data point.

I am after finding out which data points, but it does matter where I read it from, have just installed Python to try this other script and see what it shows.

Neither Tuya or LocalTuya currently returns any realtime values other than voltage and socket state.





“result”: {
“category”: “cz”,
“functions”: [
{
“code”: “switch_1”,
“dp_id”: 1,
“type”: “Boolean”,
“values”: “{}”
},
{
“code”: “switch_2”,
“dp_id”: 2,
“type”: “Boolean”,
“values”: “{}”
},
{
“code”: “switch_3”,
“dp_id”: 3,
“type”: “Boolean”,
“values”: “{}”
},
{
“code”: “switch_usb1”,
“dp_id”: 7,
“type”: “Boolean”,
“values”: “{}”
},
{
“code”: “countdown_1”,
“dp_id”: 101,
“type”: “Integer”,
“values”: “{“unit”:“秒”,“min”:0,“max”:86400,“scale”:0,“step”:1}”
},
{
“code”: “countdown_2”,
“dp_id”: 102,
“type”: “Integer”,
“values”: “{“unit”:“秒”,“min”:0,“max”:86400,“scale”:0,“step”:1}”
},
{
“code”: “countdown_3”,
“dp_id”: 103,
“type”: “Integer”,
“values”: “{“unit”:“秒”,“min”:0,“max”:86400,“scale”:0,“step”:1}”
},
{
“code”: “countdown_usb1”,
“dp_id”: 105,
“type”: “Integer”,
“values”: “{“unit”:“秒”,“min”:0,“max”:86400,“scale”:0,“step”:1}”
}

I guess you have tried to “restart” HA after adding the devices ?

So the answer it clearly stated on the link shared above for TinyTuya! The ID’s important to me is 18, 19 and 20, which is current, power and voltage.

Can You “Mark” the right Answer, as “Solved” ?