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.

79 lines
1.9 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. timer = True;
  9. #print(irsend.list_remotes())
  10. def turnAllProjectorsOn():
  11. print('UTC', datetime.now().time(), "turn all projectors on ...")
  12. irsend.send_once('panasonic_resa', ['KEY_POWER'])
  13. irsend.send_once('benq_resa', ['KEY_POWER'])
  14. def turnAllProjectorsOff():
  15. print('UTC', datetime.now().time(), "turn all projectors off ...")
  16. irsend.send_once('panasonic_resa', ['KEY_POWER2'])
  17. irsend.send_once('benq_resa', ['KEY_POWER'])
  18. time.sleep(2)
  19. irsend.send_once('panasonic_resa', ['KEY_POWER2'])
  20. irsend.send_once('benq_resa', ['KEY_POWER'])
  21. # HTTP Server
  22. class Simple(resource.Resource):
  23. isLeaf = True
  24. def render_GET(self, request):
  25. global timer
  26. print(request.uri)
  27. statustext = ""
  28. if request.uri == b"/on":
  29. statustext = "turn all projectors on ..."
  30. turnAllProjectorsOn()
  31. if request.uri == b"/off":
  32. statustext = "turn all projectors off ..."
  33. turnAllProjectorsOff()
  34. if request.uri == b"/timer-on":
  35. timer = True
  36. if request.uri == b"/timer-off":
  37. timer = False
  38. else:
  39. if timer == True:
  40. statustext = "Timer ist an"
  41. if timer == False:
  42. statustext = "Timer ist aus"
  43. html = '<b>%s</b>' % statustext
  44. return html.encode('utf-8')
  45. site = server.Site(Simple())
  46. reactor.listenTCP(8000, site)
  47. reactor.startRunning(False)
  48. # Time definitions in UTC (Vienna is UTC+2)
  49. schedule.every().day.at("19:00").do(turnAllProjectorsOn) # 21:00
  50. schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00
  51. while True:
  52. if timer == True:
  53. schedule.run_pending()
  54. time.sleep(1)
  55. # Webserver
  56. reactor.iterate()