This commit is contained in:
Kai Wansart 2018-02-02 00:21:59 +01:00
commit 9c3e560900
36 changed files with 1114 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
app/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

80
app/config.py Normal file
View File

@ -0,0 +1,80 @@
import os.path
import json, codecs
##---------------------------------------------------------------------------------------##
class Config(object):
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
def __init__(self):
##-----------------------------------------------------------------------------------##
print("Config initialisiert")
##-----------------------------------------------------------------------------------##
def defaultSettings(self):
##-----------------------------------------------------------------------------------##
print("Returning Default-Settings")
data = {
"yeelight" : {
"dunkel" : "1",
"hell" : "100",
"warm" : "1700",
"normal" : "3000",
"kalt" : "6500"
}
}
return data
##-----------------------------------------------------------------------------------##
def defaultDevices(self):
##-----------------------------------------------------------------------------------##
print("Returning Default-Devices")
data = {}
return data
##-----------------------------------------------------------------------------------##
def read(self, type):
##-----------------------------------------------------------------------------------##
data = None
if(type == "settings"):
print("Reading 'settings.json'")
if(os.path.isfile("config/settings.json")):
with open('config/settings.json', encoding='utf-8') as data_file:
try:
data = json.loads(data_file.read())
except:
print("settings.json konnte nicht gelesen werden")
data = self.defaultSettings()
self.writeConfig("settings", data)
print("Settings loaded")
else:
data =self.defaultSettings()
self.writeConfig("settings", data)
else:
print("Reading 'devices.json'")
if(os.path.isfile("config/devices.json")):
with open('config/devices.json', encoding='utf-8') as data_file:
try:
data = json.loads(data_file.read())
except:
print("devices.json konnte nicht gelesen werden")
data = self.defaultDevices()
self.writeConfig("devices", data)
print("Devices loaded")
else:
data = self.defaultDevices()
self.writeConfig("devices", data)
return data
##-----------------------------------------------------------------------------------##
def writeConfig(self, type, data):
##-----------------------------------------------------------------------------------##
if(type == "settings"):
print("Writing 'settings.json'")
with open('config/settings.json', 'w') as outfile:
json.dump(data, outfile, indent=4)
print("Settings written")
else:
print("Writing 'devices.json'")
with open('config/devices.json', 'w') as outfile:
json.dump(data, outfile, indent=4)
print("Devices written")

BIN
app/devices/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

25
app/devices/denon.py Normal file
View File

@ -0,0 +1,25 @@
import denonavr
##---------------------------------------------------------------------------------------##
class Denon(object):
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
def __init__(self, device):
##-----------------------------------------------------------------------------------##
self.device = denonavr.DenonAVR(device['ip'])
##-----------------------------------------------------------------------------------##
def power(self, state=None):
##-----------------------------------------------------------------------------------##
if(state==None):
return -1
if(state=="on"):
self.device.power_on()
else:
self.device.power_off()
##-----------------------------------------------------------------------------------##
def setInput(self, input):
##-----------------------------------------------------------------------------------##
self.device.input_func = input

44
app/devices/ssh.py Normal file
View File

@ -0,0 +1,44 @@
from paramiko import SSHClient
##---------------------------------------------------------------------------------------##
class SSH(object):
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
def __init__(self, devices):
##-----------------------------------------------------------------------------------##
for device in devices:
self.devices[device] = {}
self.devices[device]['user'] = devices[device]['user']
self.devices[device]['ip'] = devices[device]['ip']
##-----------------------------------------------------------------------------------##
def command(self, device, command):
##-----------------------------------------------------------------------------------##
self.client = SSHClient()
self.client.load_system_host_keys()
self.client.connect(self.devices[device]['ip'], self.devices[device]['user'])
if(command=="shutdown"):
self.shutdown(device)
if(command=="reboot"):
self.reboot(device)
if(command=="upgrade"):
self.upgrade(device)
##-----------------------------------------------------------------------------------##
def shutdown(self, device):
##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('poweroff')
##-----------------------------------------------------------------------------------##
def reboot(self, device):
##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('reboot')
##-----------------------------------------------------------------------------------##
def upgrade(self, device):
##-----------------------------------------------------------------------------------##
self.connect()
self.client.exec_command('apt update && apt upgrade -y')

