Browse Source

add timer on off

master
Andreas Demmelbauer 4 years ago
parent
commit
b90f1e0adb
2 changed files with 29 additions and 8 deletions
  1. +4
    -0
      README.md
  2. +25
    -8
      ir-remote-timer.py

+ 4
- 0
README.md View File

@@ -1,3 +1,6 @@
remote control devices via infra-red using a timer and web requests.


``` ```
sudo apt install git python3-pip lirc sudo apt install git python3-pip lirc
``` ```
@@ -22,6 +25,7 @@ pip3 install -r requirements.txt
``` ```
sudo cp ir-remote-timer.service /lib/systemd/system/ir-remote-timer.service sudo cp ir-remote-timer.service /lib/systemd/system/ir-remote-timer.service
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable ir-remote-timer.service
``` ```






+ 25
- 8
ir-remote-timer.py View File

@@ -8,6 +8,9 @@ from twisted.web import server, resource
from twisted.internet import reactor from twisted.internet import reactor




timer = True;


#print(irsend.list_remotes()) #print(irsend.list_remotes())




@@ -18,18 +21,22 @@ def turnAllProjectorsOn():


def turnAllProjectorsOff(): def turnAllProjectorsOff():
print('UTC', datetime.now().time(), "turn all projectors off ...") print('UTC', datetime.now().time(), "turn all projectors off ...")
irsend.send_once('panasonic_resa', ['KEY_POWER'])
irsend.send_once('panasonic_resa', ['KEY_POWER2'])
irsend.send_once('benq_resa', ['KEY_POWER']) irsend.send_once('benq_resa', ['KEY_POWER'])
time.sleep(2) time.sleep(2)
irsend.send_once('panasonic_resa', ['KEY_POWER'])
irsend.send_once('panasonic_resa', ['KEY_POWER2'])
irsend.send_once('benq_resa', ['KEY_POWER']) irsend.send_once('benq_resa', ['KEY_POWER'])






# HTTP Server # HTTP Server
class Simple(resource.Resource): class Simple(resource.Resource):
isLeaf = True isLeaf = True

def render_GET(self, request): def render_GET(self, request):
print(request)
global timer
print(request.uri)
statustext = "" statustext = ""
if request.uri == b"/on": if request.uri == b"/on":
statustext = "turn all projectors on ..." statustext = "turn all projectors on ..."
@@ -37,10 +44,19 @@ class Simple(resource.Resource):
if request.uri == b"/off": if request.uri == b"/off":
statustext = "turn all projectors off ..." statustext = "turn all projectors off ..."
turnAllProjectorsOff() turnAllProjectorsOff()

if request.uri == b"/timer-on":
timer = True

if request.uri == b"/timer-off":
timer = False

else: else:
statustext = ""
html = '<b> %s </b>' % statustext
if timer == True:
statustext = "Timer ist an"
if timer == False:
statustext = "Timer ist aus"
html = '<b>%s</b>' % statustext
return html.encode('utf-8') return html.encode('utf-8')


site = server.Site(Simple()) site = server.Site(Simple())
@@ -50,12 +66,13 @@ reactor.startRunning(False)




# Time definitions in UTC (Vienna is UTC+2) # Time definitions in UTC (Vienna is UTC+2)
schedule.every().day.at("21:00").do(turnAllProjectorsOn) # 23:00
schedule.every().day.at("19:00").do(turnAllProjectorsOn) # 21:00
schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00 schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00




while True: while True:
schedule.run_pending()
if timer == True:
schedule.run_pending()
time.sleep(1) time.sleep(1)
# Webserver # Webserver
reactor.iterate() reactor.iterate()

Loading…
Cancel
Save