jasonacox / tinytuya

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

Tinytuya, detached from the cloud and running local. Debug on a bulb that is missing functionality #265

Closed tjbcatch22 closed 1 year ago

tjbcatch22 commented 1 year ago

From post https://github.com/jasonacox/tinytuya/issues/249 so as not to hijack that post. I'm posting some of the debug in hopes of figuring out why the bulb only has some functions and not others.

Brief recap: I'm able to run Tinytuya locally without getting a Cloud subscription after using cloud-cutter (https://github.com/tuya-cloudcutter/tuya-cloudcutter).

My bulb seems to be a generic of some kind: Schwaiger A19 60W Equivalent Color Selectable Dimmable LED Light Bulb, (see here for more info: https://www.menards.com/main/p-1642874274122411.htm). I run cloud-cutter, get the Device_id and a Local_key, input those into Bulb.py and using Tinytuya bulb.py I can get the light to turn off, on, some dimming, and some limited modes. ( mode-scene has a softer light, mode-colour and music will turn the bulb red)

Unfortunately, The bulb does not do any other colors, except for when its in music or color mode as mentioned above.

There is of course, a lot of debug. I pasted some of the noteworthy: Initial running bulb.py, showing down to Bulb off and then back on. This seems to work fine: python bulb.py DEBUG:TinyTuya [1.10.0]

TinyTuya - Smart Bulb RGB Test [1.10.0]

TESTING: Device VslkoRtBGkjj7eRhlsty at 192.168.1.162 with key BVRz3kyeaqKRynlg version 3.3 DEBUG:status() entry (dev_type is default) DEBUG:building command 10 payload='{"uid":"VslkoRtBGkjj7eRhlsty","devId":"VslkoRtBGkjj7eRhlsty","t":"1674923629","gwId":"VslkoRtBGkjj7eRhlsty"}' DEBUG:sending payload DEBUG:payload encrypted='000055aa000000010000000a000000780ba4806e4edf9b45012ab30e1b9bde94d3cd6feadbb0065ee5961128dd449f4f419131fc6b45d8181ec63a9a01b199c2d4eb518a2f21c4a36110a13c3ef4c3272b6cc6e4d9cd518f2dac3fd4e97809e4865404a6b45008fc60f412b5d3e90f4c29e11ad8b4eb2a74509a0dc9a1a5524eeaaf92190000aa55' DEBUG:received data='000055aa000000010000000a0000004c00000000e4ab60132069dd1ea27a08b48b2926e06522dec412171c265371372dae54466475fbb07bc4f8fcf76cfc1c4367a5f75106b7a85309835c8fd0b5e3f668e889db025063cd0000aa55' DEBUG:received message=TuyaMessage(seqno=1, cmd=10, retcode=0, payload='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb', crc=38822861, crc_good=True, prefix=21930, iv=None) DEBUG:raw unpacked message = TuyaMessage(seqno=1, cmd=10, retcode=0, payload='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb', crc=38822861, crc_good=True, prefix=21930, iv=None) DEBUG:decode payload='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb' DEBUG:decrypting='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb' DEBUG:decrypted 3.x payload=u'{"dps":{"20":true,"21":"white","22":1000,"26":0}}' DEBUG:payload type = <type 'unicode'> DEBUG:decoded results=u'{"dps":{"20":true,"21":"white","22":1000,"26":0}}' DEBUG:status() received data={u'dps': {u'26': 0, u'20': True, u'21': u'white', u'22': 1000}} DEBUG:bulb type set to B DEBUG:status() entry (dev_type is default) DEBUG:building command 10 payload='{"uid":"VslkoRtBGkjj7eRhlsty","devId":"VslkoRtBGkjj7eRhlsty","t":"1674923629","gwId":"VslkoRtBGkjj7eRhlsty"}' DEBUG:sending payload DEBUG:payload encrypted='000055aa000000020000000a000000780ba4806e4edf9b45012ab30e1b9bde94d3cd6feadbb0065ee5961128dd449f4f419131fc6b45d8181ec63a9a01b199c2d4eb518a2f21c4a36110a13c3ef4c3272b6cc6e4d9cd518f2dac3fd4e97809e4865404a6b45008fc60f412b5d3e90f4c29e11ad8b4eb2a74509a0dc9a1a5524e04c991000000aa55' DEBUG:received data='000055aa000000020000000a0000004c00000000e4ab60132069dd1ea27a08b48b2926e06522dec412171c265371372dae54466475fbb07bc4f8fcf76cfc1c4367a5f75106b7a85309835c8fd0b5e3f668e889db9b1084a20000aa55' DEBUG:received message=TuyaMessage(seqno=2, cmd=10, retcode=0, payload='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb', crc=2601551010, crc_good=True, prefix=21930, iv=None) DEBUG:raw unpacked message = TuyaMessage(seqno=2, cmd=10, retcode=0, payload='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb', crc=2601551010, crc_good=True, prefix=21930, iv=None) DEBUG:decode payload='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb' DEBUG:decrypting='\xe4\xab\x13 i\xdd\x1e\xa2z\x08\xb4\x8b)&\xe0e"\xde\xc4\x12\x17\x1c&Sq7-\xaeTFdu\xfb\xb0{\xc4\xf8\xfc\xf7l\xfc\x1cCg\xa5\xf7Q\x06\xb7\xa8S\t\x83\\x8f\xd0\xb5\xe3\xf6h\xe8\x89\xdb' DEBUG:decrypted 3.x payload=u'{"dps":{"20":true,"21":"white","22":1000,"26":0}}' DEBUG:payload type = <type 'unicode'> DEBUG:decoded results=u'{"dps":{"20":true,"21":"white","22":1000,"26":0}}' DEBUG:status() received data={u'dps': {u'26': 0, u'20': True, u'21': u'white', u'22': 1000}}

Current Status of Bulb: {u'dps': {u'26': 0, u'20': True, u'21': u'white', u'22': 1000}}

Warm White Test DEBUG:building command 7 payload='{"devId":"VslkoRtBGkjj7eRhlsty","dps":{"21":"white","22":1000,"23":0},"uid":"VslkoRtBGkjj7eRhlsty","t":"1674923629"}' DEBUG:sending payload DEBUG:payload encrypted='000055aa000000030000000700000097332e3300000000000000000000000033a116d33b0c3fd21e5a1e04ab19b678f67c358c45d22c9ba0a0416d18a94f01c1e6225a4907030d447bd57d79fe7867f45ad1c221cb6482a390e181900ee4714fb69a8a637e02f28157ee420c026854c4d06f2ec54a30341de83ecd666fed794108d86e840e52a4f41023f2dab851a0794d860b40ec93b862549bd98ab778fbd4db29030000aa55' DEBUG:received data='000055aa00000003000000070000000c00000000c5591c5f0000aa55' DEBUG:received null payload (TuyaMessage(seqno=3, cmd=7, retcode=0, payload='', crc=3310951519, crc_good=True, prefix=21930, iv=None)), fetch new one - retry 0 / 5 DEBUG:received data='000055aa00000000000000080000005b00000000332e33000000000000f25e000000010ed6f5768e778b4f3526b31e66d1bf554c93ef064f0885fd4987c566aaa2238ca9bb0e008eafa2dc7ef95a4e9a56838db1562ff609fbf21939a1ea4efe5af533afcf1c4f0000aa55' DEBUG:received message=TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2^\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xa9\xbb\x0e\x00\x8e\xaf\xa2\xdc~\xf9ZN\x9aV\x83\x8d\xb1V/\xf6\t\xfb\xf2\x199\xa1\xeaN\xfeZ\xf53', crc=2949585999, crc_good=True, prefix=21930, iv=None) DEBUG:raw unpacked message = TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2^\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xa9\xbb\x0e\x00\x8e\xaf\xa2\xdc~\xf9ZN\x9aV\x83\x8d\xb1V/\xf6\t\xfb\xf2\x199\xa1\xeaN\xfeZ\xf53', crc=2949585999, crc_good=True, prefix=21930, iv=None) DEBUG:decode payload='3.3\x00\x00\x00\x00\x00\x00\xf2^\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xa9\xbb\x0e\x00\x8e\xaf\xa2\xdc~\xf9ZN\x9aV\x83\x8d\xb1V/\xf6\t\xfb\xf2\x199\xa1\xeaN\xfeZ\xf53' DEBUG:removing 3.x='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xa9\xbb\x0e\x00\x8e\xaf\xa2\xdc~\xf9ZN\x9aV\x83\x8d\xb1V/\xf6\t\xfb\xf2\x199\xa1\xeaN\xfeZ\xf53' DEBUG:decrypting='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xa9\xbb\x0e\x00\x8e\xaf\xa2\xdc~\xf9ZN\x9aV\x83\x8d\xb1V/\xf6\t\xfb\xf2\x199\xa1\xeaN\xfeZ\xf53' DEBUG:decrypted 3.x payload=u'{"dps":{"21":"white","22":1000},"type":"query","t":492}' DEBUG:payload type = <type 'unicode'> DEBUG:decoded results=u'{"dps":{"21":"white","22":1000},"type":"query","t":492}'

