jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
884 stars 159 forks source link

snapshot.json file does not contain the endpoint information needed to add the device to hubitat... #246

Open gleep52 opened 1 year ago

gleep52 commented 1 year ago

My shanpshot.json file that gets created when running a scan finds my floor lamp, but it does not show an address (IP is listed as 0) and the endpoint information which should be a number preceeding a "false" value in a string of comma syntax is not found at all either. The IP I can pull from my DHCP - but the endpoint I'm not sure how to obtain. Is there more guidance on this step?

jasonacox commented 1 year ago

Hi @gleep52 - The snapshot file is created as the result of a scan. Tuya devices send out a UDP broadcast packet that identifies them (their IP, protocol version and ID). Do you see the lamp when you run a scan?

python3 -m tinytuya scan

At the completion of the scan, it stores the results in the snapshop.json. A few things to note:

python3 -m tinytuya -force scan
gleep52 commented 1 year ago

Is there a way to specify the IPs to scan? I have my IoT devices on a different vlan… however the one device DOES get found but says the IP is “0” in the snapshot file.

jasonacox commented 1 year ago

That's puzzling. It could be a bug. Can you paste the output or a screenshot of the scan?

There is no option to specify the network range. However, that is a good feature TODO request.

You can activate additional debug information for the scan:

import tinytuya

tinytuya.set_debug(True)
tinytuya.scan()
gleep52 commented 1 year ago

Is there any sensitive information in a scan I shouldn’t post publically?

gleep52 commented 1 year ago

Will this driver provide the ability for me to change to my own custom scenes I create inside the tuya app, and adjust the dim setting either by scene manipulation (one bright scene, one copy of the same scene but dim set much lower), or by simply sending a dim command to the RGBIC controllers?

The model is listed as this:

"Corner Floor Lamp DFQY-CS14"

The bar code says:

"X00381JJ0L RGBIC LED Floor Lamp, Gevcc ...,Bedroom,Gaming Room(Black)"

Searching on Amazon I found this link that looks correct: https://smile.amazon.com/Gevcc-Changing-Corner-Google-Assistant/dp/B09Y1NSVNQ 9

jasonacox commented 1 year ago

Sensitive info: It is best not to show Device ID or Device KEY.

TinyTuya will allow you to write python scripts to manipulate the settings for color, brightness, etc. You can also set up scenes.

Take a look at the example scripts here: https://github.com/jasonacox/tinytuya/tree/master/examples#smart-bulb-rgb

uzlonewolf commented 1 year ago

Is there a way to specify the IPs to scan? I have my IoT devices on a different vlan

Check out my scanner rewrite at https://github.com/uzlonewolf/tinytuya/tree/scanner . With it, you can specify address ranges to scan such as python3 -m tinytuyta scan -force 192.168.0.0/22 192.168.192.128/25 10.0.0.0/8. Speaking of which, I really should get that merged in...

gleep52 commented 1 year ago

Here is my output @jasonacox

C:\>python -m tinytuya scan

TinyTuya (Tuya device scanner) [1.9.1]

[Loaded devices.json - 2 devices]

Scanning on UDP ports 6666 and 6667 for devices (17 retries)...

Scan Complete!  Found 0 devices.

>> Saving device snapshot data to snapshot.json

C:\>python -m tinytuya wizard
TinyTuya Setup Wizard [1.9.1]

    Existing settings:
        API Key=xxx
        Secret=xxx
        DeviceID=xxx
        Region=us

    Use existing credentials (Y/n): y

Device Listing

