-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitch.py
More file actions
90 lines (71 loc) · 2.37 KB
/
Copy pathswitch.py
File metadata and controls
90 lines (71 loc) · 2.37 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#! /usr/bin/python
# Imports
import RPi.GPIO as GPIO
import requests
import time
from lifxlan import LifxLAN, Light, WHITE
from gpiozero import Button
from time import sleep
# Turn off GPIO warnings
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
# Variables - Add your MAC and IP number here.
lifxlan = Light("d0:23:d5:2d:4e:60", "192.168.2.1")
currentstate = 0
button = Button(14)
previousstate = lifxlan.get_power()
lightname = lifxlan.get_label()
# Show current light state
if previousstate == 0:
print("The", lightname, "is currently OFF")
elif previousstate == 65535:
print("The", lightname, "is currently ON")
try:
print("Starting LiPiSwitch for the light named", lightname,"...")
print("")
print("lifXbutton Ready ...")
print("")
# Loop until user quits with CTRL-C
while True:
# If the Button is triggered
if button.is_pressed and previousstate == 0:
print("Button Pressed - Turning Light ON")
# LifxLAN light details
r = lifxlan.set_power("on")
h = lifxlan.set_brightness("65535") #Set the light to full brightness
g = lifxlan.set_color(WHITE) #Set the light to daylight
# Record new previous state
previousstate = 65535
#Wait 3 seconds before looping again
print("Waiting 3 seconds")
time.sleep(3)
print("")
print("Ready")
print("")
elif button.is_held:
print("Button Held - Dimming Light")
# LifxLAN light details
r = lifxlan.set_power("on")
h = lifxlan.set_brightness("5000")
#Wait 3 seconds before looping again
print("Waiting 3 seconds")
time.sleep(3)
print("")
print("Ready")
print("")
elif button.is_pressed and previousstate == 65535:
print("Button Pressed - Turning Light OFF")
# LifxLAN light details
r = lifxlan.set_power("off")
# Record new previous state
previousstate = 0
#Wait 3 seconds before looping again
print("Waiting 3 seconds")
time.sleep(3)
print("")
print("Ready")
print("")
except KeyboardInterrupt:
print("Quit")
# Reset GPIO settings
GPIO.cleanup()