Power Control Test Turn off lamp DEBUG:building command 7 payload='{"devId":"VslkoRtBGkjj7eRhlsty","dps":{"20":false},"uid":"VslkoRtBGkjj7eRhlsty","t":"1674923631"}' DEBUG:sending payload DEBUG:payload encrypted='000055aa000000040000000700000087332e3300000000000000000000000033a116d33b0c3fd21e5a1e04ab19b678f67c358c45d22c9ba0a0416d18a94f012f8689b72f74baf584db3257a736c5a4fefc7ce2bc8126cd7f06e732fce1bb76f67c358c45d22c9ba0a0416d18a94f010e5ef2dce0d031da876e4d7db48df52506b7a85309835c8fd0b5e3f668e889db44a123d30000aa55' DEBUG:received data='000055aa00000000000000080000003b00000000332e33000000000000f25f000000010ed6f5768e778b4f3526b31e66d1bf550917a5288bc51fb0c63a82f9a28e1a88e71c33d80000aa55' DEBUG:received message=TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2_\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\t\x17\xa5(\x8b\xc5\x1f\xb0\xc6:\x82\xf9\xa2\x8e\x1a\x88', crc=3877385176, crcgood=True, prefix=21930, iv=None) DEBUG:raw unpacked message = TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\t\x17\xa5(\x8b\xc5\x1f\xb0\xc6:\x82\xf9\xa2\x8e\x1a\x88', crc=3877385176, crcgood=True, prefix=21930, iv=None) DEBUG:decode payload='3.3\x00\x00\x00\x00\x00\x00\xf2\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\t\x17\xa5(\x8b\xc5\x1f\xb0\xc6:\x82\xf9\xa2\x8e\x1a\x88' DEBUG:removing 3.x='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\t\x17\xa5(\x8b\xc5\x1f\xb0\xc6:\x82\xf9\xa2\x8e\x1a\x88' DEBUG:decrypting='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\t\x17\xa5(\x8b\xc5\x1f\xb0\xc6:\x82\xf9\xa2\x8e\x1a\x88' DEBUG:decrypted 3.x payload=u'{"dps":{"21":"white"},"t":492}' DEBUG:payload type = <type 'unicode'> DEBUG:decoded results=u'{"dps":{"21":"white"},"t":492}' DEBUG:setstatus received data={u'dps': {u'21': u'white'}, u't': 492} Turn on lamp DEBUG:building command 7 payload='{"devId":"VslkoRtBGkjj7eRhlsty","dps":{"20":true},"uid":"VslkoRtBGkjj7eRhlsty","t":"1674923633"}' DEBUG:sending payload DEBUG:payload encrypted='000055aa000000050000000700000087332e3300000000000000000000000033a116d33b0c3fd21e5a1e04ab19b678f67c358c45d22c9ba0a0416d18a94f012aba1a14a6278c8a31e71fe49258a8c9b786c1777bd9b5ec3806a8bfd0deb695705743c2dbda9e9868de201d945c75450a12c3ddf78082669a88270d77afdd1e4137932e1b0e4bdbbe14760566c8007af64129e10000aa55' DEBUG:received data='000055aa00000000000000080000004b00000000332e33000000000000f260000000010ed6f5768e778b4f3526b31e66d1bf554c93ef064f0885fd4987c566aaa2238cb762fecd05421e063d5f7b3dcbeb22e1eb08da6a0000aa55' DEBUG:received message=TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2`\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xb7b\xfe\xcd\x05B\x1e\x06={=\xcb\xeb"\xe1', crc=3943225962, crcgood=True, prefix=21930, iv=None) DEBUG:raw unpacked message = TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2`\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xb7b\xfe\xcd\x05B\x1e\x06={=\xcb\xeb"\xe1', crc=3943225962, crcgood=True, prefix=21930, iv=None) DEBUG:decode payload='3.3\x00\x00\x00\x00\x00\x00\xf2`\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xb7b\xfe\xcd\x05B\x1e\x06={=\xcb\xeb"\xe1' DEBUG:removing 3.x='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xb7b\xfe\xcd\x05B\x1e\x06={=\xcb\xeb"\xe1' DEBUG:decrypting='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfUL\x93\xef\x06O\x08\x85\xfdI\x87\xc5f\xaa\xa2#\x8c\xb7b\xfe\xcd\x05B\x1e\x06={=\xcb\xeb"\xe1' DEBUG:decrypted 3.x payload=u'{"dps":{"21":"white","22":1000},"t":492}' DEBUG:payload type = <type 'unicode'> DEBUG:decoded results=u'{"dps":{"21":"white","22":1000},"t":492}' DEBUG:set_status received data={u'dps': {u'21': u'white', u'22': 1000}, u't': 492}

Not working fine: The color test. debug indicates the bulb is not capable - but it does turn red in Mode-Color and Music. And of course worked fine in the Smart Life app prior to cloudcutting:

Color Test - Cycle through rainbow blue (0,0,255) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." indigo (46,43,95) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." yellow (255,200,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." green (0,255,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." violet (139,0,255) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." orange (255,127,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." red (255,0,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."

blue (0,0,255)

DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." indigo (46,43,95) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." yellow (255,200,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." green (0,255,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." violet (139,0,255) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." orange (255,127,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color." red (255,0,0) DEBUG:ERROR Function Not Supported by Device - 907 - payload: "set_colour: Device does not support color."

And for comparison, here is Mode-Colour, which turns the bulb red: Colour DEBUG:building command 7 payload='{"devId":"VslkoRtBGkjj7eRhlsty","dps":{"21":"colour"},"uid":"VslkoRtBGkjj7eRhlsty","t":"1674923709"}' DEBUG:sending payload DEBUG:payload encrypted='000055aa0000001c0000000700000087332e3300000000000000000000000033a116d33b0c3fd21e5a1e04ab19b678f67c358c45d22c9ba0a0416d18a94f01d59ccea8b1e930bb00d4773b1f13e64856c3e0d56daedc90bc92d7aebab68e7fc4d06f2ec54a30341de83ecd666fed7980e21ae26c36560707d075b171d835bdf860803c877c0d49e0f443647c99c7e26cf68a780000aa55' DEBUG:received data='000055aa0000001b000000070000000c000000002b5d69e80000aa55' DEBUG:received null payload (TuyaMessage(seqno=27, cmd=7, retcode=0, payload='', crc=727542248, crc_good=True, prefix=21930, iv=None)), fetch new one - retry 0 / 5 DEBUG:received data='000055aa00000000000000080000004b00000000332e33000000000000f26e000000010ed6f5768e778b4f3526b31e66d1bf55a721290f981c7b0cb3ab129df62ee53b431e4dfc4e008d3a798c4998fd847f7acfcd041f0000aa55' DEBUG:received message=TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2n\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\xa7!)\x0f\x98\x1c{\x0c\xb3\xab\x12\x9d\xf6.\xe5;C\x1eM\xfcN\x00\x8d:y\x8cI\x98\xfd\x84\x7fz', crc=3486319647, crc_good=True, prefix=21930, iv=None) DEBUG:raw unpacked message = TuyaMessage(seqno=0, cmd=8, retcode=0, payload='3.3\x00\x00\x00\x00\x00\x00\xf2n\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\xa7!)\x0f\x98\x1c{\x0c\xb3\xab\x12\x9d\xf6.\xe5;C\x1eM\xfcN\x00\x8d:y\x8cI\x98\xfd\x84\x7fz', crc=3486319647, crc_good=True, prefix=21930, iv=None) DEBUG:decode payload='3.3\x00\x00\x00\x00\x00\x00\xf2n\x00\x00\x00\x01\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\xa7!)\x0f\x98\x1c{\x0c\xb3\xab\x12\x9d\xf6.\xe5;C\x1eM\xfcN\x00\x8d:y\x8cI\x98\xfd\x84\x7fz' DEBUG:removing 3.x='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\xa7!)\x0f\x98\x1c{\x0c\xb3\xab\x12\x9d\xf6.\xe5;C\x1eM\xfcN\x00\x8d:y\x8cI\x98\xfd\x84\x7fz' DEBUG:decrypting='\x0e\xd6\xf5v\x8ew\x8bO5&\xb3\x1ef\xd1\xbfU\xa7!)\x0f\x98\x1c{\x0c\xb3\xab\x12\x9d\xf6.\xe5;C\x1eM\xfcN\x00\x8d:y\x8cI\x98\xfd\x84\x7fz' DEBUG:decrypted 3.x payload=u'{"dps":{"21":"white"},"type":"query","t":570}' DEBUG:payload type = <type 'unicode'> DEBUG:decoded results=u'{"dps":{"21":"white"},"type":"query","t":570}'

jasonacox commented 1 year ago

Thanks @tjbcatch22 - let's try some things to see if this is just due to a device detection mismatch.

import tinytuya
import time

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

def setc(r, g, b):
    hexvalue = d._rgb_to_hexvalue(r, g, b, d.bulb_type)

    payload = d.generate_payload(
        tinytuya.CONTROL,
        {
            d.DPS_INDEX_MODE[d.bulb_type]: d.DPS_MODE_COLOUR,
            d.DPS_INDEX_COLOUR[d.bulb_type]: hexvalue,
        },
    )
    d._send_receive(payload)

print('\nColor Test - Cycle through 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 x in range(2):
    for i in rainbow:
        r = rainbow[i][0]
        g = rainbow[i][1]
        b = rainbow[i][2]
        print('    %s (%d,%d,%d)' % (i, r, g, b))
        setc(r, g, b)
        time.sleep(1)
    print('')
tjbcatch22 commented 1 year ago

Wow! It just worked! Stay tuned. I'm going to run it again and get debug...

tjbcatch22 commented 1 year ago

Works great. I attached the debug for reference.

What was modified? Seems like I can add the new code: `def setc(r, g, b): hexvalue = d._rgb_to_hexvalue(r, g, b, d.bulb_type)

payload = d.generate_payload(
    tinytuya.CONTROL,
    {
        d.DPS_INDEX_MODE[d.bulb_type]: d.DPS_MODE_COLOUR,
        d.DPS_INDEX_COLOUR[d.bulb_type]: hexvalue,
    },
)
d._send_receive(payload)

' to the top of bulb.py and other scripts to get color on the bulb? Right? Debug attached: Bulb_debug_Working.txt

tjbcatch22 commented 1 year ago

I noticed another post `https://github.com/jasonacox/tinytuya/issues/16' referring to "device22" and noticed that also in the my previous debug. I added that to the script and what looks like a cleaner debug (attached for reference).

I also notice that my bulb has a very limited range from the wifi source. This is not the fault of Tinytuya - just mentioning it as a finding. The bulb seem to have a range of about 10 ft from the wifi source, even with line of site. This seems strange, so I reflashed using cloudcutter and a generic tuya profile and had the same results. (I still needed device22 in the script).

Wondering if others have seem similar limited range from their bulbs Bulb_debug_WorkingBetter.txt

uzlonewolf commented 1 year ago

Yes, range is an issue with some bulbs. Usually the entire bottom part of the bulb has metal on the inside to help with heat dissipation, and the disc the LEDs are mounted to is a solid chunk of aluminum, so if the manufacturer took one of their existing bulbs and added WiFi as an afterthought then they could have done something dumb like enclosing the antenna inside all that metal.

jasonacox commented 1 year ago

What was modified?

TinyTuya uses a status response when you call set_version() to determine your bulb type and the DPS values to indicate if the bulb supports brightness, color temp and colour. When you call functions like set_colour(), it checks for capabilities before making the calls.

Current Status of Bulb: {u'dps': {u'26': 0, u'20': True, u'21': u'white', u'22': 1000}}

That is the status from your bulb. You have a type "B" bulb but for some reason it is not reporting a value for DPS '24' which is the color attribute. I suspect it shows up after you switch into color mode. Could you try this:

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

print("set_mode = white")
d.set_mode('white')
print(d.status())

print("set_mode = colour")
d.set_mode('colour')
print(d.status())

I don't know if there is a better way to handle this in TinyTuya but there is a workaround without writing your own function. You should be able to override the discovery values and declare the bulb to be color capable by doing this:

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

# override color mode
d.has_colour = True

# change color to blue
d.set_colour(0, 0, 255)
uzlonewolf commented 1 year ago

I don't know if there is a better way to handle this in TinyTuya

I have a few ideas but first need to ask: what is the problem this check is trying to solve? Unless there are devices which lock up on unknown DPS's I say just send it and let the device reject it if it doesn't like it. If the rejection causes lag then we could start with has_colour set to True and only change it to False after the first rejection/failure.

tjbcatch22 commented 1 year ago

Thank you Jason, Ill give that code a try.

jasonacox commented 1 year ago

@uzlonewolf I'm embarrassed to say I can't remember the basis for those conditionals. 😊 I suspect it is what you say and would cause long delays, lockups or exceptions so this was a 'clever' way to handle it. Of course, I naively assumed all smart bulbs and LEDs would behave the same and the classification of attributes based on the DPS set made sense. Not so much now. With this one use case, it is likely indicative of a larger population of devices that behave differently.

My first blush:

We could also:

jasonacox commented 1 year ago

@tjbcatch22 - I removed the bulb attribute block from the set_*() functions and released this as v1.10.1. You should be able to use set_colour() without the workaround now. Please test when you can. Thanks again for opening the issue.

pip install --upgrade tinytuya
tjbcatch22 commented 1 year ago

@jasonacox - Thank you for this! The colors and modes now work great from bulb.py. All Good !

jasonacox commented 1 year ago

Thanks, @tjbcatch22 ! I'll close this issue.