LocalTuya - Using Tuya IoT Platform to obtain not only Local Keys, but also DP (data point) IDs

Thanks @EnsignR ! :clap:
I wish I knew this earlier and that it was in the docs for the localtuya integration… I might add it when this year’s Hacktoberfest comes around :slight_smile:
I too found a few “almost” pages in the API Explorer so I thought the DPs were not there… until I found the right one. It doesn’t help that the names are all cut off and so similar.

1 Like

It seems like the TuyaLocal is now broken and really no longer working, and almost seems like what used to be local is not really so local anymore. I had been using my smart coffee maker for months and up until today didn’t have any major problems. Now the device is just “unavailable” in Home Assistant with no more control. I think I might just cut my losses and get a smart plug and a dumb coffee maker with a toggle switch. :-/

Can’t say I experience the same issue. Every device in LocalTuya (sockets / ledstrips / lightbulb) work just fine.

1 Like

Maybe this is manufacturer related. There are many devices made under all sort of brands that are using Tuya under the hood and maybe it’s a problem with how those companies have implemented Tuya into their devices.

I did manage to just completely remove my device and reinstall the entire Tuya Local integration. Then went through the process of re-adding the device along with all entities, except I missed one(blah). Now it seems to be working again. Perhaps this is also related to the 3.x to 4.x conversion.

Ye that sux, forgetting one. Removing is no issue, but adding is one shot… really annoying. Good to hear it works again!

So I’m thinking from what I saw over on another thread that my device just has a weird wrong setup by the manufacturer.

My in the IoT platform I can’t really get much of the correct data out for my device. Even when I go to device debugging I get nothing for an instruction set. So my testing becomes trial/error on how to configure the DPs. For the most part all I really care about based on what is in the smart controls is just starting the coffee brewing, and knowing when it shut off. That’s why I’m almost considering just getting a dumb coffee maker with a smart plug. :man_shrugging:

Following these instructions, I was able to get my Device ID and Local Key

1 Like

Soo…finally to get LocalKey of tuya device, go to Tuya IoT Platform …Cloud…API Explorer…General Device Capabilities…General Device management…Get Device Information and insert device_id in the field and hit Submit Request.
In the right pane scrool until see "local_key":"your_local_key_for_your_device".
Simple, right?

1 Like

Edit1

As soon j complained i got it working…great video

was hoping it is that simpel as well, but i was not able to get that done…i am already failing at the tuya web page…got an account but no devices in there and cant find anything that could give me a key or so…

I tried using the Get Device Specification Attribute for my Lydsto vacuum, and it returns some data, but the DP IDs don’t match up at all with what local tuya shows me.

Get Device Specification Attribute:

