Switch projectors on and off at a specified time
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

62 righe
1.6 KiB

  1. from py_irsend import irsend
  2. from datetime import datetime
  3. import schedule
  4. import time
  5. # http server
  6. from twisted.web import server, resource
  7. from twisted.internet import reactor
  8. site = server.Site(Simple())
  9. reactor.listenTCP(80, site)
  10. reactor.startRunning(False)
  11. #print(irsend.list_remotes())
  12. def turnAllProjectorsOn():
  13. print('UTC', datetime.now().time(), "turn all projectors on ...")
  14. irsend.send_once('panasonic_resa', ['KEY_POWER'])
  15. irsend.send_once('benq_resa', ['KEY_POWER'])
  16. def turnAllProjectorsOff():
  17. print('UTC', datetime.now().time(), "turn all projectors off ...")
  18. irsend.send_once('panasonic_resa', ['KEY_POWER'])
  19. irsend.send_once('benq_resa', ['KEY_POWER'])
  20. time.sleep(2)
  21. irsend.send_once('panasonic_resa', ['KEY_POWER'])
  22. irsend.send_once('benq_resa', ['KEY_POWER'])
  23. # HTTP Server
  24. class Simple(resource.Resource):
  25. isLeaf = True
  26. def render_GET(self, request):
  27. statustext = ""
  28. if request.prepath == "on":
  29. statustext = "turn all projectors on ..."
  30. turnAllProjectorsOn()
  31. if request.prepath == "off":
  32. statustext = "turn all projectors off ..."
  33. turnAllProjectorsOff()
  34. else:
  35. statustext = ""
  36. html = '<b>%s</b>' % statustext
  37. return html.encode('utf-8')
  38. # Time definitions in UTC (Vienna is UTC+2)
  39. schedule.every().day.at("21:00").do(turnAllProjectorsOn) # 23:00
  40. schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00
  41. while True:
  42. schedule.run_pending()
  43. time.sleep(1)
  44. # Webserver
  45. reactor.iterate()