19
app/devices/wol.py Normal file
View File

@ -0,0 +1,19 @@
from wakeonlan import wol
##---------------------------------------------------------------------------------------##
class WOL(object):
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
def __init__(self, devices):
##-----------------------------------------------------------------------------------##
count = 0
for device in devices:
self.devices[device] = devices[device]['mac']
##-----------------------------------------------------------------------------------##
def wakeDevice(self, device):
##-----------------------------------------------------------------------------------##
if(device in self.devices):
wol.send_magic_packet(self.devices[device])

328
app/devices/yeelight.py Normal file
View File

@ -0,0 +1,328 @@
from yeelight import *
import time
##---------------------------------------------------------------------------------------##
class Yeelight(object):
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
def __init__(self, bulbs):
##-----------------------------------------------------------------------------------##
self.bulbs = {}
self.groups = {}
for bulb in bulbs:
try:
self.bulbs.update({bulb : Bulb(bulbs[bulb]['ip'],auto_on=True)})
except:
print("ERROR: Config not saved for " + bulb)
try:
for group in bulbs[bulb]['groups']:
groupName = bulbs[bulb]['groups'][group]
if(groupName not in self.groups):
print("Create new Group " + groupName)
self.groups[groupName] = {}
self.groups[groupName][bulb] = bulb
except:
print(bulb + " ist in keiner Gruppe")
##-----------------------------------------------------------------------------------##
def command(self, data):
##-----------------------------------------------------------------------------------##
for device in data:
group = 0
if device in self.groups:
group = True
if(device in self.bulbs or device in self.groups):
if 'power' in data[device]:
self.power(device, group, data[device]['power'])
if(data[device]['power'] == "off"):
return 0
if 'brightness' in data[device]:
self.brightness(device, group, data[device]['brightness'])
if 'r' in data[device] or 'g' in data[device] or 'b' in data[device]:
if 'r' in data[device]:
r = data[device]['r']
else:
r = "0"
if 'g' in data[device]:
g = data[device]['g']
else:
g = "0"
if 'b' in data[device]:
b = data[device]['b']
else:
b = "0"
self.color(device, group, r, g, b)
if 'temperature' in data[device]:
self.temperature(device, group, data[device]['temperature'])
##-----------------------------------------------------------------------------------##
def power(self, device, group=None, state=None):
##-----------------------------------------------------------------------------------##
if(state==None):
return -1
if(device==None):
for bulb in self.bulbs:
self.powerBulb(device, state)
if(group == True):
for bulb in self.groups[device]:
self.powerBulb(bulb, state)
else:
if(device in self.bulbs):
self.powerBulb(device, state)
##-----------------------------------------------------------------------------------##
def powerBulb(self, device, state):
##-----------------------------------------------------------------------------------##
if(device in self.bulbs):
error = False
try:
oldState = self.bulbs[device].get_properties()
except:
print(device + ": Konnte nicht angesteuert werden")
error = True
finally:
if(str(oldState['power']) != str(state)):
if(state=="on"):
self.bulbs[device].turn_on()
print(device + " turned on")
else:
self.bulbs[device].turn_off()
print(device + " turned off")
if(error == True):
for count in range(0,10):
try:
oldState = self.bulbs[device].get_properties()
except:
print(device + ": Konnte nicht angesteuert werden")
finally:
if(str(oldState['power']) != str(state)):
if(state=="on"):
self.bulbs[device].turn_on()
print(device + " turned on")
else:
self.bulbs[device].turn_off()
print(device + " turned off")
try:
oldState = self.bulbs[device].get_properties()
if(oldState['power'] == str(state)):
break
except:
print(device + " keine Veraenderung")
##-----------------------------------------------------------------------------------##
def brightness(self, device, group, state=None):
##-----------------------------------------------------------------------------------##
if(state==None):
return -1
if(device==None):
for bulb in self.bulbs:
self.brightnessBulb(device, state)
if(group == True):
for bulb in self.groups[device]:
self.brightnessBulb(bulb, state)
else:
if(device in self.bulbs):
self.brightnessBulb(device, state)
##-----------------------------------------------------------------------------------##
def brightnessBulb(self, device, state):
##-----------------------------------------------------------------------------------##
if(device in self.bulbs):
error = False
try:
oldState = self.bulbs[device].get_properties()
print(oldState)
except:
print(device + ": Konnte nicht angesteuert werden")
error = True
finally:
if(str(oldState['bright']) != str(state)):
self.bulbs[device].set_brightness(int(state))
print(device + " turned brightness to " + str(state))
if(error == True):
for count in range(0,10):
try:
oldState = self.bulbs[device].get_properties()
except:
print(device + ": Konnte nicht angesteuert werden")
finally:
if(str(oldState['brigh']) != str(state)):
self.bulbs[device].set_brightness(int(state))
print(device + " turned brightness to " + str(state))
try:
oldState = self.bulbs[device].get_properties()
if(oldState['bright'] == str(state)):
break
except:
print(device + " keine Veraenderung")
##-----------------------------------------------------------------------------------##
def temperature(self, device, group, state=None):
##-----------------------------------------------------------------------------------##
if(state==None):
return -1
if(device==None):
for bulb in self.bulbs:
self.temperatureBulb(device, state)
if(group == True):
for bulb in self.groups[device]:
self.temperatureBulb(bulb, state)
else:
if(device in self.bulbs):
self.temperatureBulb(device, state)
##-----------------------------------------------------------------------------------##
def temperatureBulb(self, device, state):
##-----------------------------------------------------------------------------------##
if(device in self.bulbs):
error = False
try:
oldState = self.bulbs[device].get_properties()
except:
print(device + ": Konnte nicht angesteuert werden")
error = True
finally:
if(str(oldState['ct']) != str(state)):
self.bulbs[device].set_color_temp(int(state))
print(device + " turned temperature to " + str(state))
if(error == True):
for count in range(0,10):
try:
oldState = self.bulbs[device].get_properties()
except:
print(device + ": Konnte nicht angesteuert werden")
finally:
if(str(oldState['ct']) != str(state)):
self.bulbs[device].set_color_temp(int(state))
print(device + " turned temperature to " + str(state))
try:
oldState = self.bulbs[device].get_properties()
if(oldState['ct'] == str(state)):
break
except:
print(device + " keine Veraenderung")
##-----------------------------------------------------------------------------------##
def color(self, device, group, r, g, b):
##-----------------------------------------------------------------------------------##
if(device==None):
for bulb in self.bulbs:
self.colorBulb(device, r, g, b)
if(group == True):
for bulb in self.groups[device]:
self.colorBulb(bulb, r, g, b)
else:
if(device in self.bulbs):
self.colorBulb(device, r, g, b)
##-----------------------------------------------------------------------------------##
def colorBulb(self, device, r, g, b):
##-----------------------------------------------------------------------------------##
bulbCount = 0
bulbCheck = 0
if(device in self.bulbs):
error = False
try:
bulbCount = bulbCount + 1
oldState = self.bulbs[device].get_properties()
except:
print(device + ": Konnte nicht angesteuert werden")
error = True
finally:
self.bulbs[device].set_rgb(int(r), int(g), int(b))
print(device + " color r:" + str(r) + " g:" + str(g) + " b:" + str(b))
bulbCheck = bulbCheck + 1
if(bulbCount != bulbCheck):
for count in range(0,10):
bulbCount = 0
bulbCheck = 0
try:
bulbCount = bulbCount + 1
oldState = self.bulbs[device].get_properties()
except:
print(device + ": Konnte nicht angesteuert werden")
error = True
finally:
self.bulbs[device].set_rgb(int(r), int(g), int(b))
print(device + " color r:" + str(r) + " g:" + str(g) + " b:" + str(b))
bulbCheck = bulbCheck + 1
if(bulbCheck==bulbCount):
return 0
##-----------------------------------------------------------------------------------##
def temperatureTransition(self, startTemp=1700, endTemp=6500, startBrightness=100,
endBrightness=100, seconds=0, count=None):
##-----------------------------------------------------------------------------------##
if(count==None):
count=10
duration = seconds*1000
transitions = [
TemperatureTransition(startTemp, duration, startBrightness),
SleepTransition(duration),
TemperatureTransition(endTemp, duration, endBrightness)
]
flow = Flow(
count=1,
action=Flow.actions.recover,
transitions=transitions
)
self.temperature(startBrightness)
self.brightness(startBrightness)
bulbCount = 0
bulbCheck = 0
for bulb in self.bulbs:
bulbCount = bulbCount + 1
try:
oldState = self.bulbs[bulb].get_properties()
except:
print(bulb + ": Konnte nicht angesteuert werden")
finally:
self.bulbs[bulb].start_flow(flow)
print(bulb + " Flow")
bulbCheck = bulbCheck + 1
if(bulbCount == bulbCheck):
return 0
else:
if(count!=0):
time.sleep(.250)
temperatureTransition(startTemp, endTemp, startBrightness, endBrightness,seconds,count-1)
else:
print("Zu viele Versuche. Fehlgeschlagen!")
return -1
return 0
##-----------------------------------------------------------------------------------##
def stopTransition(self, count=None):
##-----------------------------------------------------------------------------------##
if(count==None):
count=10
bulbCount = 0
bulbCheck = 0
for bulb in self.bulbs:
bulbCount = bulbCount + 1
try:
oldState = self.bulbs[bulb].get_properties()
except:
print(bulb + ": Konnte nicht angesteuert werden")
finally:
self.bulbs[bulb].stop_flow()
bulbCheck = bulbCheck + 1
if(bulbCount == bulbCheck):
return 0
else:
if(count!=0):
time.sleep(.250)
stopTransition(count-1)
else:
print("Zu viele Versuche. Fehlgeschlagen!")
return -1
return 0