[
    {
        "name": "Computer Room Bar",
        "id": "xxx",
        "key": "xxx",
        "mac": "fc:67:1f:12:aa:12",
        "category": "dd",
        "product_name": "DFQY-CS14",
        "product_id": "tfgt1wus39urhbih",
        "biz_type": 0,
        "model": "SCW-QY-CB666",
        "sub": false,
        "icon": "https://images.tuyaus.com/smart/icon/ay15373622314086wreM/3e94ae6a6d96f2fabf66e68aa2782b91.png",
        "uuid": "xxx"
    },
    {
        "name": "Theatre Bar 1",
        "id": "xxx",
        "key": "xxx",
        "mac": "fc:67:1f:11:43:a8",
        "category": "dd",
        "product_name": "DFQY-CS14",
        "product_id": "tfgt1wus39urhbih",
        "biz_type": 0,
        "model": "SCW-QY-CB666",
        "sub": false,
        "icon": "https://images.tuyaus.com/smart/icon/ay15373622314086wreM/3e94ae6a6d96f2fabf66e68aa2782b91.png",
        "uuid": "xxx"
    },
    {
        "name": "Master Bedroom Bar",
        "id": "xxx",
        "key": "xxx",
        "mac": "fc:67:1f:11:12:60",
        "category": "dd",
        "product_name": "DFQY-CS14",
        "product_id": "tfgt1wus39urhbih",
        "biz_type": 0,
        "model": "SCW-QY-CB666",
        "sub": false,
        "icon": "https://images.tuyaus.com/smart/icon/ay15373622314086wreM/3e94ae6a6d96f2fabf66e68aa2782b91.png",
        "uuid": "xxx"
    }
]

>> Saving list to devices.json
    3 registered devices saved

>> Saving raw TuyaPlatform response to tuya-raw.json

Poll local devices? (Y/n): y

Scanning local network for Tuya devices (retry 28 times)...
    0 local devices discovered

Polling local devices...
    [Computer Room Bar] - 0 - Error: No IP found
    [Theatre Bar 1] - 0 - Error: No IP found
    [Master Bedroom Bar] - 0 - Error: No IP found

>> Saving device snapshot data to snapshot.json

Done.

C:\>
sjpbailey commented 1 year ago

Hello Jason,  Sorry to but in or is it butt? Weren't the PIR, proximity sensors also not broadcasting local IP due to being battery operated and not always online. Weird the app can find their local non-internet IP however scanning wizard for snapshot does not find the local IP address. Must be a way the app asks or polls the device to get the local IP address or maybe it doesn't use it. Or Is the app using the internet accessible IP for cloud? Watching wizard run with added print statements doesn't it give you the internet addresses of the devices? See below.Just wondering if there is a connection to this no IP attained on TinyTuya however the app does?I added PIR for rear doors and no local IP on them either.  I apologize for my grammar on tech i have only been coding with python for three years.Here you can see my PIR sensor that has no local IP has an internet IP of   "ip": "98.41.236.33",Sensitive information below is edited please delete when done, or i will enact the tape destruction as this seems to be a mission impossible 🤣 Hoping @Jamespauly has a node server for this soon on UDI! Cheers and the Best to You All!Internet results Wizard:"result": [        {            "active_time": 1668983157,            "biz_type": 0,            "category": "pir",            "create_time": 1668983157,            "icon": "smart/icon/ay152419447777777777/162545442419b6b47e132.jpg",            "id": "eb771f215ef2e21e@@@@@",            "ip": "98.41.236.33",            "lat": "37.7182",            "local_key": "3977a$$$$$3659d35",            "lon": "-121.4699",            "model": "",            "name": "Motion Master Outside ",            "online": true,            "owner_id": "8888888",            "product_id": "tuadvwloutnzat2p",            "product_name": "PIR Sensor ",            "status": [                {                    "code": "pir",                    "value": "none"                },                {                    "code": "battery_percentage",                    "value": 91                }            ],            "sub": false,            "time_zone": "-08:00",            "uid": "az1610@@@067414WkfOO",            "update_time": 1668983192,            "uuid": "7c864f922baa4444"        },        {            "active_time": 1668372689,            "biz_type": 0,            "category": "pir",            "create_time": 1668372689,            "icon": "smart/icon/ay15554925906369PM9S/13&&&&&&8aa546206ffcf603f38ceb54.png",            "id": "ebc8f347f1e1c6$$$$$$9gw",            "ip": "98.41.236.33",            "lat": "37.7183",            "local_key": "ec91544aaa7777c4c",            "lon": "-121.4701",            "model": "PIR-wifi-V01",            "name": "Motion Dining Pool",            "online": true,            "owner_id": "88888888",            "product_id": "o1l76njefmksbgkk",            "product_name": "PIR",            "status": [                {                    "code": "pir",                    "value": "none"                },                {                    "code": "battery_percentage",                    "value": 22                }            ],            "sub": false,            "time_zone": "-08:00",            "uid": "az1610958666666WkfOO",            "update_time": 1668372721,            "uuid": "3bc8f903$$$$091"        },        {            "active_time": 1668371958,            "biz_type": 0,            "category": "pir",            "create_time": 1668371958,            "icon": "smart/icon/ay15554925906369PM9S/1666666c8aa546206ffcf603f38ceb54.png",            "id": "eb1dfd5c8a9ea55655pkkh",            "ip": "98.41.236.33",            "lat": "37.7183",            "local_key": "6709aa4e3a8c1985",            "lon": "-121.4701",            "model": "PIR-wifi-V01",            "name": "Motion Garden ",            "online": true,            "owner_id": "88888888",            "product_id": "o1l76njefmksbgkk",            "product_name": "PIR",            "status": [                {                    "code": "pir",                    "value": "none"                },                {                    "code": "battery_percentage",                    "value": 44                }            ],            "sub": false,            "time_zone": "-08:00",            "uid": "az161095806741455555",            "update_time": 1668371982,            "uuid": "b2f0eab0764444db"        },On Jan 4, 2023, at 3:51 AM, gleep52 @.***> wrote: Here is my output @jasonacox C:>python -m tinytuya scan

