i to room

This commit is contained in:
lukario 2021-04-18 15:36:09 +02:00
parent afae8b4016
commit 6e8ecf2977
2 changed files with 32 additions and 32 deletions

View File

@ -32,16 +32,16 @@ for i in range(len(rooms)):
def on_connect(client, userdata, flags, rc):
log.debug("Connected with result code " + str(rc))
for i in rooms:
for room in rooms:
client.subscribe("room/" + i.name + "/heating/control/automatic")
client.subscribe("room/" + i.name + "/heating/control/temperature")
client.subscribe("room/" + i.name + "/heating/control/status")
client.subscribe("room/" + i.name + "/heating/actor/temperature")
client.subscribe("room/" + i.name + "/heating/actor/status")
# client.subscribe("room/" + i.name + "/sensoren/tuer/status")
# client.subscribe("room/" + i.name + "/sensoren/fenster/status")
# client.subscribe("room/" + i.name + "/sensoren/temperature")
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()
@ -59,29 +59,29 @@ def on_message(client, userdata, message):
if message.topic.split("/", -1)[2] == "heating":
if message.topic.split("/", -1)[3] == "control":
if message.topic.split("/", -1)[4] == "automatic":
for i in rooms:
if message.topic.split("/", -1)[1] == i.name:
i.automatic = 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 i in rooms:
if message.topic.split("/", -1)[1] == i.name:
i.temperatureSet = round(float(msg),1)
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 i in rooms:
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.statusActual = bool(msg)
sendReadings()
def sendReadings():
for i in rooms:
for room in rooms:
if i.automatic:
client.publish("room/" + i.name + "/heating/actor/temperature", i.temperatureSet, qos=1, retain=True)
client.publish("room/" + i.name + "/heating/control/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')

View File

@ -28,9 +28,9 @@ for i in range(len(rooms)):
def on_connect(client, userdata, flags, rc):
log.debug("Connected with result code " + str(rc))
for i in rooms:
client.subscribe("room/" + i.name + "/heating/actor/temperature")
client.subscribe("room/" + i.name + "/heating/actor/status")
for room in rooms:
client.subscribe("room/" + room.name + "/heating/actor/temperature")
client.subscribe("room/" + room.name + "/heating/actor/status")
sendReadings()
@ -44,12 +44,12 @@ def on_message(client, userdata, message):
msg = message.payload.decode("utf-8")
log.debug('received message: %s from %s', format(msg), format(message.topic))
for i in rooms:
tmpThermostat = Thermostat(i.thermostat)
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] == i.name:
if message.topic.split("/", -1)[1] == room.name:
tmpThermostat.mode= 3
tmpThermostat.target_temperature = round(float(msg),1)
@ -60,15 +60,15 @@ def on_message(client, userdata, message):
def sendReadings():
log.debug('read target temperature from thermostat')
for i in rooms:
tmpThermostat = Thermostat(i.thermostat)
for room in rooms:
tmpThermostat = Thermostat(room.thermostat)
tmpThermostat.update()
if tmpThermostat.target_temperature > 17.0:
client.publish("room/" + i.name + "/heating/actor/status", 1, qos=1, retain=True)
client.publish("room/" + room.name + "/heating/actor/status", 1, qos=1, retain=True)
else:
client.publish("room/" + i.name + "/heating/actor/status", 0, qos=1, retain=True)
client.publish("room/" + room.name + "/heating/actor/status", 0, qos=1, retain=True)
log.debug('sent readings')