Switch projectors on and off at a specified time
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 line
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. print(request)
  25. statustext = ""
  26. if request.uri == b"/on":
  27. statustext = "turn all projectors on ..."
  28. turnAllProjectorsOn()
  29. if request.uri == b"/off":
  30. statustext = "turn all projectors off ..."
  31. turnAllProjectorsOff()
  32. else:
  33. statustext = ""
  34. html = '<b> %s </b>' % statustext
  35. return html.encode('utf-8')
  36. site = server.Site(Simple())
  37. reactor.listenTCP(8000, site)
  38. reactor.startRunning(False)
  39. # Time definitions in UTC (Vienna is UTC+2)
  40. schedule.every().day.at("21:00").do(turnAllProjectorsOn) # 23:00
  41. schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00
  42. while True:
  43. schedule.run_pending()
  44. time.sleep(1)
  45. # Webserver
  46. reactor.iterate()