Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble connecting to strip light #580

Open
4JX opened this issue Jan 11, 2025 · 12 comments
Open

Trouble connecting to strip light #580

4JX opened this issue Jan 11, 2025 · 12 comments
Labels
tuya_device Support for specific Tuya Devices

Comments

@4JX
Copy link

4JX commented Jan 11, 2025

Having some issues getting a LED strip to play with this library. The device seems completely unresponsive to anything but the app.

A normal scan returns 0 devices found. As for a force scan, it remains unmatched:

» python3 -m tinytuya scan -force 192.168.1.0/24      

TinyTuya (Tuya device scanner) [1.16.0]
...        
Unknown v?? Device   Product ID = ?  [Failed to Force-Scan]:
    Address = 192.168.1.19   Device ID =  (len:0)  Local Key =   Version = ??  Type = default, MAC = 
    Polling 192.168.1.19 Failed: No matching key found
Scan completed in 18.038

I know for a fact that this is the device I want to connect to, since the MAC address shown in devices.json matches the one from

» arp -a | rg -i ab:cd
? (192.168.1.19) at --- [ether] on ---

If I try to connect to it manually with the information from devices.json it also doesn't seem to work either. (Current Status: {'Error': 'Unexpected Payload from Device', 'Err': '904', 'Payload': None})

import tinytuya

DEVICEID = "Foo"
DEVICEKEY = "Foo2"

# tinytuya.set_debug(True)

d = tinytuya.BulbDevice(DEVICEID, "192.168.1.19", DEVICEKEY)
d.set_socketPersistent(True)

data = d.status()
print(f"\nCurrent Status: {data!r}")

Am I using the wrong device type? Are strip lights supported?
Device is: https://www.amazon.com/Lanmonlily-Corner-Million-Control-Bedroom/dp/B0DB1739S4

@uzlonewolf
Copy link
Collaborator

Yeah, I'd try using different versions. In order from most likely to work to least likely, try: 3.3 3.5 3.4 and 3.2

d = tinytuya.BulbDevice(DEVICEID, "192.168.1.19", DEVICEKEY, version=3.3)
print(d.status())

@4JX
Copy link
Author

4JX commented Jan 11, 2025

Aha, 3.5 works, just didn't see that version listed anywhere in my searches.

» python ./tuya.py
{'dps': {'20': True, '21': 'colour', '24': '003203e803e8', '26': 0}}

Turning off and on works, and so does setting a solid color. I assume that if I want to address individual leds I'll have to play with the payload?

Also, is the maximum speed at which it reacts limited by the network connectivity? It likes to take its time with each step. Looks like whatever chip this has can't keep up with getting spammed by set color requests :b, it freezes the entire device.

@uzlonewolf
Copy link
Collaborator

If you're changing the color in a loop or something then adding persist=True will greatly speed things up as without it it makes a new connection, performs a 3-way handshake, sends the new color, and disconnects every time you send a color change command. The only downside is you need to send something every ~45 seconds or so or the device will close the connection on you; the monitor example uses heartbeat requests to keep the connection open.

d = tinytuya.BulbDevice(DEVICEID, "192.168.1.19", DEVICEKEY, version=3.5, persist=True)

@4JX
Copy link
Author

4JX commented Jan 11, 2025

If you're changing the color in a loop or something

Kind of, was trying to find if I could custom animate it (to serve as some display ambient light)

then adding persist=True will greatly speed things up

Ah yeah I do have that. Seems to hang regardless if I change it faster than every 10ms. For slower times it takes considerably longer than "sleep time*iteration count", but it works.

At that point its probably just my connection, the hardware or something of the sorts and not a library issue.

@jasonacox jasonacox added the tuya_device Support for specific Tuya Devices label Jan 11, 2025
@jasonacox
Copy link
Owner

if I change it faster than every 10ms

I don't think even the app or cloud controls could move that fast. If you need quick transitions, you should look to scene settings (see https://github.com/jasonacox/tinytuya/blob/master/examples/bulb-scenes.py). It requires you to know in advance what color shape you want, but it will allow faster transitions.

@uzlonewolf
Copy link
Collaborator

Music mode could be another option though I don't know if this particular device supports it.

This device looks interesting so I went ahead and ordered one myself, should be here Monday.

@4JX
Copy link
Author

4JX commented Jan 11, 2025

I don't think even the app or cloud controls could move that fast.

No worries, it was given as a gift so I figured I might as well toy with it.

This device looks interesting so I went ahead and ordered one myself, should be here Monday.