TinyTuya (Tuya device scanner) [1.9.1]

[Loaded devices.json - 2 devices]

Scanning on UDP ports 6666 and 6667 for devices (17 retries)...

Scan Complete! Found 0 devices.

Saving device snapshot data to snapshot.json

C:>python -m tinytuya wizard TinyTuya Setup Wizard [1.9.1]

Existing settings:
    API Key=xxx
    Secret=xxx
    DeviceID=xxx
    Region=us

Use existing credentials (Y/n): y

Device Listing

[ { "name": "Computer Room Bar", "id": "xxx", "key": "xxx", "mac": "fc:67:1f:12:aa:12", "category": "dd", "product_name": "DFQY-CS14", "product_id": "tfgt1wus39urhbih", "biz_type": 0, "model": "SCW-QY-CB666", "sub": false, "icon": "https://images.tuyaus.com/smart/icon/ay15373622314086wreM/3e94ae6a6d96f2fabf66e68aa2782b91.png", "uuid": "xxx" }, { "name": "Theatre Bar 1", "id": "xxx", "key": "xxx", "mac": "fc:67:1f:11:43:a8", "category": "dd", "product_name": "DFQY-CS14", "product_id": "tfgt1wus39urhbih", "biz_type": 0, "model": "SCW-QY-CB666", "sub": false, "icon": "https://images.tuyaus.com/smart/icon/ay15373622314086wreM/3e94ae6a6d96f2fabf66e68aa2782b91.png", "uuid": "xxx" }, { "name": "Master Bedroom Bar", "id": "xxx", "key": "xxx", "mac": "fc:67:1f:11:12:60", "category": "dd", "product_name": "DFQY-CS14", "product_id": "tfgt1wus39urhbih", "biz_type": 0, "model": "SCW-QY-CB666", "sub": false, "icon": "https://images.tuyaus.com/smart/icon/ay15373622314086wreM/3e94ae6a6d96f2fabf66e68aa2782b91.png", "uuid": "xxx" } ]

Saving list to devices.json 3 registered devices saved

Saving raw TuyaPlatform response to tuya-raw.json

Poll local devices? (Y/n): y

Scanning local network for Tuya devices (retry 28 times)... 0 local devices discovered

Polling local devices... [Computer Room Bar] - 0 - Error: No IP found [Theatre Bar 1] - 0 - Error: No IP found [Master Bedroom Bar] - 0 - Error: No IP found

Saving device snapshot data to snapshot.json

Done.

C:>

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>

jasonacox commented 1 year ago

Thanks @sjpbailey - You are right that battery powered Tuya devices will rarely show up. They go to sleep to save battery which means that they do not broadcast the UDP discovery packets.

Scanning local network for Tuya devices (retry 28 times)... 0 local devices discovered

