Smarthome Functionen
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

first_floor_east.py 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. import config
  5. import devices
  6. from function.db import get_radiator_data, set_radiator_data
  7. from function.helpers import day_event
  8. from function.modules import brightness_choose_n_action, timer_on_activation, heating_function
  9. from function.rooms import room, room_collection
  10. from function.videv import videv_switching, videv_switch_brightness, videv_switching_timer, videv_switch_brightness_color_temp, videv_heating, videv_multistate
  11. import logging
  12. try:
  13. from config import APP_NAME as ROOT_LOGGER_NAME
  14. except ImportError:
  15. ROOT_LOGGER_NAME = 'root'
  16. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  17. class first_floor_east(room_collection):
  18. def __init__(self, mqtt_client):
  19. super().__init__(mqtt_client)
  20. self.dining = first_floor_east_dining(mqtt_client)
  21. self.floor = first_floor_east_floor(mqtt_client)
  22. self.kitchen = first_floor_east_kitchen(mqtt_client)
  23. self.livingroom = first_floor_east_living(mqtt_client)
  24. self.sleep = first_floor_east_sleep(mqtt_client)
  25. class first_floor_east_floor(room):
  26. def __init__(self, mqtt_client):
  27. #
  28. # Device initialisation
  29. #
  30. # http://shelly1l-3C6105E4E629
  31. # main light
  32. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_SHELLY)
  33. super().__init__(mqtt_client)
  34. #
  35. # Virtual Device Interface
  36. #
  37. # main light
  38. self.main_light = videv_switching(
  39. mqtt_client, config.TOPIC_FFE_FLOOR_MAIN_LIGHT_VIDEV,
  40. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  41. )
  42. class first_floor_east_kitchen(room):
  43. def __init__(self, mqtt_client):
  44. #
  45. # Device initialisation
  46. #
  47. # http://shelly1l-8CAAB5616C01
  48. # main light
  49. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_SHELLY)
  50. # http://shelly1-e89f6d85a466/
  51. # circulation pump
  52. self.circulation_pump_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_SHELLY)
  53. super().__init__(mqtt_client)
  54. #
  55. # Functionality initialisation
  56. #
  57. # circulation pump
  58. self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
  59. self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
  60. #
  61. # Virtual Device Interface
  62. #
  63. # main light
  64. self.main_light_videv = videv_switching(
  65. mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
  66. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  67. )
  68. # circulation pump
  69. self.circulation_pump_videv = videv_switching_timer(
  70. mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
  71. self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0,
  72. self.circulation_pump, timer_on_activation.KEY_TIMER
  73. )
  74. class first_floor_east_dining(room):
  75. def __init__(self, mqtt_client):
  76. #
  77. # Device initialisation
  78. #
  79. self.day_events = day_event((6, 0), (22, 0), 30, -30)
  80. # http://shelly1l-84CCA8ADD055
  81. # main light
  82. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)
  83. # floor lamp
  84. self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  85. # heating function
  86. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE)
  87. # garland
  88. if config.CHRISTMAS:
  89. self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  90. super().__init__(mqtt_client)
  91. #
  92. # Functionality initialisation
  93. #
  94. self.day_events.add_callback(None, True, self.__day_events__, True)
  95. # main light
  96. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
  97. # heating function
  98. self.heating_function = heating_function(
  99. self.heating_valve,
  100. config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
  101. **get_radiator_data(self.heating_valve.topic)
  102. )
  103. self.heating_function.add_callback(None, None, set_radiator_data, True)
  104. #
  105. # Virtual Device Interface
  106. #
  107. # main light
  108. self.main_light_videv = videv_switching(
  109. mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
  110. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  111. )
  112. # floor lamp
  113. self.floorlamp_videv = videv_switching(
  114. mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
  115. self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  116. )
  117. # heating function
  118. self.heating_function_videv = videv_heating(
  119. mqtt_client, config.TOPIC_FFE_DININGROOM_HEATING_VALVE_VIDEV,
  120. self.heating_function
  121. )
  122. # garland
  123. if config.CHRISTMAS:
  124. self.garland_videv = videv_switching(
  125. mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV,
  126. self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  127. )
  128. def __day_events__(self, device, key, data):
  129. if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
  130. if config.CHRISTMAS:
  131. self.garland_powerplug.set_output_0(True)
  132. elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
  133. if config.CHRISTMAS:
  134. self.garland_powerplug.set_output_0(False)
  135. class first_floor_east_sleep(room):
  136. def __init__(self, mqtt_client):
  137. #
  138. # Device initialisation
  139. #
  140. # http://shelly1l-E8DB84A254C7
  141. # main light
  142. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY)
  143. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
  144. # bed light
  145. self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
  146. self.bed_light_ma_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
  147. # heating function
  148. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
  149. # button
  150. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
  151. super().__init__(mqtt_client)
  152. #
  153. # Functionality initialisation
  154. #
  155. # button / brightness function
  156. self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
  157. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  158. self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
  159. # button / main light
  160. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  161. self.main_light_shelly.toggle_output_0_mcb)
  162. # button / bed light
  163. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  164. self.bed_light_di_tradfri.toggle_output_0_mcb)
  165. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  166. self.bed_light_ma_powerplug.toggle_output_0_mcb)
  167. # heating function
  168. self.heating_function = heating_function(
  169. self.heating_valve,
  170. config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
  171. **get_radiator_data(self.heating_valve.topic)
  172. )
  173. self.heating_function.add_callback(None, None, set_radiator_data, True)
  174. #
  175. # Virtual Device Interface
  176. #
  177. # main light
  178. self.main_light_videv = videv_switch_brightness_color_temp(
  179. mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
  180. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  181. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  182. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  183. )
  184. # bed light
  185. self.bed_light_di_videv = videv_switch_brightness(
  186. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
  187. self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  188. self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  189. )
  190. self.bed_light_ma_videv = videv_switching(
  191. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
  192. self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  193. )
  194. # heating function
  195. self.heating_function_videv = videv_heating(
  196. mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV,
  197. self.heating_function
  198. )
  199. # button
  200. self.brightness_functions_device_videv = videv_multistate(
  201. mqtt_client, config.TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
  202. brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2
  203. )
  204. class first_floor_east_living(room):
  205. def __init__(self, mqtt_client):
  206. #
  207. # Device initialisation
  208. #
  209. # http://shelly1l-3C6105E3F910
  210. # main light
  211. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY)
  212. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
  213. # floor lamp
  214. self.floorlamp_tradfri = devices.group(
  215. *[devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i) for i in range(1, 7)])
  216. # heating function
  217. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE)
  218. # xmas tree
  219. if config.CHRISTMAS:
  220. self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  221. self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  222. super().__init__(mqtt_client)
  223. #
  224. # Functionality initialisation
  225. #
  226. # floor lamp synchronisation with main_light
  227. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
  228. # heating function
  229. self.heating_function = heating_function(
  230. self.heating_valve,
  231. config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
  232. **get_radiator_data(self.heating_valve.topic)
  233. )
  234. self.heating_function.add_callback(None, None, set_radiator_data, True)
  235. #
  236. # Virtual Device Interface
  237. #
  238. # main light
  239. self.main_light_videv = videv_switch_brightness_color_temp(
  240. mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
  241. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  242. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  243. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  244. )
  245. # floor lamp
  246. self.floorlamp_videv = videv_switch_brightness_color_temp(
  247. mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
  248. self.floorlamp_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  249. self.floorlamp_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  250. self.floorlamp_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  251. )
  252. # heating function
  253. self.heating_function_videv = videv_heating(
  254. mqtt_client, config.TOPIC_FFE_LIVINGROOM_HEATING_VALVE_VIDEV,
  255. self.heating_function
  256. )
  257. # xmas tree
  258. if config.CHRISTMAS:
  259. self.xmas_tree_videv = videv_switching(
  260. mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
  261. self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
  262. )