Smarthome Functionen
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

brennenstuhl.py 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base
  5. import json
  6. import task
  7. import time
  8. class brennenstuhl_heatingvalve(base):
  9. """ Communication (MQTT)
  10. brennenstuhl_heatingvalve {
  11. | "away_mode": ["ON", "OFF"]
  12. | "battery": [0...100] %
  13. | "child_lock": ["LOCK", "UNLOCK"]
  14. | "current_heating_setpoint": [5...30] °C
  15. | "linkquality": [0...255] lqi
  16. | "local_temperature": [numeric] °C
  17. | "preset": ["manual", ...]
  18. | "system_mode": ["heat", ...]
  19. | "valve_detection": ["ON", "OFF"]
  20. | "window_detection": ["ON", "OFF"]
  21. | }
  22. +- set {
  23. "away_mode": ["ON", "OFF", "TOGGLE"]
  24. "child_lock": ["LOCK", "UNLOCK"]
  25. "current_heating_setpoint": [5...30] °C
  26. "preset": ["manual", ...]
  27. "system_mode": ["heat", ...]
  28. "valve_detection": ["ON", "OFF", "TOGGLE"]
  29. "window_detection": ["ON", "OFF", "TOGGLE"]
  30. }
  31. """
  32. KEY_LINKQUALITY = "linkquality"
  33. KEY_BATTERY = "battery"
  34. KEY_HEATING_SETPOINT = "current_heating_setpoint"
  35. KEY_TEMPERATURE = "local_temperature"
  36. #
  37. KEY_AWAY_MODE = "away_mode"
  38. KEY_CHILD_LOCK = "child_lock"
  39. KEY_PRESET = "preset"
  40. KEY_SYSTEM_MODE = "system_mode"
  41. KEY_VALVE_DETECTION = "valve_detection"
  42. KEY_WINDOW_DETECTION = "window_detection"
  43. #
  44. RETRY_CYCLE_TIME = 2.5
  45. MAX_TX_RETRIES = 20
  46. RETRY_TIMEOUT = RETRY_CYCLE_TIME * MAX_TX_RETRIES
  47. #
  48. TX_TYPE = base.TX_DICT
  49. #
  50. RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
  51. RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET, KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
  52. def __init__(self, mqtt_client, topic):
  53. super().__init__(mqtt_client, topic)
  54. self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
  55. self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
  56. self.add_callback(self.KEY_HEATING_SETPOINT, None, self.__valave_temp_rx__)
  57. self.__tx_temperature__ = None
  58. self.__rx_temperature__ = None
  59. self.__tx_timestamp__ = 0
  60. #
  61. self.task = task.periodic(self.RETRY_CYCLE_TIME, self.__task__)
  62. self.task.run()
  63. def __state_logging__(self, inst, key, data):
  64. if key in [self.KEY_HEATING_SETPOINT, self.KEY_CHILD_LOCK, self.KEY_WINDOW_DETECTION, self.KEY_VALVE_DETECTION]:
  65. self.logger.info("State change of '%s' to '%s'", key, repr(data))
  66. def send_command(self, key, data):
  67. if key == self.KEY_HEATING_SETPOINT:
  68. self.__tx_temperature__ = data
  69. self.__tx_timestamp__ = time.time()
  70. base.send_command(self, key, data)
  71. def __valave_temp_rx__(self, inst, key, data):
  72. if key == self.KEY_HEATING_SETPOINT:
  73. self.__rx_temperature__ = data
  74. def __task__(self, rt):
  75. if self.__tx_temperature__ is not None and self.__tx_timestamp__ is not None: # Already send a setpoint
  76. if self.__tx_temperature__ != self.__rx_temperature__: # Setpoint and valve feedback are unequal
  77. if time.time() - self.__tx_timestamp__ < self.RETRY_TIMEOUT: # Timeout condition allows resend of setpoint
  78. self.logger.warning("Setpoint not yet acknoledged by device. Sending setpoint again")
  79. self.set_heating_setpoint(self.__tx_temperature__)
  80. return
  81. else:
  82. self.__tx_timestamp__ = None # Disable resend logic, if setpoint and valve setpoint are equal
  83. #
  84. # RX
  85. #
  86. @property
  87. def linkqulity(self):
  88. return self.get(self.KEY_LINKQUALITY)
  89. @property
  90. def heating_setpoint(self):
  91. return self.get(self.KEY_HEATING_SETPOINT)
  92. @property
  93. def temperature(self):
  94. return self.get(self.KEY_TEMPERATURE)
  95. #
  96. # TX
  97. #
  98. def set_heating_setpoint(self, setpoint):
  99. self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
  100. def set_heating_setpoint_mcb(self, device, key, data):
  101. self.set_heating_setpoint(data)