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

I am having random light on calls for most all the devices not just infibrite. I only have the modem/router that my rpi4 is connected via ethernet cable, I don’t have any repeaters. I tested this morning, I turned off the modem, waited and turned back on. Upon network reconnect no lights came on. however, when I restart HA i can duplicate the random “on” call. I just don’t know what is telling them to turn on. Also, when they turn on, the ones that do turn on all come on always at 56% brightness. I don’t know how to further troubleshoot this?? In the logbook, when I cycle a command it puts my username in the log and when these other light-on call happen there is nothing in the log that shows what turned it on.
image

That is interesting and most annoying.
Again in my case I can restart HA as many times as I want with absolutely no effect on any devices.
Obviously, there is something else going on with yours, since restarting HA causes the issue, but you have also previously indicated that in the morning you have found the lights on, meaning no manual restart was initiated. (noting, if a HA update was available and if you have auto update set, then a restart could occur overnight automatically) . If this is not the case, then at what time do the lights go on overnight, without a restart being initiated, is it always at the exact same time or totally random?
I don’t believe this is your case, but if the device lost power it would then reboot/restart, and depending on how it is set to handle power on state (ie, on, off, or last state) could be an issue.
Do you know if “power on state” is an available setting for your devices?
Some of my devices do have this setting and I always set to last state.

Do you have your lights set as groups?

What makes no sense to me is HA restart replicates the problem.
Are you sure you don’t have any other blueprints or other integrations that could be interfering with your config.? If you do, try disabling them, and then restart HA, to rule them out.

I’m running out of options here.

Let see here…

Random lights are coming on at random times, not just overnight. To my knowledge I do not have any auto updates or restarts set. All the lights are wired into a dumb outlet or wall switch for power. For the “power on state”, I can only see the “power on behavior” in the SmartLife app, I’m unaware of where to find this in HA. And for the power on state, I have set a custom color for the power on behavior so I know if this a power issue, however the lights turn on at 56% and not the custom setting.

I do have lights set up in groups. For the blueprints integrations, I don’t know which one could be interfering? I’ll look into this more. However, I thought the log would tell me what is turning on the device so I can troubleshoot.

Also, I looked in the system log, below, i’m getting a lot of errors.

This error originated from a custom integration.

Logger: custom_components.tuya_local.device
Source: custom_components/tuya_local/device.py:545
Integration: Tuya Local (documentation, issues)
First occurred: October 16, 2023 at 11:46:27 (18395 occurrences)
Last logged: 14:19:03

Failed to fetch device status for Galley 01
Failed to fetch device status for Living room 1
Failed to fetch device status for String TV
Failed to fetch device status for UCL 3
Failed to fetch device status for Living room 7

Also, when i look at the log within the device info window the device is unavailable or unknown for some reason then something turns it on. This is where I am in deeper than what I understand. Is the log telling me the service “Light: Turn on” is doing this? If so, how do I dig into this further?

image

I suggest that you raise a bug issue on TL, since the log is referring to;
Source: custom_components/tuya_local/device.py:545
This line in the code for device.py is;
entity.async_schedule_update_ha_state()

What I don’t understand is does this only happen with TL, what about TUYA (cloud based) on HA?
Also the groups I would try disabling, especially since scene is becoming unknown.

I was having the same issue with LT and thought that moving over to TL would fix the issue. I only used TUYA for a short time and do not recall issues but I switched to LT to get away from the cloud.

Curious, how is myTL code any different from everyone elses that uses TL? I haven’t gone into file editor to change anything?

I tend to agree with you, so it can’t be TL or SL or even Tuya, there must be something with your setup, again try disabling other integration, groups, any schedules, etc…
Is it still happening at random times or is there a pattern/time on a regular basis?

Hi,

Yes, the GitHub page for LocalTuya says that standalone sensors are not currently supported and (as far as I can remember) the sensors.py file isn’t part of the custom component download file. Yes, I could add the relevant code to either in the HA Config files or via downloading the Tuya SDK and adding the sensors.py file to LocalTuya file, or contact the developer and ask them to add each of the different devices. However, given that the Tuya integration automatically adds everything from your Tuya/Smart Life app, including all standalone sensors (such as my temp and humidity sensors), without any setup work or hassle, means that all of the above seems like LocalTuya is more hassle than it’s worth to have things run locally, for me at least.

