from py_irsend import irsend from datetime import datetime import schedule import time # http server from twisted.web import server, resource from twisted.internet import reactor timer = True; #print(irsend.list_remotes()) def turnAllProjectorsOn(): print('UTC', datetime.now().time(), "turn all projectors on ...") irsend.send_once('panasonic_resa', ['KEY_POWER']) irsend.send_once('benq_resa', ['KEY_POWER']) def turnAllProjectorsOff(): print('UTC', datetime.now().time(), "turn all projectors off ...") irsend.send_once('panasonic_resa', ['KEY_POWER2']) irsend.send_once('benq_resa', ['KEY_POWER']) time.sleep(2) irsend.send_once('panasonic_resa', ['KEY_POWER2']) irsend.send_once('benq_resa', ['KEY_POWER']) # HTTP Server class Simple(resource.Resource): isLeaf = True def render_GET(self, request): global timer print(request.uri) statustext = "" if request.uri == b"/on": statustext = "turn all projectors on ..." turnAllProjectorsOn() if request.uri == b"/off": statustext = "turn all projectors off ..." turnAllProjectorsOff() if request.uri == b"/timer-on": timer = True if request.uri == b"/timer-off": timer = False else: if timer == True: statustext = "Timer ist an" if timer == False: statustext = "Timer ist aus" html = '%s' % statustext return html.encode('utf-8') site = server.Site(Simple()) reactor.listenTCP(8000, site) reactor.startRunning(False) # Time definitions in UTC (Vienna is UTC+2) schedule.every().day.at("19:00").do(turnAllProjectorsOn) # 21:00 schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00 while True: if timer == True: schedule.run_pending() time.sleep(1) # Webserver reactor.iterate()