{
  "result": {
    "category": "sd",
    "functions": [
      {
        "code": "power",
        "dp_id": 1,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "power_go",
        "dp_id": 2,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "mode",
        "dp_id": 3,
        "type": "Enum",
        "values": "{\"range\":[\"standby\",\"smart\",\"chargego\"]}"
      },
      {
        "code": "seek",
        "dp_id": 13,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "reset_map",
        "dp_id": 129,
        "type": "Boolean",
        "values": "{}"
      },
     ...
}

Local Tuya

1 Like

Hi there. Was Hoping you could lend me some assistance.
I’m totally lost and Very Frustrated here on this whole Device Control Page or I guess DP?
I’ve spent hours trying to figure out why my LocalTuya Devices are not correct.
I’m 71 but still pretty savvy in technology… But this Integration seems overly complicated. LoL
Example: All my Tuya Color Bulbs show up as a Switch. They turn On/Off but no other features like Color, or Dimming etc… Also Tuya Smart Plugs with Energy Monitoring don’t show up.
I think it has to do with Dozens of settings that have no explanation.
I’m savvy using the GUI Integrations and do have some limited experience in yaml as I’ve integrated my DSC / Envisalink security system, and have written several Automation’s, But again this Integration is way overly complicated.
Anyway Sorry for the long Rant here, but maybe you can help.
BTW: Everything works perfectly in the Smart Life App and on Alexa.
Hope you can help. Thanks in advance…

Hello…
I just watched your great YouTube Tutorial. I’m finding this LocalTuya Integration to be Way Overly complicated. I now have 17 Tuya devices Installed and as of 12/01/2022 I’m running the latest up to date HS. However LocalTuya does not address the specifics of my Devices.
Example: Color Light only has On/Off and as I now understand this DP-ID’s is the Problem ??
I would gretly apperciate any help you can provide as I’ve spent many hours experimenting on my own. I did manage to look up and find what I think is the DP-ID’s
I’ve Pasted the data below. Can you please advise if this is correct, and what data I need to fix the one light I am working on to learn. Called Bed 3
Thank you very much…

{
“result”: {
“category”: “dj”,
“functions”: [
{
“code”: “switch_led”,
“dp_id”: 20,
“type”: “Boolean”,
“values”: “{}”
},
{
“code”: “work_mode”,
“dp_id”: 21,
“type”: “Enum”,
“values”: “{“range”:[“white”,“colour”,“scene”,“music”]}”
},
{
“code”: “bright_value_v2”,
“dp_id”: 22,
“type”: “Integer”,
“values”: “{“min”:10,“max”:1000,“scale”:0,“step”:1}”
},
{
“code”: “temp_value_v2”,
“dp_id”: 23,
“type”: “Integer”,
“values”: “{“min”:0,“max”:1000,“scale”:0,“step”:1}”
},
{
“code”: “colour_data_v2”,
“dp_id”: 24,
“type”: “Json”,
“values”: “{“h”:{“min”:0,“scale”:0,“unit”:”",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}}"
},
{
“code”: “scene_data_v2”,
“dp_id”: 25,
“type”: “Json”,
“values”: “{“scene_num”:{“min”:1,“scale”:0,“max”:8,“step”:1},“scene_units”: {“unit_change_mode”:{“range”:[“static”,“jump”,“gradient”]},“unit_switch_duration”:{“min”:0,“scale”:0,“max”:100,“step”:1},“unit_gradient_duration”:{“min”:0,“scale”:0,“max”:100,“step”:1},“bright”:{“min”:0,“scale”:0,“max”:1000,“step”:1},“temperature”:{“min”:0,“scale”:0,“max”:1000,“step”:1},“h”:{“min”:0,“scale”:0,“unit”:”",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}}}"
},
{
“code”: “countdown_1”,
“dp_id”: 26,
“type”: “Integer”,
“values”: “{“unit”:“s”,“min”:0,“max”:86400,“scale”:0,“step”:1}”
},
{
“code”: “music_data”,
“dp_id”: 27,
“type”: “Json”,
“values”: “{“change_mode”:{“range”:[“direct”,“gradient”]}, “bright”:{“min”:0,“scale”:0,“unit”:”",“max”:1000,“step”:1}, “temperature”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}, “h”:{“min”:0,“scale”:0,“unit”:"",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1}}"
},
{
“code”: “control_data”,
“dp_id”: 28,
“type”: “Json”,
“values”: “{“change_mode”:{“range”:[“direct”,“gradient”]}, “bright”:{“min”:0,“scale”:0,“unit”:”",“max”:1000,“step”:1}, “temperature”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}, “h”:{“min”:0,“scale”:0,“unit”:"",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1}}"
},
{
“code”: “power_memory”,
“dp_id”: 33,
“type”: “Raw”,
“values”: “{}”
}
],
“status”: [
{
“code”: “switch_led”,
“dp_id”: 20,
“type”: “Boolean”,
“values”: “{}”
},
{
“code”: “work_mode”,
“dp_id”: 21,
“type”: “Enum”,
“values”: “{“range”:[“white”,“colour”,“scene”,“music”]}”
},
{
“code”: “bright_value_v2”,
“dp_id”: 22,
“type”: “Integer”,
“values”: “{“min”:10,“max”:1000,“scale”:0,“step”:1}”
},
{
“code”: “temp_value_v2”,
“dp_id”: 23,
“type”: “Integer”,
“values”: “{“min”:0,“max”:1000,“scale”:0,“step”:1}”
},
{
“code”: “colour_data_v2”,
“dp_id”: 24,
“type”: “Json”,
“values”: “{“h”:{“min”:0,“scale”:0,“unit”:”",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}}"
},
{
“code”: “scene_data_v2”,
“dp_id”: 25,
“type”: “Json”,
“values”: “{“scene_num”:{“min”:1,“scale”:0,“max”:8,“step”:1},“scene_units”: {“unit_change_mode”:{“range”:[“static”,“jump”,“gradient”]},“unit_switch_duration”:{“min”:0,“scale”:0,“max”:100,“step”:1},“unit_gradient_duration”:{“min”:0,“scale”:0,“max”:100,“step”:1},“bright”:{“min”:0,“scale”:0,“max”:1000,“step”:1},“temperature”:{“min”:0,“scale”:0,“max”:1000,“step”:1},“h”:{“min”:0,“scale”:0,“unit”:”",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}}}"
},
{
“code”: “countdown_1”,
“dp_id”: 26,
“type”: “Integer”,
“values”: “{“unit”:“s”,“min”:0,“max”:86400,“scale”:0,“step”:1}”
},
{
“code”: “music_data”,
“dp_id”: 27,
“type”: “Json”,
“values”: “{“change_mode”:{“range”:[“direct”,“gradient”]}, “bright”:{“min”:0,“scale”:0,“unit”:”",“max”:1000,“step”:1}, “temperature”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}, “h”:{“min”:0,“scale”:0,“unit”:"",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1}}"
},
{
“code”: “control_data”,
“dp_id”: 28,
“type”: “Json”,
“values”: “{“change_mode”:{“range”:[“direct”,“gradient”]}, “bright”:{“min”:0,“scale”:0,“unit”:”",“max”:1000,“step”:1}, “temperature”:{“min”:0,“scale”:0,“unit”:"",“max”:1000,“step”:1}, “h”:{“min”:0,“scale”:0,“unit”:"",“max”:360,“step”:1},“s”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1},“v”:{“min”:0,“scale”:0,“unit”:"",“max”:255,“step”:1}}"
},
{
“code”: “power_memory”,
“dp_id”: 33,
“type”: “Raw”,
“values”: “{}”
}
]
},
“success”: true,
“t”: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
“tid”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
}

So my question is what goes where??
I’ve experimented and at least HA knows it’s a light not a switch, and I see the Color wheel, but still doesn;t change colors or dimm…

Good day,
So first thing is the “original Localtuya” integration wont work if your device is new or on new firmware. Check this thread. Someone has forked it and it adds the 3.4 protocol.

However, in my case I added the “new” integration and I have a light with same dp-id as yours and whilst I was able to add it, i cant control it.
I can only turn it off.

So unfortunately tuya seems to be “broken”

How do I add the pd-id’s as I am getting the same errors as others in the thread, I added my first 4 switches no problem, but now each and every switch I try to add I am getting the error.

I followed the steps to get the dp-ids from the API, but no idea on how to manually set them in Home Assistant.
Thanks in advance!

when you’re doing the config flow part, there’s a space for ‘DPS’.
you add them there like this: 20,21,22,23,24

1 Like

Yikes… not good.
So far I’ve not been successful getting any of my 17 devices to fully run Localtuya, only simple switches but thinks lights are switches. I’ve watched many videos but the DP ids seem Overly complicated. That said I’m still learning Localtuya but wondering if it’s worth it. LoL
Curious, is this because Tuya doesn’t want their devices to run locally, or because they are simply upgrading their devices with more added features.

@PCman yes, LocalTuya is rather involved because both Tuya and FOSS are intended for professionals or experienced amateurs. Bottom line is that you are free to not use it if you choose.

I also found it confusing, but once the pieces fall into place it’s not so bad. I made a document summarising the details of my Tuya devices, and the first thing was to make a table of the dp_ids from the Tuya website, like:

code            dp_id   type       values
switch_led,       20,   Boolean,
work_mode,        21,   Enum,      "white”,“colour”,“scene”,“music”
bright_value_v2,  22,   Integer,   10-1000
countdown_1,      26,   Integer,   0-86400

Note that there are actually 2 lists… “Functions” are the dp_ids you can change the values of, and most of them (and a few others maybe) are also listed under the “status” section.

You say it’s a light … but dp_id 27 is “music_data”, wow that’s odd. A christmas fairy light set ?

Anyway LocalTuya is somewhat odd in having to repeat part of the process for each dp_id you want to view/change for a device.

  1. select the device to add or edit, enter its name, local_key, etc
  2. The first time you see the “Entity Type selection” box, you just select the base entity type (probably a “switch”) and [Submit]
  3. configure details of that entity - dp_id, friendly name, etc
  4. this is the tricky bit - you will be presented the Entity Type selection" window again, and it also has a ticked check box “Do not add any more entities”. UN-tick the box and select the entity type for the next dp_id you wish to create a HA entity for, click [submit] and go back to step 3. Repeat until all entities have been created.

For a more complete description see message 50 in Energy consumption and Arlec Grid Connect (Tuya) smart plug

Yes, it is clunky, but LocalTuya does not know every device and what dp_ids it has, and this approach provides flexibility. I just wish the box defaulted to un-ticked.

Oh, and lights are essentially switches - the most basic light only allows you to turn_on and turn_off.

@juan11perez I tried entering dp_ids like that, but found that didn’t give easy access to them.

@PCman Tuya are in business of providing firmware to device manufacturers, so yes they do want cloud control. And yes their platform makes it possible for them and their clients (device manufacturers) to add new dp_ids for whatever new features … like most of the ones in your lights. I assume you didn’t get a comprehensive manual listing all the options :wink:

3 Likes

Hi, just trying to view dpids for my switch/lights
But why are the dpid not listed?

Get Device Specification Attribute:

{
  "result": {
    "category": "kg",
    "functions": [
      {
        "code": "switch_1",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "countdown_1",
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      },
      {
        "code": "relay_status",
        "type": "Enum",
        "values": "{\"range\":[\"power_off\",\"power_on\",\"last\"]}"
      },
      {
        "code": "cycle_time",
        "type": "String",
        "values": "{}"
      },
      {
        "code": "random_time",
        "type": "String",
        "values": "{}"
      },
      {
        "code": "switch_inching",
        "type": "String",
        "values": "{}"
      }
    ],
    "status": [
      {
        "code": "switch_1",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "countdown_1",
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"step\":1}"
      },
      {
        "code": "relay_status",
        "type": "Enum",
        "values": "{\"range\":[\"power_off\",\"power_on\",\"last\"]}"
      },
      {
        "code": "cycle_time",
        "type": "String",
        "values": "{}"
      },
      {
        "code": "random_time",
        "type": "String",
        "values": "{}"
      },
      {
        "code": "switch_inching",
        "type": "String",
        "values": "{}"
      }
    ]
  },
  "success": true,
  "t": 1670556389606,
  "tid": "4546eb01777111ed9b174e03f8c0f22a"
}

Yep, that gave me quite a bit of grief !
There are actually two entries in that menu with the same name - except one uses initial capital letters and the other doesn’t.
Screenshot from 2022-12-09 14-40-01

In the API Explorer window’s leftmost menu, open “Smart Home Device System” then “Device Control” (near the bottom) menu and select “Get Device Specific…” (note the capital letters).

6 Likes

Thanks! Got the dpids now