Bladeren bron

add timer on off

master
Andreas Demmelbauer 4 jaren geleden
bovenliggende
commit
b90f1e0adb
2 gewijzigde bestanden met toevoegingen van 29 en 8 verwijderingen
  1. +4
    -0
      README.md
  2. +25
    -8
      ir-remote-timer.py

+ 4
- 0
README.md Bestand weergeven

@@ -1,3 +1,6 @@
remote control devices via infra-red using a timer and web requests.


```
sudo apt install git python3-pip lirc
```
@@ -22,6 +25,7 @@ pip3 install -r requirements.txt
```
sudo cp ir-remote-timer.service /lib/systemd/system/ir-remote-timer.service
sudo systemctl daemon-reload
sudo systemctl enable ir-remote-timer.service
```




+ 25
- 8
ir-remote-timer.py Bestand weergeven

@@ -8,6 +8,9 @@ from twisted.web import server, resource
from twisted.internet import reactor


timer = True;


#print(irsend.list_remotes())


@@ -18,18 +21,22 @@ def turnAllProjectorsOn():

def turnAllProjectorsOff():
print('UTC', datetime.now().time(), "turn all projectors off ...")
irsend.send_once('panasonic_resa', ['KEY_POWER'])
irsend.send_once('panasonic_resa', ['KEY_POWER2'])
irsend.send_once('benq_resa', ['KEY_POWER'])
time.sleep(2)
irsend.send_once('panasonic_resa', ['KEY_POWER'])
irsend.send_once('panasonic_resa', ['KEY_POWER2'])
irsend.send_once('benq_resa', ['KEY_POWER'])




# HTTP Server
class Simple(resource.Resource):
isLeaf = True

def render_GET(self, request):
print(request)
global timer
print(request.uri)
statustext = ""
if request.uri == b"/on":
statustext = "turn all projectors on ..."
@@ -37,10 +44,19 @@ class Simple(resource.Resource):
if request.uri == b"/off":
statustext = "turn all projectors off ..."
turnAllProjectorsOff()

if request.uri == b"/timer-on":
timer = True

if request.uri == b"/timer-off":
timer = False

else:
statustext = ""
html = '<b> %s </b>' % statustext
if timer == True:
statustext = "Timer ist an"
if timer == False:
statustext = "Timer ist aus"
html = '<b>%s</b>' % statustext
return html.encode('utf-8')

site = server.Site(Simple())
@@ -50,12 +66,13 @@ reactor.startRunning(False)


# Time definitions in UTC (Vienna is UTC+2)
schedule.every().day.at("21:00").do(turnAllProjectorsOn) # 23:00
schedule.every().day.at("19:00").do(turnAllProjectorsOn) # 21:00
schedule.every().day.at("01:00").do(turnAllProjectorsOff) # 03:00


while True:
schedule.run_pending()
if timer == True:
schedule.run_pending()
time.sleep(1)
# Webserver
reactor.iterate()

Laden…
Annuleren
Opslaan