Smarthome Functionen
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

brennenstuhl.py 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. from devices.base import base
  5. from devices.base import BATTERY_WARN_LEVEL
  6. from devices.base import warning
  7. import json
  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. TX_TYPE = base.TX_DICT
  45. #
  46. RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
  47. RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET, KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
  48. def __init__(self, mqtt_client, topic):
  49. super().__init__(mqtt_client, topic)
  50. self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
  51. self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
  52. #
  53. self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
  54. self.__battery_warning__ = False
  55. #
  56. # WARNING CALL
  57. #
  58. def __warning__(self, client, key, data):
  59. if data <= BATTERY_WARN_LEVEL:
  60. if not self.__battery_warning__:
  61. self.__battery_warning__ = True
  62. w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", data)
  63. self.logger.warning(w)
  64. self.set(self.KEY_WARNING, w)
  65. else:
  66. self.__battery_warning__ = False
  67. #
  68. # RX
  69. #
  70. @property
  71. def linkqulity(self):
  72. return self.get(self.KEY_LINKQUALITY)
  73. @property
  74. def heating_setpoint(self):
  75. return self.get(self.KEY_HEATING_SETPOINT)
  76. @property
  77. def temperature(self):
  78. return self.get(self.KEY_TEMPERATURE)
  79. #
  80. # TX
  81. #
  82. def set_heating_setpoint(self, setpoint):
  83. self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
  84. def set_heating_setpoint_mcb(self, device, key, data):
  85. self.logger.info("Changing heating setpoint to %s", str(data))
  86. self.set_heating_setpoint(data)