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 #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_POWER']) irsend.send_once('benq_resa', ['KEY_POWER']) time.sleep(2) irsend.send_once('panasonic_resa', ['KEY_POWER']) irsend.send_once('benq_resa', ['KEY_POWER']) # HTTP Server class Simple(resource.Resource): isLeaf = True def render_GET(self, request): print(request) statustext = "" if request.uri == b"/on": statustext = "turn all projectors on ..." turnAllProjectorsOn() if request.uri == b"/off": statustext = "turn all projectors off ..." turnAllProjectorsOff() else: statustext = "" 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("21:00").do(turnAllProjectorsOn) # 23:00 schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00 while True: schedule.run_pending() time.sleep(1) # Webserver reactor.iterate()