Thanks for posting those details @gleep52 ! That helps. It is clear that TinyTuya is not seeing any device on your network. What you are seeing is the Wizard fetching the device details from the Tuya Cloud which includes, most importantly, the local Key. However, when it switches to "scan" local network mode (polling), it is not hearing any of the UDP packets from the devices. This is key for your use case:

I have my IoT devices on a different vlan

UDP packets are routable, but these devices are likely using the subnet-directed broadcast addresses (e.g. x.x.x.255) which would isolate them to your IoT VLAN and not transit across VLAN boundaries. TinyTuya will not be able to see the discovery packets that provide the IP address if the system running TinyTuya is not on the same vlan as the Tuya devices. As @uzlonewolf mentioned, there is a scanner update (thanks to @uzlonewolf !!) that will eventually be merged in to allow you to force scan across other VLANs. And yes LW, we should get that merged. :)

Outside of trying the workaround suggestion by @uzlonewolf, you could move a system to your IoT VLAN to do the scan. Alternatively you could look at your DHCP Router to get the IP addresses for your devices. Once you have those IPs, you can manage the devices directly through python scripts from the separate VLAN provided your network allows TCP traffic across that boundary.

gleep52 commented 1 year ago

Hi Jason - I was following the ending of the great details on https://github.com/jasonacox/tinytuya#tinytuya

I was able to reconfigure my broadcasts and can now see the returning polling values. I ran some of the sample scripts on the page linked above and my floor lamps don't do much. I tried the 22 device option which returned an extra few lines like type query t... I'm guessing that's perhaps a timestamp since it always changes?

Otherwise I'm trying to run this script you provided which SHOULD theoretically set the scene to a rainbow changing color I think. However, nothing happens to my lamp when I run it.

import tinytuya

"""
RGB Bulb Device
"""
import time

d = tinytuya.BulbDevice('xxx', '192.168.3.236', 'xxx', 'device22')
d.set_version(3.3)  # IMPORTANT to set this regardless of version
d.set_dpsUsed({"20": None})  # This needs to be a datapoint available on the device
data =  d.status()

# Show status of first controlled switch on device
print('Dictionary %r' % data)

# Set to RED Color - set_colour(r, g, b):
d.set_colour(255,0,0)  

# Cycle through the Rainbow
rainbow = {"red": [255, 0, 0], "orange": [255, 127, 0], "yellow": [255, 200, 0],
          "green": [0, 255, 0], "blue": [0, 0, 255], "indigo": [46, 43, 95],
          "violet": [139, 0, 255]}
for color in rainbow:
    [r, g, b] = rainbow[color]
    d.set_colour(r, g, b, nowait=True)  # nowait = Go fast don't wait for response
    time.sleep(0.25)

# Brightness: Type A devices range = 25-255 and Type B = 10-1000
d.set_brightness(1000)

# Set to White - set_white(brightness, colourtemp):
#    colourtemp: Type A devices range = 0-255 and Type B = 0-1000
d.set_white(1000,10)

# Set Bulb to Scene Mode
d.set_mode('scene')

# Scene Example: Set Color Rotation Scene
d.set_value(25, '07464602000003e803e800000000464602007803e803e80000000046460200f003e803e800000000464602003d03e803e80000000046460200ae03e803e800000000464602011303e803e800000000')

Any ideas how to get this to trigger a scene by name, or do I have to somehow find the very long string of characters for specific scenes I save maybe? I must be missing something as sending this script as is doesn't do anything to my lamp but hte dictionary output does work and returns this as the value:

Dictionary {'dps': {'20': True}, 'type': 'query', 't': 1672910676}

Thanks for your insight!

gleep52 commented 1 year ago

I turned on debug mode per your suggestion above and it seems there are some unsupported types due to color options not being supported - is that something modifiable or no dice? Any ideas - debug contents below:

DEBUG:TinyTuya [1.9.1]

