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

Music mode #118

Open
frodeheg opened this issue Mar 25, 2022 · 4 comments
Open

Music mode #118

frodeheg opened this issue Mar 25, 2022 · 4 comments
Labels
tuya_device Support for specific Tuya Devices

Comments

@frodeheg
Copy link

How is the music mode supposed to work?
If I have this python script:

a = tinytuya.BulbDevice(DEVICEID, DEVICEIP, DEVICEKEY)
a.set_version(3.3)
a.set_mode('music')
data = a.status()
print(data)

I get the following output
{'dps': {'20': True, '21': 'music', '22': 1000, '23': 750, '24': '007803e803e8', '25': '07464602000003e803e800000000464602007803e803e80000000046460200f003e803e800000000464602003d03e803e80000000046460200ae03e803e800000000464602011303e803e800000000', '26': 0, '41': True}}
The light only turn red but does not respond to sound. Should it?
I have no idea whether or not there is a microphone in the lightbulb but at least it did change to music mode.

@panic2k
Copy link

panic2k commented May 1, 2022

The Bulbs itself does not have a microphone.
As far i assume and little bit know the music mode differs from color mode by more responsiveness as color updates would not be send to cloud and maybe not stored on device itself. As i seen on iot.tuya.com music mode is send only. The devices although wont send a reply local. TinyTuya implements commands to set music mode, but for now no function for updating the device's colors in this mode. As i implemented my Tuya in DiyHue I did some research how the payload send to devices maybe could look like but i found nothing usable till now. The tuya documentation did not helped. The only thing i found is this json snippet:
{ "commands":[ { "code":"music_data", "value":{ "change_mode":"direct", "bright":500, "temperature":800, "h":201, "s":611, "v":999 } } ] }

Maybe its an idea to setup a mitm proxy for capturing traffic and try to decrypt messages in music mode with smarthome app or maybe jasonacox has an better idea. Would be glad to hear something about :-)

@jasonacox
Copy link
Owner

Hi @panic2k and @frodeheg . According to Tuya (see here), it seems that the app is the one that is sending color changes to the bulb. I'm sure you figured that part out by now. What we don't know is what the app is sending to the bulb.

It appears that DPS 27 is reserved for this (see here). If I use the async method, I can use this DPS to change the color in some random way, and the string I send seems to change (higher values have slower fades). I'm sure there is other combinations or string that drive more specialization. Perhaps the Phone app is just sending packets to indicate a beat which would cause the bulb to change to what appears to be the "beat of the music". In any case, here is a working script you can play with. See what you can figure out:

import tinytuya
import time

#tinytuya.set_debug() # uncomment if you want to see all packets

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

# Show status of device
data = d.status()
print('\nCurrent Status of Bulb: %r' % data)

# Music Test
print('Setting to Music')
d.set_mode('music')
data = d.status()

# Send some music data to bulb
x = 0
while (x<20):
    value = "%02d01" % x
    print (" > Sending %s" % value)
    payload = d.generate_payload(tinytuya.CONTROL, {"27": value})
    d.send(payload)
    if (x % 3):
        time.sleep(1)  # extend every 3 beat
    time.sleep(0.2)
    x = x + 1

# Done
print('\nDone')
d.set_white()

jasonacox added a commit that referenced this issue May 3, 2022
@panic2k
Copy link

panic2k commented Jun 19, 2022

Thank you, that's maybe great for some bulbs. I've tried with my GU10 bulbs, but they are stay just red. If i use Android App, the next color is displayed on phone - there must be an command to set the bulbs. I've no Idea how cloud messages could be decrypted, but maybe a deeper look at TuyaOS IDE could give an idea. In spare time i take a look this. For sure, that's no easy task. But maybe there's something useful there. :-)

@jasonacox
Copy link
Owner

Thanks @panic2k ! I can't help but wonder if this sequence is similar to sending IR commands for IR Tuya devices. You might check these out:

@jasonacox jasonacox added the tuya_device Support for specific Tuya Devices label Sep 26, 2022
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

3 participants