Smarthome Functionen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

first_floor_east.py 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. import devices
  6. import logging
  7. from function.rooms import room_shelly, room_shelly_tradfri_light
  8. try:
  9. from config import APP_NAME as ROOT_LOGGER_NAME
  10. except ImportError:
  11. ROOT_LOGGER_NAME = 'root'
  12. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  13. class first_floor_east_floor(room_shelly):
  14. def __init__(self, mqtt_client):
  15. # http://shelly1l-3C6105E4E629
  16. super().__init__(mqtt_client, "shellies/floor_madi", "gui/ffe_sw_floor")
  17. def toggle_main_light(self, device, key, data):
  18. logger.info("Toggeling \"%s\" main light", type(self).__name__)
  19. self.main_light_shelly.set_output_0("toggle")
  20. class first_floor_east_kitchen(room_shelly):
  21. # TODO: add circulation pump (switch, time)
  22. def __init__(self, mqtt_client):
  23. # http://shelly1l-8CAAB5616C01
  24. super().__init__(mqtt_client, "shellies/kitchen", "gui/ffe_sw_kitchen")
  25. class first_floor_east_dining(room_shelly):
  26. def __init__(self, mqtt_client):
  27. # http://shelly1l-84CCA8ADD055
  28. super().__init__(mqtt_client, "shellies/diningroom", "gui/ffe_sw_diningroom")
  29. self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, "zigbee_og_e/powerplug/dining_floorlamp")
  30. if config.CHRISTMAS:
  31. self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, topic="zigbee_og_e/powerplug/aux")
  32. #
  33. self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_dining_floorlamp")
  34. #
  35. # Callback initialisation
  36. #
  37. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
  38. self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
  39. self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0,
  40. None, self.gui_switch_feedback_floorlamp)
  41. #
  42. self.main_light_shelly_last = None
  43. def floorlamp_synchronisation(self, device, key, data):
  44. if data != self.main_light_shelly_last:
  45. logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
  46. self.floorlamp_powerplug.set_output_0(data)
  47. self.main_light_shelly_last = data
  48. def gui_switch_command_floorlamp(self, device, key, data):
  49. logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
  50. self.floorlamp_powerplug.set_output_0(data)
  51. def gui_switch_feedback_floorlamp(self, device, key, data):
  52. self.gui_switch_floorlamp.set_feedback(data)
  53. class first_floor_east_sleep_madi(room_shelly_tradfri_light):
  54. def __init__(self, mqtt_client):
  55. # http://shelly1l-E8DB84A254C7
  56. super().__init__(mqtt_client, "shellies/sleep_madi", "gui/ffe_sw_sleep_madi",
  57. "zigbee_og_e/light/sleep_madi", "gui/ffe_br_sleep_madi", "gui/ffe_ct_sleep_madi")
  58. #
  59. self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/sleep_bed_di")
  60. #
  61. self.gui_switch_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_sw_bed_light_di")
  62. self.gui_brightness_bed_light_di = devices.nodered_gui(mqtt_client, "gui/ffe_br_bed_light_di")
  63. self.gui_brightness_bed_light_di.enable(False)
  64. self.gui_brightness_bed_light_di.set_feedback(0)
  65. #
  66. # Callback initialisation
  67. #
  68. self.gui_switch_bed_light_di.add_callback(
  69. devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_bed_light_di)
  70. self.bed_light_di_tradfri.add_callback(
  71. devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_bed_light_di)
  72. self.bed_light_di_tradfri.add_callback(
  73. devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_bed_light_di)
  74. self.gui_brightness_bed_light_di.add_callback(
  75. devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_bed_light_di)
  76. def toggle_main_light(self, device, key, data):
  77. logger.info("Toggeling \"%s\" main light", type(self).__name__)
  78. self.main_light_shelly.set_output_0("toggle")
  79. def fade_bed_light(self, device, topic, data):
  80. if (data == 'brightness_up_hold'):
  81. logger.info("Increasing brightness \"%s\" bed light dirk", type(self).__name__)
  82. self.bed_light_di_tradfri.brightness_inc()
  83. elif (data == 'brightness_down_hold'):
  84. logger.info("Decreasing brightness \"%s\" bed light dirk", type(self).__name__)
  85. self.bed_light_di_tradfri.brightness_dec()
  86. elif (data.startswith('brightness') and data.endswith('release')):
  87. logger.info("Stoping brightness change \"%s\" bed light dirk", type(self).__name__)
  88. self.bed_light_di_tradfri.brightness_stop()
  89. def gui_switch_command_bed_light_di(self, device, key, data):
  90. logger.info("Switching \"%s\" bed light dirk: %s", type(self).__name__, str(data))
  91. self.bed_light_di_tradfri.set_output_0(data)
  92. def gui_switch_feedback_bed_light_di(self, device, key, data):
  93. self.gui_switch_bed_light_di.set_feedback(data)
  94. self.gui_brightness_bed_light_di.enable(data)
  95. if data is False:
  96. self.gui_brightness_bed_light_di.set_feedback(0)
  97. else:
  98. self.gui_brightness_bed_light_di.set_feedback(self.bed_light_di_tradfri.brightness)
  99. def set_gui_brightness_bed_light_di(self, device, key, data):
  100. self.gui_brightness_bed_light_di.set_feedback(data)
  101. def set_brightness_bed_light_di(self, device, key, data):
  102. logger.info("Setting brightness \"%s\" bed light dirk: %.1f", type(self).__name__, data)
  103. self.bed_light_di_tradfri.set_brightness(data)
  104. def toggle_bed_light_di(self, device, key, data):
  105. logger.info("Toggeling \"%s\" bed light dirk", type(self).__name__)
  106. self.bed_light_di_tradfri.set_output_0("toggle")
  107. class first_floor_east_living(room_shelly_tradfri_light):
  108. def __init__(self, mqtt_client):
  109. # http://shelly1l-3C6105E3F910
  110. super().__init__(mqtt_client, "shellies/livingroom", "gui/ffe_sw_livingroom",
  111. "zigbee_og_e/light/livingroom", "gui/ffe_br_livingroom", "gui/ffe_ct_livingroom")
  112. for i in range(1, 7):
  113. setattr(self, 'floorlamp_tradfri_%d' % i,
  114. devices.tradfri_light(mqtt_client, topic="zigbee_og_e/light/living_floorlamp_%d" % i))
  115. #
  116. self.gui_switch_floorlamp = devices.nodered_gui(mqtt_client, topic="gui/ffe_sw_living_floorlamp")
  117. self.gui_brightness_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_br_livingroom_floorlamp")
  118. self.gui_brightness_floorlamp.enable(False)
  119. self.gui_brightness_floorlamp.set_feedback(0)
  120. self.gui_color_temp_floorlamp = devices.nodered_gui(mqtt_client, "gui/ffe_ct_livingroom_floorlamp")
  121. self.gui_color_temp_floorlamp.enable(False)
  122. self.gui_color_temp_floorlamp.set_feedback(0)
  123. #
  124. # Callback initialisation
  125. #
  126. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_synchronisation)
  127. self.gui_switch_floorlamp.add_callback(devices.nodered_gui.KEY_STATE, None, self.gui_switch_command_floorlamp)
  128. self.floorlamp_tradfri_1.add_callback(
  129. devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_switch_feedback_floorlamp)
  130. self.floorlamp_tradfri_1.add_callback(
  131. devices.tradfri_light.KEY_BRIGHTNESS, None, self.set_gui_brightness_floorlamp)
  132. self.floorlamp_tradfri_1.add_callback(
  133. devices.tradfri_light.KEY_COLOR_TEMP, None, self.set_gui_color_temp_floorlamp)
  134. self.gui_brightness_floorlamp.add_callback(
  135. devices.nodered_gui.KEY_BRIGHTNESS, None, self.set_brightness_floorlamp)
  136. self.gui_color_temp_floorlamp.add_callback(
  137. devices.nodered_gui.KEY_COLOR_TEMP, None, self.set_color_temp_floorlamp)
  138. #
  139. self.main_light_shelly_last = None
  140. def __floorlamp_devices__(self):
  141. rv = []
  142. for i in range(1, 7):
  143. rv.append(getattr(self, 'floorlamp_tradfri_%d' % i))
  144. return rv
  145. def floorlamp_synchronisation(self, device, key, data):
  146. if data != self.main_light_shelly_last:
  147. logger.info("Synching \"%s\" floorlamp with main light (%s)", type(self).__name__, str(data))
  148. for device in self.__floorlamp_devices__():
  149. device.set_output_0(data)
  150. self.main_light_shelly_last = data
  151. def gui_switch_command_floorlamp(self, device, key, data):
  152. logger.info("Switching \"%s\" floorlamp: %s", type(self).__name__, str(data))
  153. for device in self.__floorlamp_devices__():
  154. device.set_output_0(data)
  155. def gui_switch_feedback_floorlamp(self, device, key, data):
  156. self.gui_switch_floorlamp.set_feedback(data)
  157. self.gui_brightness_floorlamp.enable(data)
  158. self.gui_color_temp_floorlamp.enable(data)
  159. if data is False:
  160. self.gui_brightness_floorlamp.set_feedback(0)
  161. self.gui_color_temp_floorlamp.set_feedback(0)
  162. else:
  163. self.gui_brightness_floorlamp.set_feedback(self.floorlamp_tradfri_1.brightness)
  164. self.gui_color_temp_floorlamp.set_feedback(self.floorlamp_tradfri_1.color_temp / 10)
  165. def set_gui_brightness_floorlamp(self, device, key, data):
  166. self.gui_brightness_floorlamp.set_feedback(data)
  167. def set_gui_color_temp_floorlamp(self, device, key, data):
  168. self.gui_color_temp_floorlamp.set_feedback(data / 10)
  169. def set_brightness_floorlamp(self, device, key, data):
  170. logger.info("Setting brightness \"%s\" floorlamp: %.1f", type(self).__name__, data)
  171. for device in self.__floorlamp_devices__():
  172. device.set_brightness(data)
  173. def set_color_temp_floorlamp(self, device, key, data):
  174. logger.info("Setting color_temp \"%s\" floorlamp: %.1f", type(self).__name__, data)
  175. for device in self.__floorlamp_devices__():
  176. device.set_color_temp(data * 10)