91
app/webserver.py Normal file
View File

@ -0,0 +1,91 @@
from flask import Flask, request
##---------------------------------------------------------------------------------------##
class Webserver(object):
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
def __init__(self, config):
##-----------------------------------------------------------------------------------##
print("Webserver initialisiert")
self.settings = config.read("settings")
self.devices = config.read("devices")
##-----------------------------------------------------------------------------------##
def run(self):
##-----------------------------------------------------------------------------------##
app = Flask(__name__)
if(self.devices['yeelight'] != None):
print("Enabled Yeelight")
from app.devices import yeelight
self.yeelight = yeelight.Yeelight(self.devices['yeelight'])
@app.route('/yeelight', methods=['POST'])
def yeelight():
app.logger.debug("JSON received...")
app.logger.debug(request.json)
if request.json:
data = request.get_json(force=True)
self.yeelight.command(data)
return '200'
else:
return '500'
else:
print("Disabled Yeelight")
if(self.devices['ssh'] != None):
print("Enabled SSH")
from app.devices import ssh
self.ssh = ssh.SSH(self.devices['ssh'])
@app.route('/ssh', methods=['POST'])
def ssh():
app.logger.debug("JSON received...")
app.logger.debug(request.json)
if request.json:
data = request.get_json(force=True)
self.ssh.command(data)
return '200'
else:
return '500'
else:
print("Disabled SSH")
if(self.devices['wol'] != None):
print("Enabled WOL")
from app.devices import wol
self.wol = wol.WOL(self.devices['wol'])
@app.route('/wol', methods=['POST'])
def wol():
app.logger.debug("JSON received...")
app.logger.debug(request.json)
if request.json:
data = request.get_json(force=True)
self.wol.command(data)
return '200'
else:
return '500'
else:
print("Disabled SSH")
if(self.devices['denon'] != None):
print("Enabled Denon")
from app.devices import denon
self.denon = wol.WOL(self.devices['denon'])
@app.route('/denon', methods=['POST'])
def denon():
app.logger.debug("JSON received...")
app.logger.debug(request.json)
if request.json:
data = request.get_json(force=True)
self.denon.command(data)
return '200'
else:
return '500'
else:
print("Disabled Denon")
app.run(debug=False, host='0.0.0.0')

