forked from jasonacox/tinytuya
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulb-music.py
59 lines (48 loc) · 1.46 KB
/
bulb-music.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# TinyTuya Example
# -*- coding: utf-8 -*-
"""
TinyTuya - Smart Bulb RGB Music Test
TODO: Figure out what strings to send to the bulb to
represent real music data, beats, note, fades, etc.
Author: Jason A. Cox
For more information see https://github.com/jasonacox/tinytuya
"""
import tinytuya
import time
#tinytuya.set_debug()
# SmartBulb
DEVICEID = "01234567891234567890"
DEVICEIP = "10.0.1.99"
DEVICEKEY = "0123456789abcdef"
DEVICEVERS = "3.3"
print("TinyTuya - Smart Bulb Music Test [%s]\n" % tinytuya.__version__)
print('TESTING: Device %s at %s with key %s version %s' %
(DEVICEID, DEVICEIP, DEVICEKEY, DEVICEVERS))
# Connect to Tuya BulbDevice
d = tinytuya.BulbDevice(DEVICEID, DEVICEIP, DEVICEKEY)
d.set_version(float(DEVICEVERS)) # IMPORTANT to always set version
# Keep socket connection open between commands
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 example music data to bulb
# TODO: Figure out what the value does and how to use it to
# represent real music data, beats, colors, fades
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()