From e14e282bec7adfe85238d9478faad1f32229de0e Mon Sep 17 00:00:00 2001 From: Andreas Demmelbauer Date: Thu, 4 Jun 2020 23:49:25 +0200 Subject: [PATCH] v1 --- README.md | 17 ++++++++++--- ir-remote-timer.py | 61 +++++++++++++++++++++++++++++++--------------- requirements.txt | 1 + 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 1aa5819..4bee310 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ``` -sudo apt install git python3-pip +sudo apt install git python3-pip lirc ``` ### Clone this repo @@ -26,7 +26,18 @@ sudo systemctl daemon-reload -### Setting up a random remote -Use `irrecord` to create a lirc Config file and copy the generated file in +### Setting up the infrared +Use `irrecord` to create a lirc Config file. You need an ir receiver for that. +`sudo irrecord -d /dev/lirc0` +and copy the generated file in `/etc/lirc/lircd.conf.d/your-remotes-name.lircd.conf` +remove devinput +`mv /etc/lirc/lircd.conf.d/devinput.lircd.conf /etc/lirc/lircd.conf.d/devinput.lircd.conf.dist` + +Add following lines to `/etc/modules` +``` +lirc_dev +lirc_rpi gpio_out_pin=22 +``` +https://indibit.de/raspberry-pi-mit-lirc-infrarot-befehle-senden-irsend/ \ No newline at end of file diff --git a/ir-remote-timer.py b/ir-remote-timer.py index f3debfb..5cb0e1d 100644 --- a/ir-remote-timer.py +++ b/ir-remote-timer.py @@ -1,34 +1,57 @@ 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 -irsend.list_remotes() - -def turnAllProjectorsOn(): - print("turn all projectors on ...") - irsend.send_once('logitech_z906', ['POWER']) - irsend.send_once('logitech_z906', ['POWER']) - - -def turnAllProjectorsOff(): - print("turn all projectors off ...") - irsend.send_once('logitech_z906', ['POWER']) - irsend.send_once('logitech_z906', ['POWER']) +#print(irsend.list_remotes()) -schedule.every().day.at("21:00").do(turnAllProjectorsOn) +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']) -schedule.every().day.at("06:00").do(turnAllProjectorsOff) +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): + statustext = "" + if request.prepath == "on": + statustext = "turn all projectors on ..." + turnAllProjectorsOn() + if request.prepath == "off": + statustext = "turn all projectors off ..." + turnAllProjectorsOff() + else: + statustext = "" + + html = '%s' % statustext + return html.encode('utf-8') + + + +# 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() diff --git a/requirements.txt b/requirements.txt index 38f4aaf..19f2383 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ py_irsend schedule +twisted \ No newline at end of file