Switch projectors on and off at a specified time
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

61 linhas
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. #print(irsend.list_remotes())
  9. def turnAllProjectorsOn():
  10. print('UTC', datetime.now().time(), "turn all projectors on ...")
  11. irsend.send_once('panasonic_resa', ['KEY_POWER'])
  12. irsend.send_once('benq_resa', ['KEY_POWER'])
  13. def turnAllProjectorsOff():
  14. print('UTC', datetime.now().time(), "turn all projectors off ...")
  15. irsend.send_once('panasonic_resa', ['KEY_POWER'])
  16. irsend.send_once('benq_resa', ['KEY_POWER'])
  17. time.sleep(2)
  18. irsend.send_once('panasonic_resa', ['KEY_POWER'])
  19. irsend.send_once('benq_resa', ['KEY_POWER'])
  20. # HTTP Server
  21. class Simple(resource.Resource):
  22. isLeaf = True
  23. def render_GET(self, request):
  24. statustext = ""
  25. if request.prepath == "on":
  26. statustext = "turn all projectors on ..."
  27. turnAllProjectorsOn()
  28. if request.prepath == "off":
  29. statustext = "turn all projectors off ..."
  30. turnAllProjectorsOff()
  31. else:
  32. statustext = ""
  33. html = '<b>%s</b>' % statustext
  34. return html.encode('utf-8')
  35. site = server.Site(Simple())
  36. reactor.listenTCP(8000, site)
  37. reactor.startRunning(False)
  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()