BIN
config/.DS_Store vendored Normal file

Binary file not shown.

51
config/devices.json Normal file
View File

@ -0,0 +1,51 @@
{
"yeelight" : {
"fernseher" : {
"ip" : "192.168.178.127",
"type" : "rgb",
"groups" : {
"1" : "passiv",
"2" : "zimmer"
}
},
"regal" : {
"ip" : "192.168.178.128",
"type" : "rgb",
"groups" : {
"1" : "passiv",
"2" : "zimmer"
}
},
"monitor" : {
"ip" : "192.168.178.126",
"type" : "rgb",
"groups" : {
"1" : "passiv",
"2" : "zimmer"
}
},
"bett" : {
"ip" : "192.168.178.122",
"type" : "rgb",
"groups" : {
"1" : "zimmer"
}
}
},
"ssh" : {
"nas" : {
"ip" : "192.168.178.81",
"user" : "root"
}
},
"wol" : {
"nas" : { "mac" : "38.EA.A7.A1.09.D7" }
},
"denon" : {
"ip" : "192.168.178.69",
"input" : {
"TV" : "TV Audio",
"Internet Radio" : "Internet Radio"
}
}
}

View File

@ -0,0 +1,36 @@
{
"yeelight" : {
"fernseher" : {
"ip" : "192.168.178.127",
"type" : "rgb"
},
"regal" : {
"ip" : "192.168.178.128",
"type" : "rgb"
},
"monitor" : {
"ip" : "192.168.178.126",
"type" : "rgb"
},
"bett" : {
"ip" : "192.168.178.122",
"type" : "rgb"
}
},
"ssh" : {
"nas" : {
"ip" : "192.168.178.81",
"user" : "root"
}
},
"wol" : {
"nas" : { "mac" : "38.EA.A7.A1.09.D7" }
},
"denon" : {
"ip" : "192.168.178.69",
"input" : {
"TV" : "TV Audio",
"Internet Radio" : "Internet Radio"
}
}
}

