-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_control.py
More file actions
73 lines (60 loc) · 1.68 KB
/
basic_control.py
File metadata and controls
73 lines (60 loc) · 1.68 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""
Basic Govee device control example.
Demonstrates:
- Initializing the client
- Discovering devices
- Basic on/off control
- Setting brightness and color
"""
import time
from govee import GoveeClient, Colors
# Initialize client with your API key
client = GoveeClient(
api_key="your-api-key-here",
prefer_lan=True, # Try LAN first for faster response
log_level="INFO"
)
# Option 1: Discover devices from Cloud API (first-time setup)
print("Discovering devices...")
devices = client.discover_devices()
print(f"Found {len(devices)} devices")
# Export as Python modules for future use
client.export_as_modules("./")
# Option 2: Import device directly (after running export once)
# from govee_devices import garage_left
# device = garage_left
# Get a specific device
device = client.get_device("Garage Left")
print(f"Controlling device: {device.name}")
print(f" SKU: {device.sku}")
print(f" Supports LAN: {device.supports_lan}")
print(f" IP: {device.ip or 'Not set'}")
# Turn on
print("\nTurning on...")
client.power(device, on=True)
time.sleep(1)
# Set brightness to 50%
print("Setting brightness to 50%...")
client.set_brightness(device, 50)
time.sleep(1)
# Change colors
colors = [
("Red", Colors.RED),
("Green", Colors.GREEN),
("Blue", Colors.BLUE),
("Purple", Colors.PURPLE),
("Neon Pink", Colors.NEON_PINK)
]
for color_name, color_rgb in colors:
print(f"Setting color to {color_name}...")
client.set_color(device, color_rgb)
time.sleep(2)
# Set brightness to 100%
print("Setting brightness to 100%...")
client.set_brightness(device, 100)
time.sleep(1)
# Turn off
print("Turning off...")
client.power(device, on=False)
print("\nDone!")