-
Notifications
You must be signed in to change notification settings - Fork 3
/
brighten.py
46 lines (35 loc) · 1.46 KB
/
brighten.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
'''
brighten.py
Based in part on code from: https://github.com/ggravlingen/pytradfri/
Simply sets you light to minimum dimness then slowly brightens to max.
Make you you update the IP address to match your gateway's and
run $ python3 -i -m pytradfri IP to (re)create your
tradfri_standalone_psk.conf (Credentials file)
'''
from pytradfri import Gateway
from pytradfri.api.libcoap_api import APIFactory
from pytradfri.util import load_json, save_json
from time import sleep
# Change this IP address to your gateway
IP_ADDRESS = '192.168.0.158'
# Make sure you're in the same directory as this file
CONFIG_FILE = 'tradfri_standalone_psk.conf'
# Load in the file, get our password for the gateway and create an API
conf = load_json(CONFIG_FILE)
identity = conf[IP_ADDRESS].get('identity')
psk = conf[IP_ADDRESS].get('key')
api_factory = APIFactory(host=IP_ADDRESS, psk_id=identity, psk=psk)
# This section connects to the gateway and gets information on devices
api = api_factory.request
gateway = Gateway()
devices_command = gateway.get_devices()
devices_commands = api(devices_command)
devices = api(devices_commands)
# Create an array of objects that are lights
lights = [dev for dev in devices if dev.has_light_control]
# Brightness ranges from 0 to 254, so lets set the light in stages of 5
for brightness in range(0, 255, 5):
# Set the first light to 'brightness' and then pause for a moment
api(lights[0].light_control.set_dimmer(brightness))
sleep(0.1)