From d1e5ff35ae62094a0b829aec54bb5c57d046c4c2 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 18 Mar 2021 13:15:51 +0100 Subject: [PATCH] fiddeling with heater and fyrtur --- configs/pepe/home-assistant/light-control.nix | 8 ++ .../home-assistant/zigbee2mqtt/heater.nix | 1 + mqtt/fyrtur.py | 9 +- mqtt/heater.py | 84 +++++++++++++++++-- mqtt/heater/__init__.py | 0 mqtt/heater/modules/__init__.py | 0 mqtt/heater/modules/heater.py | 39 --------- mqtt/heater/modules/watcher.py | 34 -------- 8 files changed, 86 insertions(+), 89 deletions(-) delete mode 100644 mqtt/heater/__init__.py delete mode 100644 mqtt/heater/modules/__init__.py delete mode 100644 mqtt/heater/modules/heater.py delete mode 100644 mqtt/heater/modules/watcher.py diff --git a/configs/pepe/home-assistant/light-control.nix b/configs/pepe/home-assistant/light-control.nix index 8b589f8..7a9f8a5 100644 --- a/configs/pepe/home-assistant/light-control.nix +++ b/configs/pepe/home-assistant/light-control.nix @@ -24,6 +24,14 @@ "zigbee2mqtt/door_sensor_4" "zigbee2mqtt/door_sensor_5" ]; + disabled_switches = [ + "zigbee2mqtt/led_1" + "zigbee2mqtt/led_2" + "zigbee2mqtt/light_2" + "zigbee2mqtt/light_4" + "zigbee2mqtt/light_5" + "zigbee2mqtt/light_7" + ]; } { name = "down"; diff --git a/configs/pepe/home-assistant/zigbee2mqtt/heater.nix b/configs/pepe/home-assistant/zigbee2mqtt/heater.nix index 963611a..417a8e3 100644 --- a/configs/pepe/home-assistant/zigbee2mqtt/heater.nix +++ b/configs/pepe/home-assistant/zigbee2mqtt/heater.nix @@ -18,6 +18,7 @@ in { { id, ... }: { name = id; value = { + legacy = false; retain = false; friendly_name = name; transition = 1; diff --git a/mqtt/fyrtur.py b/mqtt/fyrtur.py index 3fcddc3..df4f8f1 100644 --- a/mqtt/fyrtur.py +++ b/mqtt/fyrtur.py @@ -6,10 +6,6 @@ import paho.mqtt.client as mqtt import json import threading -# initial scene -from heater.modules.heater import Heater -from heater.modules.watcher import Watcher - scene = "up-dark" @@ -53,14 +49,14 @@ class FyrturWatcher: fyrtur.update_position(payload) return - def update(self, name, position : Position): + def update(self, name, position: Position): fyrtur: Fyrtur = self.fyrturs.get(name) if position == Position.UP: fyrtur.wanted_position = fyrtur.top elif position == Position.DOWN: fyrtur.wanted_position = fyrtur.bottom elif position == Position.HALF: - fyrtur.wanted_position = round((fyrtur.top - fyrtur.bottom) / 2) + fyrtur.wanted_position = round((fyrtur.top - fyrtur.bottom) / 2 + fyrtur.bottom) def publish(self, client): for fyrtur in self.fyrturs.values(): @@ -69,7 +65,6 @@ class FyrturWatcher: time.sleep(2) - watcher = FyrturWatcher({ "office1": Fyrtur(topic="zigbee2mqtt/fyrtur1", set_topic="zigbee2mqtt/fyrtur1/set", top=100, bottom=16), "office2": Fyrtur(topic="zigbee2mqtt/fyrtur4", set_topic="zigbee2mqtt/fyrtur4/set", top=100, bottom=22), diff --git a/mqtt/heater.py b/mqtt/heater.py index 616cc9b..1e0a07a 100644 --- a/mqtt/heater.py +++ b/mqtt/heater.py @@ -1,12 +1,77 @@ -import time - -import paho.mqtt.client as mqtt import json +import paho.mqtt.client as mqtt import threading +import time +from typing import Dict + + +class Heater: + def __init__(self, topic, set_topic): + self.not_initialized_yet = True + self.wanted_temperature = 15 + self.actual_temperature = 15 + self.set_topic = set_topic + self.topic = topic + + def payload(self): + payload = { + "system_mode": "auto", + "current_heating_setpoint": self.wanted_temperature, + "eurotronic_host_flags": {"window_open": True} + } + return json.dumps(payload) + + def needs_publish(self): + if self.not_initialized_yet: + return True + else: + return self.wanted_temperature != self.actual_temperature + + def update_actual_heating_point(self, payload): + heating_setpoint = int(payload["current_heating_setpoint"]) + if self.not_initialized_yet: + self.not_initialized_yet = False + self.wanted_temperature = heating_setpoint + print("%s: update wanted temperature %d" % (self.topic, self.actual_temperature)) + self.actual_temperature = heating_setpoint + print("%s: update actual temperature %d" % (self.topic, self.actual_temperature)) + + def topic_and_payload_for_query(self): + payload = { + "current_heating_setpoint": "" + } + return ("%s/get" % self.topic), json.dumps(payload) + + +class Watcher: + + def __init__(self, heater: Dict[str, Heater]): + self.heater = heater + + def publish(self, client): + for heater in self.heater.values(): + if heater.needs_publish(): + client.publish(heater.set_topic, heater.payload()) + time.sleep(2) + + def update(self, name, temperature): + heater: Heater = self.heater.get(name) + heater.wanted_temperature = temperature + + def get_topics(self): + return [heater.topic for heater in self.heater.values()] + + def update_actual_heating_point_for_topic(self, topic, payload): + for heater in self.heater.values(): + if heater.topic == topic: + heater.update_actual_heating_point(payload) + return + + def pull_values(self, client): + for heater in self.heater.values(): + topic, payload = heater.topic_and_payload_for_query() + client.publish(topic, payload) -# initial scene -from heater.modules.heater import Heater -from heater.modules.watcher import Watcher scene = "default" @@ -42,7 +107,7 @@ def on_message(client, _userdata, msg): else: print("got %s" % topic) watcher.update_actual_heating_point_for_topic(topic, payload) - #watcher.publish(client) + # watcher.publish(client) def parse_message(msg): @@ -57,8 +122,8 @@ def update_scene(client): watcher.update("office2", 10) watcher.update("bedroom", 13) elif scene in ["default", "up-bright", "up-dark", "half", "down"]: - watcher.update("office1", 23) - watcher.update("office2", 23) + watcher.update("office1", 26) + watcher.update("office2", 26) watcher.update("bedroom", 18) else: watcher.update("office1", 10) @@ -80,6 +145,7 @@ if __name__ == "__main__": mqttClient.on_message = on_message mqttClient.username_pw_set("homeassistant", password="password") mqttClient.connect("pepe.private", 1883, 60) + # Blocking call that processes network traffic, dispatches callbacks and # handles reconnecting. # Other loop*() functions are available that give a threaded interface and a diff --git a/mqtt/heater/__init__.py b/mqtt/heater/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/mqtt/heater/modules/__init__.py b/mqtt/heater/modules/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/mqtt/heater/modules/heater.py b/mqtt/heater/modules/heater.py deleted file mode 100644 index f020354..0000000 --- a/mqtt/heater/modules/heater.py +++ /dev/null @@ -1,39 +0,0 @@ -import json - - -class Heater: - def __init__(self, topic, set_topic): - self.not_initialized_yet = True - self.wanted_temperature = 15 - self.actual_temperature = 15 - self.set_topic = set_topic - self.topic = topic - - def payload(self): - payload = { - "system_mode": "auto", - "current_heating_setpoint": str(self.wanted_temperature), - "eurotronic_host_flags": {"window_open": True} - } - return json.dumps(payload) - - def needs_publish(self): - if self.not_initialized_yet: - return True - else: - return self.wanted_temperature != self.actual_temperature - - def update_actual_heating_point(self, payload): - heating_setpoint = int(payload["current_heating_setpoint"]) - if self.not_initialized_yet: - self.not_initialized_yet = False - self.wanted_temperature = heating_setpoint - print("%s: update wanted temperature %d" % (self.topic, self.actual_temperature)) - self.actual_temperature = heating_setpoint - print("%s: update actual temperature %d" % (self.topic, self.actual_temperature)) - - def topic_and_payload_for_query(self): - payload = { - "current_heating_setpoint": "" - } - return ("%s/get" % self.topic), json.dumps(payload) diff --git a/mqtt/heater/modules/watcher.py b/mqtt/heater/modules/watcher.py deleted file mode 100644 index 4892207..0000000 --- a/mqtt/heater/modules/watcher.py +++ /dev/null @@ -1,34 +0,0 @@ -import time -from typing import List, Dict - -from heater.modules.heater import Heater - - -class Watcher: - - def __init__(self, heater: Dict[str, Heater]): - self.heater = heater - - def publish(self, client): - for heater in self.heater.values(): - if heater.needs_publish(): - client.publish(heater.set_topic, heater.payload()) - time.sleep(2) - - def update(self, name, temperature): - heater: Heater = self.heater.get(name) - heater.wanted_temperature = temperature - - def get_topics(self): - return [heater.topic for heater in self.heater.values()] - - def update_actual_heating_point_for_topic(self, topic, payload): - for heater in self.heater.values(): - if heater.topic == topic: - heater.update_actual_heating_point(payload) - return - - def pull_values(self, client): - for heater in self.heater.values(): - topic, payload = heater.topic_and_payload_for_query() - client.publish(topic, payload)