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.

first_floor_east.py 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. # heating function
  54. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_KITCHEN_HEATING_VALVE_ZIGBEE)
  55. super().__init__(mqtt_client)
  56. #
  57. # Functionality initialisation
  58. #
  59. # circulation pump
  60. self.circulation_pump = timer_on_activation(self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0, 10*60)
  61. self.circulation_pump_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_shelly.flash_0_mcb, True)
  62. # heating function
  63. self.heating_function = heating_function(
  64. self.heating_valve,
  65. config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
  66. **get_radiator_data(self.heating_valve.topic)
  67. )
  68. self.heating_function.add_callback(None, None, set_radiator_data, True)
  69. #
  70. # Virtual Device Interface
  71. #
  72. # main light
  73. self.main_light_videv = videv_switching(
  74. mqtt_client, config.TOPIC_FFE_KITCHEN_MAIN_LIGHT_VIDEV,
  75. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  76. )
  77. # circulation pump
  78. self.circulation_pump_videv = videv_switching_timer(
  79. mqtt_client, config.TOPIC_FFE_KITCHEN_CIRCULATION_PUMP_VIDEV,
  80. self.circulation_pump_shelly, devices.shelly.KEY_OUTPUT_0,
  81. self.circulation_pump, timer_on_activation.KEY_TIMER
  82. )
  83. # heating function
  84. self.heating_function_videv = videv_heating(
  85. mqtt_client, config.TOPIC_FFE_KITCHEN_HEATING_VALVE_VIDEV,
  86. self.heating_function
  87. )
  88. class first_floor_east_dining(room):
  89. def __init__(self, mqtt_client):
  90. #
  91. # Device initialisation
  92. #
  93. self.day_events = day_event((6, 0), (22, 0), 30, -30)
  94. # http://shelly1l-84CCA8ADD055
  95. # main light
  96. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_SHELLY)
  97. # floor lamp
  98. self.floorlamp_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_POWERPLUG)
  99. # heating function
  100. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_DININGROOM_HEATING_VALVE_ZIGBEE)
  101. # garland
  102. if config.CHRISTMAS:
  103. self.garland_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_POWERPLUG)
  104. super().__init__(mqtt_client)
  105. #
  106. # Functionality initialisation
  107. #
  108. self.day_events.add_callback(None, True, self.__day_events__, True)
  109. # main light
  110. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_powerplug.set_output_0_mcb, True)
  111. # heating function
  112. self.heating_function = heating_function(
  113. self.heating_valve,
  114. config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
  115. **get_radiator_data(self.heating_valve.topic)
  116. )
  117. self.heating_function.add_callback(None, None, set_radiator_data, True)
  118. #
  119. # Virtual Device Interface
  120. #
  121. # main light
  122. self.main_light_videv = videv_switching(
  123. mqtt_client, config.TOPIC_FFE_DININGROOM_MAIN_LIGHT_VIDEV,
  124. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  125. )
  126. # floor lamp
  127. self.floorlamp_videv = videv_switching(
  128. mqtt_client, config.TOPIC_FFE_DININGROOM_FLOOR_LAMP_VIDEV,
  129. self.floorlamp_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  130. )
  131. # heating function
  132. self.heating_function_videv = videv_heating(
  133. mqtt_client, config.TOPIC_FFE_DININGROOM_HEATING_VALVE_VIDEV,
  134. self.heating_function
  135. )
  136. # garland
  137. if config.CHRISTMAS:
  138. self.garland_videv = videv_switching(
  139. mqtt_client, config.TOPIC_FFE_DININGROOM_GARLAND_VIDEV,
  140. self.garland_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  141. )
  142. def __day_events__(self, device, key, data):
  143. if key in (self.day_events.KEY_SUNSET, self.day_events.KEY_START_OF_DAY):
  144. if config.CHRISTMAS:
  145. self.garland_powerplug.set_output_0(True)
  146. elif key in (self.day_events.KEY_START_OF_NIGHT, self.day_events.KEY_SUNRISE):
  147. if config.CHRISTMAS:
  148. self.garland_powerplug.set_output_0(False)
  149. class first_floor_east_sleep(room):
  150. def __init__(self, mqtt_client):
  151. #
  152. # Device initialisation
  153. #
  154. # http://shelly1l-E8DB84A254C7
  155. # main light
  156. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_SHELLY)
  157. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_ZIGBEE)
  158. # bed light
  159. self.bed_light_di_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_ZIGBEE)
  160. self.bed_light_ma_powerplug = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_POWERPLUG)
  161. # heating function
  162. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_ZIGBEE)
  163. # button
  164. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_FFE_SLEEP_INPUT_DEVICE)
  165. super().__init__(mqtt_client)
  166. #
  167. # Functionality initialisation
  168. #
  169. # button / brightness function
  170. self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
  171. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  172. self.brightness_functions.add(self.bed_light_di_tradfri, self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0)
  173. # button / main light
  174. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  175. self.main_light_shelly.toggle_output_0_mcb)
  176. # button / bed light
  177. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  178. self.bed_light_di_tradfri.toggle_output_0_mcb)
  179. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  180. self.bed_light_ma_powerplug.toggle_output_0_mcb)
  181. # heating function
  182. self.heating_function = heating_function(
  183. self.heating_valve,
  184. config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
  185. **get_radiator_data(self.heating_valve.topic)
  186. )
  187. self.heating_function.add_callback(None, None, set_radiator_data, True)
  188. #
  189. # Virtual Device Interface
  190. #
  191. # main light
  192. self.main_light_videv = videv_switch_brightness_color_temp(
  193. mqtt_client, config.TOPIC_FFE_SLEEP_MAIN_LIGHT_VIDEV,
  194. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  195. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  196. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  197. )
  198. # bed light
  199. self.bed_light_di_videv = videv_switch_brightness(
  200. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_DI_VIDEV,
  201. self.bed_light_di_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  202. self.bed_light_di_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  203. )
  204. self.bed_light_ma_videv = videv_switching(
  205. mqtt_client, config.TOPIC_FFE_SLEEP_BED_LIGHT_MA_VIDEV,
  206. self.bed_light_ma_powerplug, devices.silvercrest_powerplug.KEY_OUTPUT_0
  207. )
  208. # heating function
  209. self.heating_function_videv = videv_heating(
  210. mqtt_client, config.TOPIC_FFE_SLEEP_HEATING_VALVE_VIDEV,
  211. self.heating_function
  212. )
  213. # button
  214. self.brightness_functions_device_videv = videv_multistate(
  215. mqtt_client, config.TOPIC_FFE_SLEEP_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
  216. brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 2
  217. )
  218. class first_floor_east_living(room):
  219. def __init__(self, mqtt_client):
  220. #
  221. # Device initialisation
  222. #
  223. # http://shelly1l-3C6105E3F910
  224. # main light
  225. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_SHELLY)
  226. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_ZIGBEE)
  227. # floor lamp
  228. self.floorlamp_tradfri = devices.group(
  229. *[devices.tradfri_light(mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_ZIGBEE % i) for i in range(1, 7)])
  230. # heating function
  231. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_FFE_LIVINGROOM_HEATING_VALVE_ZIGBEE)
  232. # xmas tree
  233. if config.CHRISTMAS:
  234. self.powerplug_xmas_tree = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_POWERPLUG)
  235. self.powerplug_xmas_star = devices.silvercrest_powerplug(mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_STAR_POWERPLUG)
  236. super().__init__(mqtt_client)
  237. #
  238. # Functionality initialisation
  239. #
  240. # floor lamp synchronisation with main_light
  241. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.floorlamp_tradfri.set_output_0_mcb, True)
  242. # heating function
  243. self.heating_function = heating_function(
  244. self.heating_valve,
  245. config.DEFAULT_TEMPERATURE[self.heating_valve.topic],
  246. **get_radiator_data(self.heating_valve.topic)
  247. )
  248. self.heating_function.add_callback(None, None, set_radiator_data, True)
  249. #
  250. # Virtual Device Interface
  251. #
  252. # main light
  253. self.main_light_videv = videv_switch_brightness_color_temp(
  254. mqtt_client, config.TOPIC_FFE_LIVINGROOM_MAIN_LIGHT_VIDEV,
  255. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  256. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  257. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  258. )
  259. # floor lamp
  260. self.floorlamp_videv = videv_switch_brightness_color_temp(
  261. mqtt_client, config.TOPIC_FFE_LIVINGROOM_FLOOR_LAMP_VIDEV,
  262. self.floorlamp_tradfri, devices.tradfri_light.KEY_OUTPUT_0,
  263. self.floorlamp_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  264. self.floorlamp_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  265. )
  266. # heating function
  267. self.heating_function_videv = videv_heating(
  268. mqtt_client, config.TOPIC_FFE_LIVINGROOM_HEATING_VALVE_VIDEV,
  269. self.heating_function
  270. )
  271. # xmas tree
  272. if config.CHRISTMAS:
  273. self.xmas_tree_videv = videv_switching(
  274. mqtt_client, config.TOPIC_FFE_LIVINGROOM_XMAS_TREE_VIDEV,
  275. self.powerplug_xmas_tree, devices.silvercrest_powerplug.KEY_OUTPUT_0
  276. )