forked from Chaospott/Heizberry
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
89a7a0addb | |||
6e8ecf2977 | |||
afae8b4016 | |||
37c0fc4320 | |||
6f81666386 | |||
67a4b85867 | |||
2ae081198f | |||
1834211e89 | |||
a410dc90ef | |||
8eba2c198c | |||
99415291ea |
@ -10,38 +10,38 @@ import schedule
|
|||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
|
|
||||||
class Zimmer:
|
class Room:
|
||||||
name = None
|
name = None
|
||||||
automatic = None
|
automatic = None
|
||||||
temperaturSet = None
|
temperatureSet = None
|
||||||
statusActual = None
|
statusActual = None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
zimmer = [Zimmer, Zimmer]
|
rooms = [Room(), Room(), Room(), Room(), Room(), Room()]
|
||||||
zimmerName =["alexander", "wohnzimmer"]
|
roomName =["alexander", "livingroom", "bathroom", "christina", "kitchen", "simon"]
|
||||||
|
|
||||||
|
|
||||||
for i in range(len(zimmer)):
|
for i in range(len(rooms)):
|
||||||
zimmer[i].name = zimmerName[i]
|
rooms[i].name = roomName[i]
|
||||||
zimmer[i].automatic = 0
|
rooms[i].automatic = 0
|
||||||
zimmer[i].temperaturSet = 0.0
|
rooms[i].temperatureSet = 0.0
|
||||||
zimmer[i].statusActual = 0
|
rooms[i].statusActual = 0
|
||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
log.debug("Connected with result code " + str(rc))
|
log.debug("Connected with result code " + str(rc))
|
||||||
|
|
||||||
for i in zimmer:
|
for room in rooms:
|
||||||
|
|
||||||
client.subscribe("zimmer/" + i.name + "/heizung/homeassistant/automatic")
|
client.subscribe("room/" + room.name + "/heating/control/automatic")
|
||||||
client.subscribe("zimmer/" + i.name + "/heizung/homeassistant/temperatur")
|
client.subscribe("room/" + room.name + "/heating/control/temperature")
|
||||||
client.subscribe("zimmer/" + i.name + "/heizung/homeassistant/status")
|
client.subscribe("room/" + room.name + "/heating/control/status")
|
||||||
client.subscribe("zimmer/" + i.name + "/heizung/temperatur")
|
client.subscribe("room/" + room.name + "/heating/actor/temperature")
|
||||||
client.subscribe("zimmer/" + i.name + "/heizung/status")
|
client.subscribe("room/" + room.name + "/heating/actor/status")
|
||||||
# client.subscribe("zimmer/" + i.name + "/sensoren/tuer/status")
|
# client.subscribe("room/" + room.name + "/sensoren/tuer/status")
|
||||||
# client.subscribe("zimmer/" + i.name + "/sensoren/fenster/status")
|
# client.subscribe("room/" + room.name + "/sensoren/fenster/status")
|
||||||
# client.subscribe("zimmer/" + i.name + "/sensoren/temperatur")
|
# client.subscribe("room/" + room.name + "/sensoren/temperature")
|
||||||
|
|
||||||
sendReadings()
|
sendReadings()
|
||||||
|
|
||||||
@ -56,31 +56,32 @@ def on_message(client, userdata, message):
|
|||||||
msg = message.payload.decode("utf-8")
|
msg = message.payload.decode("utf-8")
|
||||||
log.debug('received message: %s from %s', format(msg), format(message.topic))
|
log.debug('received message: %s from %s', format(msg), format(message.topic))
|
||||||
|
|
||||||
if message.topic.split("/", -1)[2] == "heizung":
|
if message.topic.split("/", -1)[2] == "heating":
|
||||||
if message.topic.split("/", -1)[3] == "homeassistant":
|
if message.topic.split("/", -1)[3] == "control":
|
||||||
if message.topic.split("/", -1)[4] == "automatic":
|
if message.topic.split("/", -1)[4] == "automatic":
|
||||||
for i in zimmer:
|
for room in rooms:
|
||||||
if message.topic.split("/", -1)[1] == i.name:
|
if message.topic.split("/", -1)[1] == room.name:
|
||||||
i.automatic = bool(msg)
|
room.automatic = bool(msg)
|
||||||
if message.topic.split("/", -1)[4] == "temperatur":
|
if message.topic.split("/", -1)[4] == "temperature":
|
||||||
for i in zimmer:
|
for room in rooms:
|
||||||
if message.topic.split("/", -1)[1] == i.name:
|
if message.topic.split("/", -1)[1] == room.name:
|
||||||
i.temperaturSet = round(float(msg),1)
|
room.temperatureSet = round(float(msg),1)
|
||||||
if message.topic.split("/", -1)[3] == "status":
|
if message.topic.split("/", -1)[3] == "actor":
|
||||||
for i in zimmer:
|
if message.topic.split("/", -1)[4] == "status":
|
||||||
if message.topic.split("/", -1)[1] == i.name:
|
for room in rooms:
|
||||||
i.statusActual = bool(msg)
|
if message.topic.split("/", -1)[1] == room.name:
|
||||||
|
room.statusActual = bool(msg)
|
||||||
|
|
||||||
|
|
||||||
sendReadings()
|
sendReadings()
|
||||||
|
|
||||||
def sendReadings():
|
def sendReadings():
|
||||||
|
|
||||||
for i in zimmer:
|
for room in rooms:
|
||||||
|
|
||||||
if i.automatic:
|
if room.automatic:
|
||||||
client.publish("zimmer/" + i.name + "/heizung/temperatur", i.temperaturSet, qos=1, retain=True)
|
client.publish("room/" + room.name + "/heating/actor/temperature", room.temperatureSet, qos=1, retain=True)
|
||||||
client.publish("zimmer/" + i.name + "/heizung/homeassistant/status", i.statusActual, qos=1, retain=True)
|
client.publish("room/" + room.name + "/heating/control/status", room.statusActual, qos=1, retain=True)
|
||||||
|
|
||||||
log.debug('sent readings')
|
log.debug('sent readings')
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ def getArgs():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
signal.signal(signal.SIGINT, terminate)
|
signal.signal(signal.SIGINT, terminate)
|
||||||
args = getArgs()
|
args = getArgs()
|
||||||
logging.basicConfig(filename='/var/log/homeassistant_services/heizberry_control.log', level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
logging.basicConfig(filename='/var/log/heizberry/heizberry_control.log', level=logging.WARN, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
||||||
log = logging.getLogger('heizberry')
|
log = logging.getLogger('heizberry')
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
@ -4,7 +4,7 @@ After=network-online.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/srv/homeassistent_services/heizberry_control.py
|
ExecStart=/srv/heizberry/heizberry_control.py
|
||||||
|
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=20
|
RestartSec=20
|
||||||
|
@ -11,26 +11,26 @@ import paho.mqtt.client as mqtt
|
|||||||
from eq3bt import Thermostat
|
from eq3bt import Thermostat
|
||||||
|
|
||||||
|
|
||||||
class Zimmer:
|
class Room:
|
||||||
name = None
|
name = None
|
||||||
thermostat = None
|
thermostat = None
|
||||||
|
|
||||||
|
|
||||||
zimmer = [Zimmer, Zimmer]
|
rooms = [Room(), Room(), Room(), Room(), Room(), Room()]
|
||||||
zimmerName = ["alexander", "wohnzimmer" ]
|
roomName = ["alexander", "livingroom", "bathroom", "kitchen", "christina", "simon"]
|
||||||
zimmerThermostat = [Thermostat('00:1A:22:16:4B:B4'), Thermostat('00:1A:22:16:25:C3)]
|
roomThermostat = ["00:1A:22:16:4B:B4", "00:1A:22:16:25:C3", "00:1A:22:16:2C:20", "00:1A:22:16:26:06", "00:1A:22:16:26:75", "00:1A:22:16:2C:85"]
|
||||||
|
|
||||||
for i in range(len(zimmer)):
|
for i in range(len(rooms)):
|
||||||
zimmer[i].name = zimmerName[i]
|
rooms[i].name = roomName[i]
|
||||||
zimmer[i].thermostat = zimmerThermostat[i]
|
rooms[i].thermostat = roomThermostat[i]
|
||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
log.debug("Connected with result code " + str(rc))
|
log.debug("Connected with result code " + str(rc))
|
||||||
|
|
||||||
for i in zimmer:
|
for room in rooms:
|
||||||
client.subscribe("zimmer/" + i.name + "/heizung/temperatur")
|
client.subscribe("room/" + room.name + "/heating/actor/temperature")
|
||||||
client.subscribe("zimmer/" + i.name + "/heizung/status")
|
client.subscribe("room/" + room.name + "/heating/actor/status")
|
||||||
|
|
||||||
sendReadings()
|
sendReadings()
|
||||||
|
|
||||||
@ -44,29 +44,31 @@ def on_message(client, userdata, message):
|
|||||||
msg = message.payload.decode("utf-8")
|
msg = message.payload.decode("utf-8")
|
||||||
log.debug('received message: %s from %s', format(msg), format(message.topic))
|
log.debug('received message: %s from %s', format(msg), format(message.topic))
|
||||||
|
|
||||||
if message.topic.split("/", -1)[2] == "heizung":
|
for room in rooms:
|
||||||
if message.topic.split("/", -1)[3] == "temperatur":
|
tmpThermostat = Thermostat(room.thermostat)
|
||||||
for i in zimmer:
|
if message.topic.split("/", -1)[2] == "heating":
|
||||||
if message.topic.split("/", -1)[1] == i.name:
|
if message.topic.split("/", -1)[3] == "actor":
|
||||||
i.thermostat.mode= 3
|
if message.topic.split("/", -1)[4] == "temperature":
|
||||||
i.thermostat.target_temperature = round(float(msg),1)
|
if message.topic.split("/", -1)[1] == room.name:
|
||||||
|
tmpThermostat.mode= 3
|
||||||
|
tmpThermostat.target_temperature = round(float(msg),1)
|
||||||
|
|
||||||
sendReadings()
|
sendReadings()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def sendReadings():
|
def sendReadings():
|
||||||
log.debug('read target temperature from thermostats')
|
log.debug('read target temperature from thermostat')
|
||||||
|
|
||||||
for i in zimmer:
|
for room in rooms:
|
||||||
|
tmpThermostat = Thermostat(room.thermostat)
|
||||||
|
|
||||||
i.thermostat.update()
|
tmpThermostat.update()
|
||||||
|
|
||||||
if i.thermostat.target_temperature > 17.0:
|
if tmpThermostat.target_temperature > 17.0:
|
||||||
client.publish("zimmer/" + i.name + "/heizung/status", 1, qos=1, retain=True)
|
client.publish("room/" + room.name + "/heating/actor/status", 1, qos=1, retain=True)
|
||||||
else:
|
else:
|
||||||
client.publish("zimmer/" + i.name + "/heizung/status", 0, qos=1, retain=True)
|
client.publish("room/" + room.name + "/heating/actor/status", 0, qos=1, retain=True)
|
||||||
|
|
||||||
log.debug('sent readings')
|
log.debug('sent readings')
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ def getArgs():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
signal.signal(signal.SIGINT, terminate)
|
signal.signal(signal.SIGINT, terminate)
|
||||||
args = getArgs()
|
args = getArgs()
|
||||||
logging.basicConfig(filename='/var/log/homeassistant_services/heizberry_io.log', level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
logging.basicConfig(filename='/var/log/heizberry/heizberry_io.log', level=logging.WARN, format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
|
||||||
log = logging.getLogger('heizberry')
|
log = logging.getLogger('heizberry')
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
@ -4,7 +4,7 @@ After=network-online.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/srv/homeassistent_services/heizberry_io.py
|
ExecStart=/srv/heizberry/heizberry_io.py
|
||||||
|
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=20
|
RestartSec=20
|
||||||
|
Loading…
Reference in New Issue
Block a user