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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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, timer_on_activation, heating_function
  7. from function.rooms import room, room_collection
  8. from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate
  9. import logging
  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(room_collection):
  16. def __init__(self, mqtt_client):
  17. super().__init__(mqtt_client)
  18. self.dining = first_floor_east_dining(mqtt_client)
  19. self.floor = first_floor_east_floor(mqtt_client)
  20. self.kitchen = first_floor_east_kitchen(mqtt_client)
  21. self.livingroom = first_floor_east_living(mqtt_client)
  22. self.sleep = first_floor_east_sleep(mqtt_client)
  23. class first_floor_east_floor(room):
  24. def __init__(self, mqtt_client):
  25. #
  26. # Device initialisation
  27. #
  28. # http://shelly1l-3C6105E4E629
  29. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)
  30. super().__init__(mqtt_client)
  31. #
  32. # Virtual Device Interface
  33. #
  34. self.main_light = videv_switching(
  35. mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
  36. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  37. )
  38. class first_floor_east_kitchen(room):
  39. def __init__(self, mqtt_client):
  40. #
  41. # Device initialisation
  42. #
  43. # http://shelly1l-8CAAB5616C01
  44. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY)
  45. # http://shelly1-e89f6d85a466/
  46. self.circulation_pump_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY)
  47. super().__init__(mqtt_client)
  48. #
  49. # Functionality initialisation
  50. #
  51. self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
  52. self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
  53. #
  54. # Virtual Device Interface
  55. #
  56. self.main_light_videv = videv_switching(
  57. mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
  58. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  59. )
  60. self.circulation_pump_videv = videv_switching_timer(
  61. mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
  62. self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0,
  63. self.circulation_pump, timer_on_activation.KEY_TIMER
  64. )
  65. class first_floor_east_dining(room):
  66. def __init__(self, mqtt_client):
  67. #
  68. # Device initialisation
  69. #
  70. # http://shelly1l-84CCA8ADD055
  71. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)
  72. self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  73. if config.CHRISTMAS:
  74. self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  75. super().__init__(mqtt_client)
  76. #
  77. # Functionality initialisation
  78. #
  79. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
  80. #
  81. # Virtual Device Interface
  82. #
  83. self.main_light_videv = videv_switching(
  84. mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
  85. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  86. )
  87. self.floorlamp_videv = videv_switching(
  88. mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
  89. self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  90. )
  91. if config.CHRISTMAS:
  92. self.garland_videv = videv_switching(
  93. mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV,
  94. self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  95. )
  96. class first_floor_east_sleep(room):
  97. def __init__(self, mqtt_client):
  98. #
  99. # Device initialisation
  100. #
  101. # http://shelly1l-E8DB84A254C7
  102. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY)
  103. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
  104. self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
  105. self.bed_light_ma_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
  106. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
  107. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
  108. super().__init__(mqtt_client)
  109. #
  110. # Functionality initialisation
  111. #
  112. # button / brightness function
  113. self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
  114. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  115. self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
  116. # button / main light
  117. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  118. self.main_light_shelly.toggle_output_0_mcb)
  119. # button / bed light
  120. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  121. self.bed_light_di_tradfri.toggle_output_0_mcb)
  122. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  123. self.bed_light_ma_powerplug.toggle_output_0_mcb)
  124. # heating function
  125. self.heating_function = heating_function(self.heating_valve)
  126. #
  127. # Virtual Device Interface
  128. #
  129. self.main_light_videv = videv_switch_brightness_color_temp(
  130. mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
  131. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  132. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  133. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  134. )
  135. self.bed_light_di_videv = videv_switch_brightness(
  136. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
  137. self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  138. self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  139. )
  140. self.bed_light_ma_videv = videv_switching(
  141. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
  142. self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  143. )
  144. self.heating_function_videv = videv_heating(
  145. mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV,
  146. self.heating_function
  147. )
  148. self.brightness_functions_device_videv = videv_multistate(
  149. mqtt_client, config.TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
  150. brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2
  151. )
  152. class first_floor_east_living(room):
  153. def __init__(self, mqtt_client):
  154. #
  155. # Device initialisation
  156. #
  157. # http://shelly1l-3C6105E3F910
  158. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY)
  159. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
  160. self.floorlamp_tradfri = devices.group(
  161. *[devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i) for i in range(1, 7)])
  162. if config.CHRISTMAS:
  163. self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  164. self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  165. super().__init__(mqtt_client)
  166. #
  167. # Functionality initialisation
  168. #
  169. # floor lamp synchronisation with main_light
  170. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
  171. #
  172. # Virtual Device Interface
  173. #
  174. self.main_light_videv = videv_switch_brightness_color_temp(
  175. mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
  176. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  177. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  178. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  179. )
  180. self.floorlamp_videv = videv_switch_brightness_color_temp(
  181. mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
  182. self.floorlamp_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  183. self.floorlamp_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  184. self.floorlamp_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  185. )
  186. if config.CHRISTMAS:
  187. self.xmas_tree_videv = videv_switching(
  188. mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
  189. self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
  190. )