Compare commits

..

11 Commits

4 changed files with 65 additions and 62 deletions

View File

@ -10,38 +10,38 @@ import schedule
import paho.mqtt.client as mqtt
class Zimmer:
class Room:
name = None
automatic = None
temperaturSet = None
temperatureSet = None
statusActual = None
zimmer = [Zimmer, Zimmer]
zimmerName =["alexander", "wohnzimmer"]
rooms = [Room(), Room(), Room(), Room(), Room(), Room()]
roomName =["alexander", "livingroom", "bathroom", "christina", "kitchen", "simon"]
for i in range(len(zimmer)):
zimmer[i].name = zimmerName[i]
zimmer[i].automatic = 0
zimmer[i].temperaturSet = 0.0
zimmer[i].statusActual = 0
for i in range(len(rooms)):
rooms[i].name = roomName[i]
rooms[i].automatic = 0
rooms[i].temperatureSet = 0.0
rooms[i].statusActual = 0
def on_connect(client, userdata, flags, 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("zimmer/" + i.name + "/heizung/homeassistant/temperatur")
client.subscribe("zimmer/" + i.name + "/heizung/homeassistant/status")
client.subscribe("zimmer/" + i.name + "/heizung/temperatur")
client.subscribe("zimmer/" + i.name + "/heizung/status")
# client.subscribe("zimmer/" + i.name + "/sensoren/tuer/status")
# client.subscribe("zimmer/" + i.name + "/sensoren/fenster/status")
# client.subscribe("zimmer/" + i.name + "/sensoren/temperatur")
client.subscribe("room/" + room.name + "/heating/control/automatic")
client.subscribe("room/" + room.name + "/heating/control/temperature")
client.subscribe("room/" + room.name + "/heating/control/status")
client.subscribe("room/" + room.name + "/heating/actor/temperature")
client.subscribe("room/" + room.name + "/heating/actor/status")
# client.subscribe("room/" + room.name + "/sensoren/tuer/status")
# client.subscribe("room/" + room.name + "/sensoren/fenster/status")
# client.subscribe("room/" + room.name + "/sensoren/temperature")
sendReadings()
@ -56,31 +56,32 @@ def on_message(client, userdata, message):
msg = message.payload.decode("utf-8")
log.debug('received message: %s from %s', format(msg), format(message.topic))
if message.topic.split("/", -1)[2] == "heizung":
if message.topic.split("/", -1)[3] == "homeassistant":
if message.topic.split("/", -1)[2] == "heating":
if message.topic.split("/", -1)[3] == "control":
if message.topic.split("/", -1)[4] == "automatic":
for i in zimmer:
if message.topic.split("/", -1)[1] == i.name:
i.automatic = bool(msg)
if message.topic.split("/", -1)[4] == "temperatur":
for i in zimmer:
if message.topic.split("/", -1)[1] == i.name:
i.temperaturSet = round(float(msg),1)
if message.topic.split("/", -1)[3] == "status":
for i in zimmer:
if message.topic.split("/", -1)[1] == i.name:
i.statusActual = bool(msg)
for room in rooms:
if message.topic.split("/", -1)[1] == room.name:
room.automatic = bool(msg)
if message.topic.split("/", -1)[4] == "temperature":
for room in rooms:
if message.topic.split("/", -1)[1] == room.name:
room.temperatureSet = round(float(msg),1)
if message.topic.split("/", -1)[3] == "actor":
if message.topic.split("/", -1)[4] == "status":
for room in rooms:
if message.topic.split("/", -1)[1] == room.name:
room.statusActual = bool(msg)
sendReadings()
def sendReadings():
for i in zimmer:
for room in rooms:
if i.automatic:
client.publish("zimmer/" + i.name + "/heizung/temperatur", i.temperaturSet, qos=1, retain=True)
client.publish("zimmer/" + i.name + "/heizung/homeassistant/status", i.statusActual, qos=1, retain=True)
if room.automatic:
client.publish("room/" + room.name + "/heating/actor/temperature", room.temperatureSet, qos=1, retain=True)
client.publish("room/" + room.name + "/heating/control/status", room.statusActual, qos=1, retain=True)
log.debug('sent readings')
@ -107,7 +108,7 @@ def getArgs():
if __name__ == '__main__':
signal.signal(signal.SIGINT, terminate)
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')
if args.verbose:
log.setLevel(logging.DEBUG)

View File

@ -4,7 +4,7 @@ After=network-online.target
[Service]
Type=simple
ExecStart=/srv/homeassistent_services/heizberry_control.py
ExecStart=/srv/heizberry/heizberry_control.py
Restart=always
RestartSec=20

View File

@ -11,26 +11,26 @@ import paho.mqtt.client as mqtt
from eq3bt import Thermostat
class Zimmer:
class Room:
name = None
thermostat = None
zimmer = [Zimmer, Zimmer]
zimmerName = ["alexander", "wohnzimmer" ]
zimmerThermostat = [Thermostat('00:1A:22:16:4B:B4'), Thermostat('00:1A:22:16:25:C3)]
rooms = [Room(), Room(), Room(), Room(), Room(), Room()]
roomName = ["alexander", "livingroom", "bathroom", "kitchen", "christina", "simon"]
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)):
zimmer[i].name = zimmerName[i]
zimmer[i].thermostat = zimmerThermostat[i]
for i in range(len(rooms)):
rooms[i].name = roomName[i]
rooms[i].thermostat = roomThermostat[i]
def on_connect(client, userdata, flags, rc):
log.debug("Connected with result code " + str(rc))
for i in zimmer:
client.subscribe("zimmer/" + i.name + "/heizung/temperatur")
client.subscribe("zimmer/" + i.name + "/heizung/status")
for room in rooms:
client.subscribe("room/" + room.name + "/heating/actor/temperature")
client.subscribe("room/" + room.name + "/heating/actor/status")
sendReadings()
@ -44,29 +44,31 @@ def on_message(client, userdata, message):
msg = message.payload.decode("utf-8")
log.debug('received message: %s from %s', format(msg), format(message.topic))
if message.topic.split("/", -1)[2] == "heizung":
if message.topic.split("/", -1)[3] == "temperatur":
for i in zimmer:
if message.topic.split("/", -1)[1] == i.name:
i.thermostat.mode= 3
i.thermostat.target_temperature = round(float(msg),1)
for room in rooms:
tmpThermostat = Thermostat(room.thermostat)
if message.topic.split("/", -1)[2] == "heating":
if message.topic.split("/", -1)[3] == "actor":
if message.topic.split("/", -1)[4] == "temperature":
if message.topic.split("/", -1)[1] == room.name:
tmpThermostat.mode= 3
tmpThermostat.target_temperature = round(float(msg),1)
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:
client.publish("zimmer/" + i.name + "/heizung/status", 1, qos=1, retain=True)
if tmpThermostat.target_temperature > 17.0:
client.publish("room/" + room.name + "/heating/actor/status", 1, qos=1, retain=True)
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')
@ -93,7 +95,7 @@ def getArgs():
if __name__ == '__main__':
signal.signal(signal.SIGINT, terminate)
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')
if args.verbose:
log.setLevel(logging.DEBUG)

View File

@ -4,7 +4,7 @@ After=network-online.target
[Service]
Type=simple
ExecStart=/srv/homeassistent_services/heizberry_io.py
ExecStart=/srv/heizberry/heizberry_io.py
Restart=always
RestartSec=20