Smarthome Functionen
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

first_floor_east.py 13KB

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