-
Notifications
You must be signed in to change notification settings - Fork 11
/
livolo.py
executable file
·70 lines (62 loc) · 3.27 KB
/
livolo.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
60
61
62
63
64
65
66
67
68
69
70
import time
import sys
import RPi.GPIO as GPIO
off = '1242424352424342424242424242425342524342'
on = '124242435242434242424242424242425243424242'
if sys.argv[1:] == 'off':
NUM_ATTEMPTS = 1000
else:
NUM_ATTEMPTS = 150
TRANSMIT_PIN = 17
def transmit_code(code):
'''Transmit a chosen code string using the GPIO transmitter'''
GPIO.setmode(GPIO.BCM)
GPIO.setup(TRANSMIT_PIN, GPIO.OUT)
for t in range(NUM_ATTEMPTS):
for i in code:
if i == '1':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(.00055);
GPIO.output(TRANSMIT_PIN, 0)
elif i == '2':
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(.00011);
GPIO.output(TRANSMIT_PIN, 1)
elif i == '3':
GPIO.output(TRANSMIT_PIN, 0)
time.sleep(.000303);
GPIO.output(TRANSMIT_PIN, 1)
elif i == '4':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(.00011);
GPIO.output(TRANSMIT_PIN, 0)
elif i == '5':
GPIO.output(TRANSMIT_PIN, 1)
time.sleep(.00029);
GPIO.output(TRANSMIT_PIN, 0)
else:
continue
GPIO.output(TRANSMIT_PIN, 0)
GPIO.cleanup()
if __name__ == '__main__':
for argument in sys.argv[1:]:
exec('transmit_code(' + str(argument) + ')')
# How to use:: I am putting this here, because it seems few people have figured out livolo switches.
# Hold down livolo light switch for 5 seconds and wait for a beep.
# Run ```python livolo.py on```
# Livolo light switch should beep again, signalling it is paired
# Now running ```python livolo.py on``` will toggle the switch.
# ```python livolo.py off``` is global to all switches and should work out of box.
# The following lines are possible RF codes which can be learned by the switch.
# Just make them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