**Update - The Tuya developers (at Tuya itself) are currently beta testing a new Smart Life integration that works exactly like the current Tuya integration (as in adds every device and scene automatically) but DOESN’T require a Tuya IoT account and the 6 monthly requests for IoT Core access. You only need to enter your User Code (from your Tuya/Smart Life app security settings page) and all devices in the app get added to HA. While it is still in Beta testing you can download it as a custom repository from…

https://github.com/tuya/tuya-smart-life?search=1#smart-life-beta-home-assistant-integration

…I’ve already installed it and it works perfectly.

You can easily get device id’s and local keys with only your account credentials using this python script

LOL…Easy for you…? Are there any instructions on how to use tuya-uncover from a Homeassistant instalation? Yes it would be very helpful to use with Tuya-Local.

You run it from any computer that has python and the instructions are in the readme file

Hello,

It’s been awhile…

So far, the conclusion to my issue has been to turn off the SMARTLIFE app running in the background in the permissions on my phone.

FINGERS CROSSED!!

Still don’t understand why TinyTuya isn’t just built into this integration somehow. Make it prompt for the one key from the Tuya cloud API, have it do all the scanning and fetching of local keys…etc.

1 Like

I don’t get any "dp_id" keys returned in the json when I make this call. I do get a key with chinese text which google translate confirms it matches the name of the action - eg “docking”. Is there something else I need to do? This is on a Lubluelu sl60d.

@umu_ugg has created an excellent LocalTuya fork which allows full auto discovery and local control of sub-devices behind a gateway too!

I can’t get my light working despite acquiring all the data points. The values return with (value:-1), despite this not showing in the tuya developer portal against the data points.