DEBUG:status() entry (dev_type is device22)
DEBUG:building command 10 payload=b'{"devId":"xxx","uid":"xxx","t":"1672910984","dps":{}}'
DEBUG:sending payload
DEBUG:payload encrypted=b'000055aa000000010000000d00000077332e3300000000000000000000000030106393b7c689131a4f5164ca58fb9f19f73aad11fbc5b593f5cdc50a2015db0f1442471423116e08c2224929849d579754530ade5f4c1c107a90c46587fe82ee6648532ef17d8916d34754401369c51a89ac2efd88d2269ce0b2fa42ecc90d1141ca6b0000aa55'
DEBUG:received data=b'000055aa000000010000000d0000000c00000000302b238a0000aa55'
DEBUG:received null payload (TuyaMessage(seqno=1, cmd=13, retcode=0, payload=b'', crc=808133514, crc_good=True)), fetch new one - retry 0 / 5
DEBUG:status() received data=None
DEBUG:bulb type set to B
DEBUG:status() entry (dev_type is device22)
DEBUG:building command 10 payload=b'{"devId":"xxx","uid":"xxx","t":"1672910990","dps":{"20":null}}'
DEBUG:sending payload
DEBUG:payload encrypted=b'000055aa000000020000000d00000087332e3300000000000000000000000030106393b7c689131a4f5164ca58fb9f19f73aad11fbc5b593f5cdc50a2015db0f1442471423116e08c2224929849d579754530ade5f4c1c107a90c46587fe82959e288f5a16efdc03a8232a277feeea6ca4a53c449d0ab60c221cdcb7526747e8dcf8ecbe09970ad9a9f9f59fb5cbd7891269ac0000aa55'
DEBUG:received data=b'000055aa000000020000000d0000000c000000008de14f440000aa55'
DEBUG:received null payload (TuyaMessage(seqno=2, cmd=13, retcode=0, payload=b'', crc=2380353348, crc_good=True)), fetch new one - retry 0 / 5
DEBUG:received data=b'000055aa00000000000000080000005b00000000332e3300000000000045ef00000001c3b2914a0930756ac3bc881e0f67fa2e761c9ee8152e329fba57dfdc8fec880f33252bc868323973868a60b9d5295d0bad64354edc459170013ff87eaeb04a97ce0de0850000aa55'
DEBUG:received message=TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00E\xef\x00\x00\x00\x01\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0f3%+\xc8h29s\x86\x8a`\xb9\xd5)]\x0b\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97', crc=3457015941, crc_good=True)
DEBUG:raw unpacked message = TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00E\xef\x00\x00\x00\x01\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0f3%+\xc8h29s\x86\x8a`\xb9\xd5)]\x0b\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97', crc=3457015941, crc_good=True)
DEBUG:decode payload=b'3.3\x00\x00\x00\x00\x00\x00E\xef\x00\x00\x00\x01\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0f3%+\xc8h29s\x86\x8a`\xb9\xd5)]\x0b\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97'
DEBUG:removing 3.x=b'\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0f3%+\xc8h29s\x86\x8a`\xb9\xd5)]\x0b\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97'
DEBUG:decrypting=b'\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0f3%+\xc8h29s\x86\x8a`\xb9\xd5)]\x0b\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97'
DEBUG:decrypted 3.x payload='{"dps":{"20":true},"type":"query","t":1672910990}'
DEBUG:payload type = <class 'str'>
DEBUG:decoded results='{"dps":{"20":true},"type":"query","t":1672910990}'
DEBUG:status() received data={'dps': {'20': True}, 'type': 'query', 't': 1672910990}
Dictionary {'dps': {'20': True}, 'type': 'query', 't': 1672910990}
Output exceeds the size limit. Open the full output data in a text editor
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."
DEBUG:status() entry (dev_type is device22)
DEBUG:building command 10 payload=b'{"devId":"xxx","uid":"xxx","t":"1672910992","dps":{"20":null}}'
DEBUG:sending payload
DEBUG:payload encrypted=b'000055aa000000030000000d00000087332e3300000000000000000000000030106393b7c689131a4f5164ca58fb9f19f73aad11fbc5b593f5cdc50a2015db0f1442471423116e08c2224929849d579754530ade5f4c1c107a90c46587fe829b79ae4fd53f4d9d37f0ed17059ad9356ca4a53c449d0ab60c221cdcb7526747e8dcf8ecbe09970ad9a9f9f59fb5cbd7428c981a0000aa55'
DEBUG:received data=b'000055aa000000030000000d0000000c00000000507796c10000aa55'
DEBUG:received null payload (TuyaMessage(seqno=3, cmd=13, retcode=0, payload=b'', crc=1350014657, crc_good=True)), fetch new one - retry 0 / 5
DEBUG:received data=b'000055aa00000000000000080000005b00000000332e3300000000000045f000000001c3b2914a0930756ac3bc881e0f67fa2e761c9ee8152e329fba57dfdc8fec880f547fc4a868f00202a65dfb34aca7f0b7ad64354edc459170013ff87eaeb04a97f37506100000aa55'
DEBUG:received message=TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00E\xf0\x00\x00\x00\x01\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0fT\x7f\xc4\xa8h\xf0\x02\x02\xa6]\xfb4\xac\xa7\xf0\xb7\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97', crc=4084532752, crc_good=True)
DEBUG:raw unpacked message = TuyaMessage(seqno=0, cmd=8, retcode=0, payload=b'3.3\x00\x00\x00\x00\x00\x00E\xf0\x00\x00\x00\x01\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0fT\x7f\xc4\xa8h\xf0\x02\x02\xa6]\xfb4\xac\xa7\xf0\xb7\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97', crc=4084532752, crc_good=True)
DEBUG:decode payload=b'3.3\x00\x00\x00\x00\x00\x00E\xf0\x00\x00\x00\x01\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0fT\x7f\xc4\xa8h\xf0\x02\x02\xa6]\xfb4\xac\xa7\xf0\xb7\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97'
DEBUG:removing 3.x=b'\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0fT\x7f\xc4\xa8h\xf0\x02\x02\xa6]\xfb4\xac\xa7\xf0\xb7\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97'
DEBUG:decrypting=b'\xc3\xb2\x91J\t0uj\xc3\xbc\x88\x1e\x0fg\xfa.v\x1c\x9e\xe8\x15.2\x9f\xbaW\xdf\xdc\x8f\xec\x88\x0fT\x7f\xc4\xa8h\xf0\x02\x02\xa6]\xfb4\xac\xa7\xf0\xb7\xadd5N\xdcE\x91p\x01?\xf8~\xae\xb0J\x97'
DEBUG:decrypted 3.x payload='{"dps":{"20":true},"type":"query","t":1672910992}'
DEBUG:payload type = <class 'str'>
DEBUG:decoded results='{"dps":{"20":true},"type":"query","t":1672910992}'
DEBUG:status() received data={'dps': {'20': True}, 'type': 'query', 't': 1672910992}
DEBUG:ERROR Device in Unknown State - 906 - payload: "set_brightness: Unknown bulb state."
...
DEBUG:sending payload
DEBUG:payload encrypted=b'000055aa000000060000000700000127332e3300000000000000000000000030106393b7c689131a4f5164ca58fb9f19f73aad11fbc5b593f5cdc50a2015db0f1442471423116e08c2224929849d579754530ade5f4c1c107a90c46587fe82ac650ca6c9112904de2648ee90b4cbeace4515730397f71f69a18f1ee3d6339296ef8aed53d5e7d4d39aa0f1c726bc7ed9a6db34ea44628bad31f6ea8740203d36ef7275c60dcbc471f821c4e4a89585ff3dccee9c70f5543dda7d29fb49ae841cc6dcd6b256446dc91bfcc80102da014016303c51ce4c380ca1df7cd08273944ffb3ac7e66874c836ec7b553df552a6c2ad5a47efc3d40deef52353a5eba636e59322a3178b4c2f0a39898b5e615659bf6cfb6fc81bcf23b0593d091ace9d7902681bc3b7bc264d3cb2581d966a0c7b61670b800000aa55'
DEBUG:received data=b'000055aa00000006000000070000000c00000000d876af4c0000aa55'
DEBUG:received null payload (TuyaMessage(seqno=6, cmd=7, retcode=0, payload=b'', crc=3631656780, crc_good=True)), fetch new one - retry 0 / 5
jasonacox commented 1 year ago

