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 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. import json
  7. class brennenstuhl_heatingvalve(base):
  8. """ Communication (MQTT)
  9. brennenstuhl_heatingvalve {
  10. | "away_mode": ["ON", "OFF"]
  11. | "battery": [0...100] %
  12. | "child_lock": ["LOCK", "UNLOCK"]
  13. | "current_heating_setpoint": [5...30] °C
  14. | "linkquality": [0...255] lqi
  15. | "local_temperature": [numeric] °C
  16. | "preset": ["manual", ...]
  17. | "system_mode": ["heat", ...]
  18. | "valve_detection": ["ON", "OFF"]
  19. | "window_detection": ["ON", "OFF"]
  20. | }
  21. +- set {
  22. "away_mode": ["ON", "OFF", "TOGGLE"]
  23. "child_lock": ["LOCK", "UNLOCK"]
  24. "current_heating_setpoint": [5...30] °C
  25. "preset": ["manual", ...]
  26. "system_mode": ["heat", ...]
  27. "valve_detection": ["ON", "OFF", "TOGGLE"]
  28. "window_detection": ["ON", "OFF", "TOGGLE"]
  29. }
  30. """
  31. KEY_LINKQUALITY = "linkquality"
  32. KEY_BATTERY = "battery"
  33. KEY_HEATING_SETPOINT = "current_heating_setpoint"
  34. KEY_TEMPERATURE = "local_temperature"
  35. #
  36. KEY_AWAY_MODE = "away_mode"
  37. KEY_CHILD_LOCK = "child_lock"
  38. KEY_PRESET = "preset"
  39. KEY_SYSTEM_MODE = "system_mode"
  40. KEY_VALVE_DETECTION = "valve_detection"
  41. KEY_WINDOW_DETECTION = "window_detection"
  42. #
  43. TX_TYPE = base.TX_DICT
  44. #
  45. RX_KEYS = [KEY_LINKQUALITY, KEY_BATTERY, KEY_HEATING_SETPOINT, KEY_TEMPERATURE]
  46. RX_IGNORE_KEYS = [KEY_AWAY_MODE, KEY_CHILD_LOCK, KEY_PRESET, KEY_SYSTEM_MODE, KEY_VALVE_DETECTION, KEY_WINDOW_DETECTION]
  47. def __init__(self, mqtt_client, topic):
  48. super().__init__(mqtt_client, topic)
  49. self.mqtt_client.send(self.topic + '/' + self.TX_TOPIC, json.dumps({self.KEY_WINDOW_DETECTION: "ON",
  50. self.KEY_CHILD_LOCK: "UNLOCK", self.KEY_VALVE_DETECTION: "ON", self.KEY_SYSTEM_MODE: "heat", self.KEY_PRESET: "manual"}))
  51. #
  52. self.add_callback(self.KEY_BATTERY, None, self.__warning__, True)
  53. self.__battery_warning__ = False
  54. #
  55. # WARNING CALL
  56. #
  57. def __warning__(self, client, key, data):
  58. if data <= BATTERY_WARN_LEVEL:
  59. if not self.__battery_warning__:
  60. self.__battery_warning__ = True
  61. w = warning(self.topic, warning.TYPE_BATTERY_LOW, "Battery low (%.1f%%)", data)
  62. self.logger.warning(w)
  63. self.set(self.KEY_WARNING, w)
  64. else:
  65. self.__battery_warning__ = False
  66. #
  67. # RX
  68. #
  69. @property
  70. def linkqulity(self):
  71. return self.get(self.KEY_LINKQUALITY)
  72. @property
  73. def heating_setpoint(self):
  74. return self.get(self.KEY_HEATING_SETPOINT)
  75. @property
  76. def temperature(self):
  77. return self.get(self.KEY_TEMPERATURE)
  78. #
  79. # TX
  80. #
  81. def set_heating_setpoint(self, setpoint):
  82. self.send_command(self.KEY_HEATING_SETPOINT, setpoint)
  83. def set_heating_setpoint_mcb(self, device, key, data):
  84. self.logger.info("Changing heating setpoint to %s", str(data))
  85. self.set_heating_setpoint(data)