-
Notifications
You must be signed in to change notification settings - Fork 1
/
Telegram_Relay.py
68 lines (60 loc) · 1.84 KB
/
Telegram_Relay.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
import time, datetime
import PiRelay
import telepot
from telepot.loop import MessageLoop
relay1 = PiRelay.Relay("RELAY1")
relay2 = PiRelay.Relay("RELAY2")
relay3 = PiRelay.Relay("RELAY3")
relay4 = PiRelay.Relay("RELAY4")
def action(msg):
chat_id = msg['chat']['id']
command = msg['text']
print('Received: %s' % command)
if 'ON' in command:
message = "Turned ON "
if 'Relay 1' in command:
message = message + "Relay 1"
relay1.on()
elif 'Relay 2' in command:
message = message + "Relay 2"
relay2.on()
elif 'Relay 3' in command:
message = message + "Relay 3"
relay3.on()
elif 'Relay 4' in command:
message = message + "green "
relay4.on()
elif 'all' in command:
message = message + "all Relay's"
relay1.on()
relay2.on()
relay3.on()
relay4.on()
telegram_bot.sendMessage (chat_id, message)
if 'OFF' in command:
message = "Turned OFF "
if 'Relay 1' in command:
message = message + "Relay 1"
relay1.off()
if 'Relay 2' in command:
message = message + "Relay 2"
relay2.off()
if 'Relay 3' in command:
message = message + "Relay 3"
relay3.off()
if 'Relay 4' in command:
message = message + "Relay 4"
relay4.off()
if 'all' in command:
message = message + "all Relay's "
relay1.off()
relay2.off()
relay3.off()
relay4.off()
telegram_bot.sendMessage (chat_id, message)
telegram_bot = telepot.Bot('Enter your API Key')
print (telegram_bot.getMe())
MessageLoop(telegram_bot, action).run_as_thread()
print('Running....')
while 1:
time.sleep(10)