9
config/settings.json Normal file
View File

@ -0,0 +1,9 @@
{
"yeelight": {
"dunkel": "1",
"hell": "100",
"warm": "1700",
"normal": "3000",
"kalt": "6500"
}
}

View File

@ -0,0 +1,9 @@
{
"yeelight" : {
"dunkel" : "1",
"hell" : "100",
"warm" : "1700",
"normal" : "3000",
"kalt" : "6500"
}
}

8
readme.md Normal file
View File

@ -0,0 +1,8 @@
# TODO
1. Return available commands
2. Presets (Yeelight)
3. Website.....
4. Yamaha Receiver
5. Yeelight Flow
6. Wecker

54
remote.py Normal file
View File

@ -0,0 +1,54 @@
import serial
import requests
import time
from app import yeelight
bulbs = {
"fernseher" : { "ip" : "192.168.178.127" },
"regal" : { "ip" : "192.168.178.128" },
"monitor" : { "ip" : "192.168.178.126" },
"bett" : { "ip" : "192.168.178.122" }
}
yeelight = yeelight.Yeelight(bulbs)
ser = serial.Serial('/dev/ttyUSB0', 9600)
while 1 :
out = ''
while ser.inWaiting() > 0:
out = str(ser.readline())
if out != '':
l = list(out)
try:
del(l[0])
del(l[0])
del(l[2])
del(l[2])
del(l[2])
del(l[2])
del(l[2])
out = "".join(l)
#print("try")
except:
print("Fehlerhafter Wert")
finally:
print(out)
# Taste 3
if(out == "31"): # Abend
yeelight.color(0,0,255)
if(out == "30"): # Nacht
yeelight.temperature(1700)
yeelight.brightness(1)
# Taste 4
if(out == "41"): # Hell
yeelight.brightness(100)
if(out == "40"): # Dunkel
yeelight.brightness(1)
# Taste 5
if(out == "51"): # An
yeelight.power("on")
if(out == "50"): # Aus
yeelight.power("off")
time.sleep(.250)