Progress! It sounds like these lamps are not reacting like Smart Bulbs or LED strips so the BulbDevice class may not won't work.

Try this: Run the monitor script and use the app (or lamp directly) to change things like on/off, color, scene and see what shows up in the log. Based on what you see, those DPS (dps:) values will be what we would send to it to change things like color or scene.

https://github.com/jasonacox/tinytuya#example-device-monitor

import tinytuya

d = tinytuya.OutletDevice('DEVICEID', 'DEVICEIP', 'DEVICEKEY')
d.set_version(3.3)
d.set_socketPersistent(True)

print(" > Send Request for Status < ")
payload = d.generate_payload(tinytuya.DP_QUERY)
d.send(payload)

print(" > Begin Monitor Loop <")
while(True):
    # See if any data is available
    data = d.receive()
    print('Received Payload: %r' % data)

    # Send keyalive heartbeat
    print(" > Send Heartbeat Ping < ")
    payload = d.generate_payload(tinytuya.HEART_BEAT)
    d.send(payload)
gleep52 commented 1 year ago

Oh this is brilliant!

Received Payload: {'dps': {'51': 'AckLZGRgAABkAABkAHhkAOFkAPVkAUJk'}, 't': 1673029196}
 > Send Heartbeat Ping < 
Received Payload: {'dps': {'51': 'AcoAZGTAAABkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJkAWJk'}, 't': 1673029199}
 > Send Heartbeat Ping < 