Works well for what it is, though its probably a tad expensive.

It does support music mode (if a bit shoddily due to the mic positioning), and then some:
*Chinese translated

{
  "modelId": "e1kem6ns",
  "services": [
    {
      "actions": [],
      "code": "",
      "description": "",
      "events": [],
      "name": "",
      "properties": [
        {"abilityId": 20, "accessMode": "rw", "code": "switch_led", "description": "", "extensions": {"iconName": "icon-dp_power", "attribute": "643"}, "name": "Switch", "typeSpec": {"type": "bool"}},
        {"abilityId": 21, "accessMode": "rw", "code": "work_mode", "description": "", "extensions": {"iconName": "icon-dp_mode", "attribute": "640"}, "name": "Mode", "typeSpec": {"type": "enum", "range": ["white", "colour", "scene", "music"]}},
        {"abilityId": 24, "accessMode": "rw", "code": "colour_data", "description": "Type: String;\\nValue: 000011112222;\\n0000: H (Hue: 0-360, 0X0000-0X0168);\\n1111: S (Saturation: 0-1000, 0X0000-0X03E8);\\n2222: V (Brightness: 0-1000, 0X0000-0X03E8)", "extensions": {"iconName": "icon-yanse", "attribute": "512"}, "name": "Color Light", "typeSpec": {"type": "string", "maxlen": 255}},
        {"abilityId": 26, "accessMode": "rw", "code": "countdown", "description": "", "extensions": {"iconName": "icon-dp_time2", "attribute": "640"}, "name": "Countdown", "typeSpec": {"type": "value", "max": 86400, "min": 0, "scale": 0, "step": 1, "unit": "s"}},
        {"abilityId": 27, "accessMode": "wr", "code": "music_data", "description": "Type: String;\\nValue: 011112222333344445555;\\n0: Change method, 0 means direct output, 1 means gradual change;\\n1111: H (Hue: 0-360, 0X0000-0X0168);\\n2222: S (Saturation: 0-1000, 0X0000-0X03E8);\\n3333: V (Brightness: 0-1000, 0X0000-0X03E8);\\n4444: White light brightness (0-1000);\\n5555: Color temperature value (0-1000)", "extensions": {"iconName": "icon-dp_mic", "attribute": "640"}, "name": "Music Rhythm", "typeSpec": {"type": "string", "maxlen": 255}},
        {"abilityId": 28, "accessMode": "wr", "code": "control_data", "description": "Type: String;\\nValue: 011112222333344445555;\\n0: Change method, 0 means direct output, 1 means gradual change;\\n1111: H (Hue: 0-360, 0X0000-0X0168);\\n2222: S (Saturation: 0-1000, 0X0000-0X03E8);\\n3333: V (Brightness: 0-1000, 0X0000-0X03E8);\\n4444: White light brightness (0-1000);\\n5555: Color temperature value (0-1000)", "extensions": {"iconName": "icon-setting", "attribute": "1024"}, "name": "Adjustment", "typeSpec": {"type": "string", "maxlen": 255}},
        {"abilityId": 51, "accessMode": "rw", "code": "dreamlight_scene_mode", "description": "Specifically for the colorful light strip scene", "extensions": {"iconName": "icon-dp_mode", "attribute": "640"}, "name": "Colorful Scene", "typeSpec": {"type": "raw", "maxlen": 128}},
        {"abilityId": 52, "accessMode": "rw", "code": "dreamlightmic_music_data", "description": "Specifically for the local music rhythm of the colorful light strip", "extensions": {"iconName": "icon-dp_mic", "attribute": "128"}, "name": "Colorful Local Music Rhythm", "typeSpec": {"type": "raw", "maxlen": 128}},
        {"abilityId": 61, "accessMode": "rw", "code": "paint_colour_data", "description": "Specifically for dimming and coloring of the colorful light strip. The protocol only displays color light and color card mode. If the adjustment mode is white light, then byte 5 is 00 (paint bucket), bytes 6 and 7 are brightness, bytes 8 and 9 are color temperature;\\nIf the adjustment mode is a combination mode, then byte 5 is 00, bytes 6-11 are HSV.", "extensions": {"iconName": "icon-dp_circle", "attribute": "512"}, "name": "Color Mixing", "typeSpec": {"type": "raw", "maxlen": 128}}
      ]
    }
  ]
}

In any case my original issue is solved, so this would be fine to close.

@uzlonewolf
Copy link
Collaborator

That property list is interesting, which endpoint did you grab them from?