10
server.py Normal file
View File

@ -0,0 +1,10 @@
from app import config, webserver
##---------------------------------------------------------------------------------------##
## Main Program
##---------------------------------------------------------------------------------------##
if __name__ == '__main__':
config = config.Config()
webserver = webserver.Webserver(config)
webserver.run()

180
server_old.py Normal file
View File

@ -0,0 +1,180 @@
#!flask/bin/python
from flask import Flask, request
from app import yeelight, linux, denon
import pprint, json
class LoggingMiddleware(object):
def __init__(self, app):
self._app = app
def __call__(self, environ, resp):
errorlog = environ['wsgi.errors']
pprint.pprint(('REQUEST', environ), stream=errorlog)
def log_response(status, headers, *args):
pprint.pprint(('RESPONSE', status, headers), stream=errorlog)
return resp(status, headers, *args)
return self._app(environ, log_response)
global devices
devices = None
def loadConfig():
with open('devices.json', encoding='utf-8') as data_file:
devices = json.loads(data_file.read())
##---------------------------------------------------------------------------------------##
## Config
##---------------------------------------------------------------------------------------##
#bulbs = {
# "fernseher" : { "ip" : "192.168.178.127" },
# "regal" : { "ip" : "192.168.178.128" },
# "monitor" : { "ip" : "192.168.178.126" },
# "bett" : { "ip" : "192.168.178.122" }
# }
brightnessDark = 1
brightnessBright = 100
temperatureWarm = 1700
temperatureNormal = 3000
temperatureCold = 6500
#sshIp = "192.168.178.81"
#sshUser = "root"
#wakeonlanMac = "38.EA.A7.A1.09.D7"
#
#denonIp = "192.168.178.69"
##---------------------------------------------------------------------------------------##
## Init
##---------------------------------------------------------------------------------------##
def init():
app = Flask(__name__)
yeelight = yeelight.Yeelight(devices['yeelight']['rgb'])
wakeonlan = linux.WakeOnLan()
sshcmd = linux.SSHCmd(devices['ssh']['nas']['ip'], devices['ssh']['nas']['user']) # fuer mehrere Verbindungen, mehrere Instanzen erzeugen!
denon = denon.Denon(devices['denon']['ip'])
##---------------------------------------------------------------------------------------##
## HTTP REQUESTS
##---------------------------------------------------------------------------------------##
##-----------------------------------------------------------------------------------##
## Yeelight
##-----------------------------------------------------------------------------------##
@app.route('/bulb/on', methods=['PUT', 'POST'])
def httpBulbOn():
yeelight.power("on")
return 'OK'
@app.route('/bulb/off', methods=['PUT', 'POST'])
def httpBulbOff():
yeelight.power("off")
return 'OK'
#@app.route('/bulb/brightness', methods=['PUT', 'POST'])
#def httpBrightness():
# data = str(request.data)
# brightness = int(data["brightness"])
# if brightness <= 100 and brightness >= 0:
# yeelight.brightness(brightness)
# return 'OK'
@app.route('/bulb/dark', methods=['PUT', 'POST'])
def httpBulbBrightnessDark():
yeelight.brightness(brightnessDark)
return 'OK'
@app.route('/bulb/bright', methods=['PUT', 'POST'])
def httpBulbBrightnessBright():
yeelight.brightness(brightnessBright)
return 'OK'
@app.route('/bulb/blue', methods=['PUT', 'POST'])
def httpBulbColorBlue():
yeelight.color(0,0,255)
return 'OK'
@app.route('/bulb/red', methods=['PUT', 'POST'])
def httpBulbColorRed():
yeelight.color(255,0,0)
return 'OK'
@app.route('/bulb/warm', methods=['PUT', 'POST'])
def httpBulbTempWarm():
yeelight.temperature(temperatureWarm)
return 'OK'
@app.route('/bulb/cold', methods=['PUT', 'POST'])
def httpBulbTempCold():
yeelight.temperature(temperatureCold)
return 'OK'
@app.route('/bulb/normal', methods=['PUT', 'POST'])
def httpBulbNormal():
yeelight.temperature(temperatureNormal)
return 'OK'
@app.route('/bulb/abend', methods=['PUT', 'POST'])
def httpBulbEvening():
yeelight.color(0,0,255)
return 'OK'
@app.route('/bulb/nacht', methods=['PUT', 'POST'])
def httpBulbNight():
yeelight.temperature(temperatureWarm)
yeelight.brightness(brightnessDark)
return 'OK'
@app.route('/bulb/flowMorgen', methods=['PUT', 'POST'])
def httpBulbFlowMorning():
yeelight.temperatureTransition(startTemp=1700, endTemp=6500, startBrightness=0,
endBrightness=100, seconds=60*15)
return 'OK'
@app.route('/bulb/flowNacht', methods=['PUT', 'POST'])
def httpBulbFlowNight():
yeelight.temperatureTransition(startTemp=1700, endTemp=1700, startBrightness=100,
endBrightness=1, seconds=60*15)
return 'OK'
@app.route('/bulb/flowStopp', methods=['PUT', 'POST'])
def httpBulbFlowStop():
yeelight.stopTransition()
return 'OK'
##-----------------------------------------------------------------------------------##
## Denon
##-----------------------------------------------------------------------------------##
@app.route('/denon/on', methods=['PUT', 'POST'])
def httpReceiverOn():
denon.power("on")
return 'OK'
@app.route('/denon/off', methods=['PUT', 'POST'])
def httpReceiverOff():
denon.power("off")
return 'OK'
@app.route('/denon/inet', methods=['PUT', 'POST'])
def httpReceiverInet():
denon.setInput("Internet Radio")
return 'OK'
@app.route('/denon/tv', methods=['PUT', 'POST'])
def httpReceiverTv():
denon.setInput("TV Audio")
return 'OK'
##-----------------------------------------------------------------------------------##
## SSH
##-----------------------------------------------------------------------------------##
@app.route('/wol/nas', methods=['PUT', 'POST'])
def httpNasOn():
wakeonlan.wakeDevice(devices['wol']['nas']['mac'])
return 'OK'
@app.route('/nas/poweroff', methods=['PUT', 'POST'])
def httpNasOff():
sshcmd.shutdown
return 'OK'
@app.route('/nas/reboot', methods=['PUT', 'POST'])
def httpNasReboot():
sshcmd.reboot()
return 'OK'
@app.route('/nas/update', methods=['PUT', 'POST'])
def httpNasUpdate():
sshcmd.upgrade()
return 'OK'
##---------------------------------------------------------------------------------------##
## Main Program
##---------------------------------------------------------------------------------------##
if __name__ == '__main__':
#app.wsgi_app = LoggingMiddleware(app.wsgi_app)
loadConfig()
init()
app.run(debug=True, host='0.0.0.0')

