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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. import devices
  6. from function.modules import brightness_choose_n_action, circulation_pump, radiator_function
  7. import logging
  8. from function.rooms import room_shelly, room_shelly_motion_sensor, room_shelly_tradfri_light
  9. from function.videv import videv_switching, videv_switch_brightness, videv_switch_brightness_color_temp
  10. try:
  11. from config import APP_NAME as ROOT_LOGGER_NAME
  12. except ImportError:
  13. ROOT_LOGGER_NAME = 'root'
  14. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  15. class first_floor_east_floor(room_shelly):
  16. def __init__(self, mqtt_client):
  17. # http://shelly1l-3C6105E4E629
  18. super().__init__(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_GUI)
  19. #
  20. self.main_light = videv_switching(
  21. mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
  22. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  23. )
  24. class first_floor_east_kitchen(room_shelly):
  25. def __init__(self, mqtt_client):
  26. # http://shelly1l-8CAAB5616C01
  27. super().__init__(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_GUI)
  28. #
  29. self.circulation_pump = circulation_pump(mqtt_client)
  30. self.circulation_pump.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.flash_main_light)
  31. #
  32. self.main_light_videv = videv_switching(
  33. mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
  34. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  35. )
  36. self.circulation_pump_videv = videv_switching(
  37. mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
  38. self.circulation_pump.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  39. )
  40. def all_off(self, device=None, key=None, data=None):
  41. self.circulation_pump.all_off(device, key, data)
  42. return super().all_off(device, key, data)
  43. class first_floor_east_dining(room_shelly):
  44. def __init__(self, mqtt_client):
  45. # http://shelly1l-84CCA8ADD055
  46. super().__init__(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_GUI)
  47. self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  48. if config.CHRISTMAS:
  49. self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  50. #
  51. self.gui_floorlamp = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_GUI)
  52. #
  53. # Callback initialisation
  54. #
  55. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
  56. self.gui_floorlamp.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.floorlamp_powerplug.set_output_0_mcb)
  57. self.floorlamp_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb)
  58. #
  59. self.main_light_videv = videv_switching(
  60. mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
  61. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  62. )
  63. self.floorlamp_videv = videv_switching(
  64. mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
  65. self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  66. )
  67. def all_off(self, device=None, key=None, data=None):
  68. super().all_off(device, key, data)
  69. self.floorlamp_powerplug.set_output_0(False)
  70. if config.CHRISTMAS:
  71. self.garland_powerplug.set_output_0(False)
  72. class first_floor_east_sleep(room_shelly_tradfri_light):
  73. def __init__(self, mqtt_client):
  74. # http://shelly1l-E8DB84A254C7
  75. super().__init__(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_GUI, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
  76. # bed light
  77. self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
  78. self.gui_bed_light_di = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_GUI)
  79. self.bed_light_ma_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
  80. self.gui_bed_light_ma = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_GUI)
  81. #
  82. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
  83. # button / brightness function
  84. self.brightness_functions = brightness_choose_n_action(mqtt_client, self.button_tradfri, config.TOPIC_FFE_SLEEP_DEVICE_CHOOSER_LED)
  85. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  86. self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
  87. # radiator valve
  88. self.radiator_function = radiator_function(mqtt_client, config.TOPIC_FFE_SLEEP_RADIATOR_VALVE_ZIGBEE,
  89. config.TOPIC_FFE_SLEEP_RADIATOR_VALVE_GUI, config.DEFAULT_TEMPERATURE_FFE_SLEEP)
  90. #
  91. # Callback initialisation
  92. #
  93. # on/off with button
  94. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  95. self.main_light_shelly.toggle_output_0_mcb)
  96. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  97. self.bed_light_di_tradfri.toggle_output_0_mcb)
  98. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  99. self.bed_light_ma_powerplug.toggle_output_0_mcb)
  100. # bed light
  101. # switch
  102. self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.bed_light_di_tradfri.set_output_0_mcb)
  103. self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_state_mcb)
  104. self.gui_bed_light_ma.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.bed_light_ma_powerplug.set_output_0_mcb)
  105. self.bed_light_ma_powerplug.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_bed_light_ma.set_state_mcb)
  106. # brightness and color temperature
  107. self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb)
  108. self.gui_bed_light_di.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.bed_light_di_tradfri.set_brightness_mcb)
  109. self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_bed_light_di.set_enable_mcb)
  110. self.bed_light_di_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_bed_light_di.set_brightness_mcb)
  111. #
  112. self.main_light_videv = videv_switch_brightness_color_temp(
  113. mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
  114. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  115. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  116. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  117. )
  118. self.bed_light_di_videv = videv_switch_brightness(
  119. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
  120. self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  121. self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  122. )
  123. self.bed_light_ma_videv = videv_switching(
  124. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
  125. self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  126. )
  127. def all_off(self, device=None, key=None, data=None):
  128. super().all_off(device, key, data)
  129. self.bed_light_di_tradfri.set_output_0(False)
  130. self.bed_light_ma_powerplug.set_output_0(False)
  131. class first_floor_east_living(room_shelly_tradfri_light):
  132. def __init__(self, mqtt_client):
  133. # http://shelly1l-3C6105E3F910
  134. super().__init__(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY,
  135. config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_GUI, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
  136. for i in range(1, 7):
  137. setattr(self, 'floorlamp_tradfri_%d' % i, devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i))
  138. #
  139. if config.CHRISTMAS:
  140. self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  141. self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  142. #
  143. self.gui_floorlamp = devices.nodered_gui_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_GUI)
  144. #
  145. if config.CHRISTMAS:
  146. self.gui_xmas_tree = devices.nodered_gui_switch(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_GUI)
  147. #
  148. # Callback initialisation
  149. #
  150. # floor lamp
  151. for device in self.__floorlamp_devices__():
  152. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, device.set_output_0_mcb, True)
  153. self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_STATE, None, device.set_output_0_mcb)
  154. self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, device.set_brightness_mcb)
  155. self.gui_floorlamp.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, device.set_color_temp_mcb)
  156. self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_state_mcb)
  157. self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_OUTPUT_0, None, self.gui_floorlamp.set_enable_mcb)
  158. self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_floorlamp.set_brightness_mcb)
  159. self.floorlamp_tradfri_1.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_floorlamp.set_color_temp_mcb)
  160. #
  161. if config.CHRISTMAS:
  162. self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.gui_xmas_tree.set_state_mcb)
  163. self.gui_xmas_tree.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_xmas_tree.set_output_0_mcb)
  164. #
  165. self.powerplug_xmas_tree.add_callback(devices.silvercrest_powerplug.KEY_OUTPUT_0, None, self.powerplug_xmas_star.set_output_0_mcb)
  166. #
  167. self.main_light_videv = videv_switch_brightness_color_temp(
  168. mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
  169. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  170. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  171. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  172. )
  173. self.floorlamp_videv = videv_switch_brightness_color_temp(
  174. mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
  175. self.floorlamp_tradfri_1, devices.tradfri_light.KEY_OUTPUT_0,
  176. self.floorlamp_tradfri_1, devices.tradfri_light.KEY_BRIGHTNESS,
  177. self.floorlamp_tradfri_1, devices.tradfri_light.KEY_COLOR_TEMP
  178. )
  179. if config.CHRISTMAS:
  180. self.xmas_tree_videv = videv_switching(
  181. mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
  182. self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
  183. )
  184. def all_off(self, device=None, key=None, data=None):
  185. super().all_off(device, key, data)
  186. for floorlamp in self.__floorlamp_devices__():
  187. floorlamp.set_output_0(False)
  188. if config.CHRISTMAS:
  189. self.powerplug_xmas_tree.set_output_0(False)
  190. self.powerplug_xmas_star.set_output_0(False)
  191. def __floorlamp_devices__(self):
  192. rv = []
  193. for i in range(1, 7):
  194. rv.append(getattr(self, 'floorlamp_tradfri_%d' % i))
  195. return rv