{
  "result": {
    "properties": [
      {
        "code": "switch_led",
        "custom_name": "",
        "dp_id": 20,
        "time": 1705434823728,
        "value": true
      },
      {
        "code": "work_mode",
        "custom_name": "",
        "dp_id": 21,
        "time": 1705434785014,
        "value": "scene"
      },
      {
        "code": "bright_value",
        "custom_name": "",
        "dp_id": 22,
        "time": 1705431400653,
        "value": 701
      },
      {
        "code": "temp_value",
        "custom_name": "",
        "dp_id": 23,
        "time": 1705431402915,
        "value": 758
      },
      {
        "code": "colour_data",
        "custom_name": "",
        "dp_id": 24,
        "time": 1705431364516,
        "value": "00b403e803e8"
      },
      {
        "code": "scene_data",
        "custom_name": "",
        "dp_id": 25,
        "time": 1705412782630,
        "value": "000e0d0000000000000000c80000"
      },
      {
        "code": "countdown",
        "custom_name": "",
        "dp_id": 26,
        "time": 1705412782630,
        "value": 0
      },
      {
        "code": "music_data",
        "custom_name": "",
        "dp_id": 27,
        "time": 1705412780833,
        "value": ""
      },
      {
        "code": "control_data",
        "custom_name": "",
        "dp_id": 28,
        "time": 1705412780833,
        "value": ""
      },
      {
        "code": "power_memory",
        "custom_name": "",
        "dp_id": 33,
        "time": 1705412782734,
        "value": "AAEAAAPoA+gD6AAA"
      },
      {
        "code": "mic_music_data",
        "custom_name": "",
        "dp_id": 42,
        "time": 1705412782630,
        "value": "010000016432000003e8007803e800f003e8003c03e800b403e8012c03e8"
      }
    ]
  },
  "success": true,
  "t": 1705438188949,
  "tid": "c9de147cb4b011ee847d96852008b4f4"

I get permission issue although I am logged into Tuya IoT account. Is there a separate subscription for this logging service?

IMO, like others have said, use the “Tuya” app that comes with HASS if you do not mind using a chinese cloud based app. It works pretty seemlessly and for me was very reliable.
If that bothers you and if you want to try to use a local tuya integration, use “TUYALOCAL” not “localTuya” .
The “Tuya Local” solution has good support and supports many of the Tuya devices and is much much easier to implement. If you have trouvle implementing your device, open a ticket and they are very good at righting a new driver pretty quickly.
I would not use “Local Tuya” in short it is very dificult to set up each device.

Don, I know it’s been a while but did you figure out what to do about this?

After maybe a year, my Atomi-branded string lights developed this problem that is all over the internet wherein one bulb schizes out and everything after it blinks different colors at max brightness, usually at 3 AM so the neighbors are maximally annoyed. Don’t buy Atomi.
So, I looked all over the place and splurged for the Enbrighten Café premium string lights which do seem more heavy duty than the Atomi. Anyway, they’re the dj category and seem to be communicating all their data in a json-formatted line on dp 28 (which according to the charts here should be for debugging). tuyalocal will only turn them on and off and localtuya calls them unavailable.

  "result": {
    "category": "dj",
    "functions": [
      {
        "code": "switch_led",
        "dp_id": 20,
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "countdown_1",
        "dp_id": 26,
        "type": "Integer",
        "values": "{\"unit\":\"s\",\"min\":0,\"max\":86400,\"scale\":0,\"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}}"

EDIT: it looks like “dj” is just code for a light source, not like you’re being the DJ at the party…

Hi all,

I added a LSC smart pet feeder to the Tuya app and noticed that a lot of entities/functions are missing which are available in the smart life app. I got into the API explorer and found the DP’s:

{
  "result": {
    "category": "sp",
    "functions": [
      {
        "code": "basic_flip",
        "desc": "{}",
        "name": "反面翻转",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "motion_sensitivity",
        "desc": "{\"range\":[\"0\",\"1\",\"2\"]}",
        "name": "移动侦测灵敏度",
        "type": "Enum",
        "values": "{\"range\":[\"0\",\"1\",\"2\"]}"
      },
      {
        "code": "basic_nightvision",
        "desc": "{\"range\":[\"0\",\"1\",\"2\"]}",
        "name": "红外夜视",
        "type": "Enum",
        "values": "{\"range\":[\"0\",\"1\",\"2\"]}"
      },
      {
        "code": "sd_format",
        "desc": "{}",
        "name": "存储卡格式化",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "motion_switch",
        "desc": "{}",
        "name": "移动报警开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "record_switch",
        "desc": "{}",
        "name": "SD卡录像开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "record_mode",
        "desc": "{\"range\":[\"1\",\"2\"]}",
        "name": "录像模式",
        "type": "Enum",
        "values": "{\"range\":[\"1\",\"2\"]}"
      }
    ],
    "status": [
      {
        "code": "basic_flip",
        "name": "反面翻转",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "motion_sensitivity",
        "name": "移动侦测灵敏度",
        "type": "Enum",
        "values": "{\"range\":[\"0\",\"1\",\"2\"]}"
      },
      {
        "code": "basic_nightvision",
        "name": "红外夜视",
        "type": "Enum",
        "values": "{\"range\":[\"0\",\"1\",\"2\"]}"
      },
      {
        "code": "sd_storge",
        "name": "获取存储卡容量",
        "type": "String",
        "values": "{\"maxlen\":255}"
      },
      {
        "code": "sd_status",
        "name": "存储卡状态",
        "type": "Integer",
        "values": "{\"min\":1,\"max\":5,\"scale\":0,\"step\":1}"
      },
      {
        "code": "sd_format",
        "name": "存储卡格式化",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "movement_detect_pic",
        "name": "移动检测",
        "type": "Raw",
        "values": "{}"
      },
      {
        "code": "sd_format_state",
        "name": "格式化状态",
        "type": "Integer",
        "values": "{\"unit\":\"\",\"min\":-20000,\"max\":200000,\"scale\":0,\"step\":1}"
      },
      {
        "code": "motion_switch",
        "name": "移动报警开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "record_switch",
        "name": "SD卡录像开关",
        "type": "Boolean",
        "values": "{}"
      },
      {
        "code": "record_mode",
        "name": "录像模式",
        "type": "Enum",
        "values": "{\"range\":[\"1\",\"2\"]}"
      }
    ]
  },
  "success": true,
  "t": 1723719954134,
  "tid": "570f826e5af611ef883136d89ae34f8e"
}

But i don’t see any options in Tuya to add these. I added local tuya but that also doesn’t seem to work, although the option in there so add DP’s. Now here I read people mentioning tuyalocal, but i can only find the integration called localtuya… Does anyone have a link of tuyalocal? or does someone know if these additional DP’s can be added in the tuya integration? Which would have my prefference.

I also created a seperate thread for this which can be found here: Tuya - How to map data points? - Pet feeder

Maybe more people would benefit from this is we can document the eassiest way to add DP’s.

Thanks!