12
test/yeelight.json Normal file
View File

@ -0,0 +1,12 @@
{
"fernseher" : {
"power" : "on",
"brightness" : "50",
"r" : "100",
"g" : "0",
"b" : "100"
},
"bett" : {
"power" : "off"
}
}

9
test/yeelightG.json Normal file
View File

@ -0,0 +1,9 @@
{
"zimmer" : {
"power" : "on",
"brightness" : "50",
"r" : "100",
"g" : "0",
"b" : "50"
}
}

BIN
www/.DS_Store vendored Normal file

Binary file not shown.

0
www/css/main.css Normal file
View File

BIN
www/html/.DS_Store vendored Normal file

Binary file not shown.

33
www/html/devices.html Normal file
View File

@ -0,0 +1,33 @@
<div class="container-fluid text-center bg-grey">
<h2>Lampen</h2>
<div class="row text-center">
<div class="col-sm-4 bg-grey">
<p>Regal</p>
<div class="btn-group">
<button type="button" class="btn btn-primary">An</button>
<button type="button" class="btn btn-primary">Aus</button>
</div>
</div>
<div class="col-sm-4">
<p>Monitor</p>
<div class="btn-group">
<button type="button" class="btn btn-primary">An</button>
<button type="button" class="btn btn-primary">Aus</button>
</div>
</div>
<div class="col-sm-4 bg-grey">
<p>Fernseher</p>
<div class="btn-group">
<button type="button" class="btn btn-primary">An</button>
<button type="button" class="btn btn-primary">Aus</button>
</div>
</div>
<div class="col-sm-4">
<p>Bett</p>
<div class="btn-group">
<button type="button" class="btn btn-primary">An</button>
<button type="button" class="btn btn-primary">Aus</button>
</div>
</div>
</div>
</div>