@4JX
Copy link
Author

4JX commented Jan 11, 2025

Saw it mentioned in an issue here and over at HA. In tuya's dev platform go to Cloud -> API Explorer -> Device Control -> Query Things Data Model and place any device ID in there.

@CmdrAvegan
Copy link

I have a device similar to the one described in this thread, and I've been working on a script to send commands with minimal sleep time between them. However, I've noticed that the device tends to go offline after a while, which disrupts the process.

Here's a brief overview of what I've been doing:

I'm using tinytuya to control the device.

I generate the payload using the tinytuya function: payload = device.generate_payload(tinytuya.CONTROL, sorted_commands).

After generating and sending the payload, I ping the device to check connectivity.

Based on the ping time, I dynamically adjust the sleep interval for each command.

Currently, I'm alternating between using the exact ping time for some commands and adding a small additional delay for others to maintain stability.

Despite these measures, the device still goes offline occasionally. Has anyone found a reliable way to send commands with minimal delay without causing the device to disconnect? Any insights or suggestions would be greatly appreciated! Sorry if this is the wrong place to comment this.

@jasonacox
Copy link
Owner

@CmdrAvegan can you give us the device name (and URL if you can) and version (e.g. 3.4)?

I wish we knew the trick to make these more stable. I do wonder if there is a way to simulate this using the SmartLife app w/o it using the cloud. If it also causes the devices to become unstable, we confirm our suspicion that the local API is brittle on the 3.4 devices. If it doesn't, we should investigate to see if the app is doing something different (some new message?) that helps the devices remain stable.

@CmdrAvegan
Copy link

@CmdrAvegan can you give us the device name (and URL if you can) and version (e.g. 3.4)?

I wish we knew the trick to make these more stable. I do wonder if there is a way to simulate this using the SmartLife app w/o it using the cloud. If it also causes the devices to become unstable, we confirm our suspicion that the local API is brittle on the 3.4 devices. If it doesn't, we should investigate to see if the app is doing something different (some new message?) that helps the devices remain stable.

The device name is "Chasing Strip Light" it's using version 3.5

Here's the URL: https://www.feit.com/products/20-ft-smart-color-chasing-led-strip-light-tape20-chase

Mapping:

        "mapping": {
            "20": {
                "code": "switch_led",
                "type": "Boolean",
                "values": {}
            },
            "21": {
                "code": "work_mode",
                "type": "Enum",
                "values": {
                    "range": [
                        "white",
                        "colour",
                        "scene",
                        "music"
                    ]
                }
            },
            "22": {
                "code": "bright_value",
                "type": "Integer",
                "values": {
                    "min": 10,
                    "max": 1000,
                    "scale": 0,
                    "step": 1
                }
            },
            "23": {
                "code": "temp_value",
                "type": "Integer",
                "values": {
                    "min": 0,
                    "max": 1000,
                    "scale": 0,
                    "step": 1
                }
            },
            "24": {
                "code": "colour_data",
                "type": "String",
                "values": "{\"maxlen\":255}"
            },
            "26": {
                "code": "countdown",
                "type": "Integer",
                "values": {
                    "unit": "s",
                    "min": 0,
                    "max": 86400,
                    "scale": 0,
                    "step": 1
                }
            },
            "46": {
                "code": "light_length",
                "type": "Integer",
                "values": {
                    "unit": "\u00b0Cm",
                    "min": 1,
                    "max": 10000,
                    "scale": 0,
                    "step": 1
                }
            },
            "47": {
                "code": "light_pixel",
                "type": "Integer",
                "values": {
                    "min": 1,
                    "max": 1024,
                    "scale": 0,
                    "step": 1
                }
            },
            "51": {
                "code": "dreamlight_scene_mode",
                "type": "Raw",
                "values": {
                    "maxlen": 128
                }
            },
            "53": {
                "code": "lightpixel_number_set",
                "type": "Integer",
                "values": {
                    "min": 1,
                    "max": 1000,
                    "scale": 1,
                    "step": 1
                }
            },
            "61": {
                "code": "paint_colour_data",
                "type": "Raw",
                "values": {
                    "maxlen": 128
                }
            },
            "27": {
                "code": "music_data",
                "type": "String",
                "values": "{\"maxlen\":255}"
            },
            "28": {
                "code": "control_data",
                "type": "String",
                "values": "{\"maxlen\":255}"
            }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tuya_device Support for specific Tuya Devices
Projects
None yet
Development

No branches or pull requests

4 participants