Received Payload: {'dps': {'51': 'AcgLZGRwAABkAABkAVFkAQJkANtkAA1k'}, 't': 1673029202}
 > Send Heartbeat Ping < 
Received Payload: {'dps': {'51': 'AckLZGRgAABkAABkAHhkAOFkAPVkAUJk'}, 't': 1673029207}
 > Send Heartbeat Ping < 
Received Payload: {'dps': {'20': False}, 't': 1673029211}
 > Send Heartbeat Ping < 
Received Payload: {'dps': {'20': True}, 't': 1673029216}
 > Send Heartbeat Ping < 
Received Payload: {'dps': {'51': 'AckLZGRgAABkAABkAHhkAOFkAPVkAUJk'}, 't': 1673029216}
 > Send Heartbeat Ping < 
Received Payload: {'dps': {'51': 'AcgLZGRwAABkAABkAVFkAQJkANtkAA1k'}, 't': 1673029218}

So it appears 51 is used for changing the scene and those random text strings are the scenes I have already created and was switching between.

uzlonewolf commented 1 year ago

That's great! It looks similar to other RGB lights, it just uses base64 instead of a hex string. Decoding the base64 and converting to hex for those 3 values gives:

01c90b64646000006400006400786400e16400f564014264
01ca006464c0000064016264016264016264016264016264016264016264016264016264016264016264016264016264016264016264
01c80b64647000006400006401516401026400db64000d64

Decoding the values should be pretty easy (if a bit tedious), just change one thing at a time and see what changes. Looks to me like it's 3 bytes per color, probably HSV going by those values (byte 1 is 0-255 and 2+3 are 0-100 (0x64 hex); 016264 would be a shade of red).

jasonacox commented 1 year ago

You are amazing, @uzlonewolf !

@gleep52 Let us know what you discover. At a minimum, you can record all the scenes you want and use TinyTuya to set them, eg.

d = tinytuya.OutletDevice('DEVICEID', 'DEVICEIP', 'DEVICEKEY')
d.set_version(3.3)
d.set_socketPersistent(True)
d.set_value(51, 'AckLZGRgAABkAABkAHhkAOFkAPVkAUJk')
gleep52 commented 1 year ago

while I understand how to do this via python on my own machine - how do I get this working in Hubitat's hub? I realize this is not on your radar or scope of TinyTuya - but curious if you've ever ran across it before. I found TinyTuya from the hubitat forums and truly appreciate the help with what you've done so far to help me.

jasonacox commented 1 year ago

I don't know much about Hubitat, but doing a quick search, it doesn't look promising. I found this https://docs2.hubitat.com/developer/app/building-a-simple-app but poking around in the forums show that it isn't very open source friendly. It is Java based and there doesn't seems to be an interest in supporting Python. Please let us know if you discover otherwise.