18
www/html/settings.html Normal file
View File

@ -0,0 +1,18 @@
<div class="container" id="nas">
<div class="col-xs-9">
<div class="btn-group btn-group-justified">
<div class="btn-group">
<button type="button" class="btn btn-primary" id="start"><span class="glyphicon glyphicon-off"></span> Start</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary" id="shutdown"><span class="glyphicon glyphicon-off"></span> Shutdown</button>
</div>
<div class="btn-group">
<button type="button" class="btn btn-primary" id="reboot"><span class="glyphicon glyphicon-off"></span> Reboot</button>
</div>
</div>
</div>
<div class="col-xs-3">
<button type="button" class="btn btn-primary" id="update"><span class="glyphicon glyphicon-off"></span> Update</button>
</div>
</div>

BIN
www/img/.DS_Store vendored Normal file

Binary file not shown.

36
www/index.html Normal file
View File

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Theme Made By www.w3schools.com - No Copyright -->
<title>HomeControl</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="js/cm.js"></script>
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<!-- Navbar -->
<nav class="navbar navbar-expand-sm bg-light navbar-light">
<ul id="navbarBtn" class="navbar-nav">
<li class="navbar-brand">HomeControl</li>
<!--<li id="pageDevices" class="nav-item active"><a class="nav-link">Geräte</a></li>-->
<li><button id="pageDevices" type="button" class="btn btn-outline-light text-dark active">Geräte</button></li>
<li><button id="pageSettings" type="button" class="btn btn-outline-light text-dark">Einstellungen</button></li>
</ul>
</nav>
<div class="content" id="content">
</div>
<!-- Footer -->
<footer class="container-fluid bg-4 text-center">
</footer>
</body>
</html>

BIN
www/js/.DS_Store vendored Normal file

Binary file not shown.

62
www/js/cm.js Normal file
View File

@ -0,0 +1,62 @@
//------------------------------------------------------------------------------
// CM - Hauptfunktion
//------------------------------------------------------------------------------
class CM
{
constructor ()
{
this.BodyDataAction();
console.log("CM LOADED");
}
BodyDataAction ()
{
var menuButtons = document.getElementById("navbarBtn").
getElementsByTagName("button");
for (var i = 0; i < menuButtons.length; i++) {
menuButtons[i].onclick = function(evt) {
var res = evt.target.id;
CM_o.Menu(res);
};
}
}
Menu (message)
{
var selectedId = $(".selected").attr('id');
switch (message)
{
case 'pageDevices':
console.log( "pageDevices")
this.LoadContent('html/devices.html');
document.getElementById('pageDevices').className = "btn btn-outline-light text-dark active";
document.getElementById('pageSettings').className = "btn btn-outline-light text-dark";
break;
case 'pageSettings':
console.log( "pageDevices")
this.LoadContent('html/settings.html');
document.getElementById('pageDevices').className = "btn btn-outline-light text-dark";
document.getElementById('pageSettings').className = "btn btn-outline-light text-dark active";
break;
default:
alert ('[CM] Unbekannte Anfrage: ' + message);
}
}
LoadContent ( path )
{
$.get( path, function( data ) {
$( ".content" ).html( data );
console.log( "Load was performed." );
});
}
}
$(function() {
console.log("ONLOAD");
CM_o = new CM();
CM_o.Menu("pageDevices");
});