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.

ground_floor_west.py 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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, heating_function
  7. import logging
  8. from function.rooms import room
  9. from function.videv import videv_switching, videv_switch_brightness_color_temp, videv_heating, videv_multistate
  10. import task
  11. try:
  12. from config import APP_NAME as ROOT_LOGGER_NAME
  13. except ImportError:
  14. ROOT_LOGGER_NAME = 'root'
  15. logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
  16. class ground_floor_west_floor(room):
  17. def __init__(self, mqtt_client):
  18. #
  19. # Device initialisation
  20. #
  21. # http://shelly1l-84CCA8AD1148
  22. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_SHELLY)
  23. self.main_light_tradfri = devices.group(
  24. devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 1),
  25. devices.tradfri_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_ZIGBEE % 2)
  26. )
  27. super().__init__(mqtt_client)
  28. #
  29. # Functionality initialisation
  30. #
  31. # Request silvercrest data of lead light after power on
  32. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, True, self.main_light_tradfri[0].request_data, True)
  33. ##### TEMPORARY ###################################################################################################################
  34. self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_GUI)
  35. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
  36. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
  37. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
  38. self.main_light_tradfri[0].add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
  39. self.main_light_tradfri[0].add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
  40. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
  41. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
  42. ##### TEMPORARY ###################################################################################################################
  43. #
  44. # Virtual Device Interface
  45. #
  46. self.main_light_videv = videv_switch_brightness_color_temp(
  47. mqtt_client, config.TOPIC_GFW_FLOOR_MAIN_LIGHT_VIDEV,
  48. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  49. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  50. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  51. )
  52. class ground_floor_west_marion(room):
  53. def __init__(self, mqtt_client):
  54. #
  55. # Device initialisation
  56. #
  57. # http://shelly1l-E8DB84A1E067
  58. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_SHELLY)
  59. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_ZIGBEE)
  60. super().__init__(mqtt_client)
  61. #
  62. # Functionality initialisation
  63. #
  64. # heating function
  65. self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_MARION)
  66. ##### TEMPORARY ###################################################################################################################
  67. self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_GUI)
  68. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
  69. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
  70. self.gui_heating = devices.nodered_gui_radiator(mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_GUI)
  71. self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_temperature_mcb, True)
  72. def set_heating_setpoint(device, key, data):
  73. self.heating_function.set(heating_function.KEY_USER_TEMPERATURE_SETPOINT, data)
  74. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TEMP, None, set_heating_setpoint)
  75. self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_setpoint_temperature_mcb, True)
  76. def boost(device, key, data):
  77. self.heating_function.set(heating_function.KEY_START_BOOST, data)
  78. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_BOOST, None, boost)
  79. def setpoint_to_default(device, key, data):
  80. self.heating_function.set(heating_function.KEY_SET_DEFAULT_TEMPERATURE, data)
  81. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, setpoint_to_default)
  82. def away_mode(device, key, data):
  83. self.heating_function.set(heating_function.KEY_AWAY_MODE, data)
  84. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, away_mode)
  85. self.heating_function.add_callback(heating_function.KEY_AWAY_MODE, None, self.gui_heating.set_away_mcb)
  86. def summer_mode(device, key, data):
  87. self.heating_function.set(heating_function.KEY_SUMMER_MODE, data)
  88. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, summer_mode)
  89. self.heating_function.add_callback(heating_function.KEY_SUMMER_MODE, None, self.gui_heating.set_summer_mcb)
  90. self.heating_function.add_callback(heating_function.KEY_BOOST_TIMER, None, self.gui_heating.set_timer_mcb)
  91. ##### TEMPORARY ###################################################################################################################
  92. #
  93. # Virtual Device Interface
  94. #
  95. self.main_light_videv = videv_switching(
  96. mqtt_client, config.TOPIC_GFW_MARION_MAIN_LIGHT_VIDEV,
  97. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0
  98. )
  99. self.heating_function_videv = videv_heating(
  100. mqtt_client, config.TOPIC_GFW_MARION_HEATING_VALVE_VIDEV,
  101. self.heating_function
  102. )
  103. class ground_floor_west_dirk(room):
  104. STATE_ACTIVE_DEVICE_MAIN_LIGHT = 0
  105. STATE_ACTIVE_DEVICE_DESK_LIGHT = 1
  106. STATE_ACTIVE_DEVICE_AMPLIFIER = 2
  107. STATE_ACTIVE_DEVICE_MAX_VALUE = STATE_ACTIVE_DEVICE_AMPLIFIER
  108. #
  109. LED_ACTIVE_DEVICE_MAIN_LIGHT = devices.nodered_gui_leds.KEY_LED_0
  110. LED_ACTIVE_DEVICE_DESK_LIGHT = devices.nodered_gui_leds.KEY_LED_1
  111. LED_ACTIVE_DEVICE_AMPLIFIER = devices.nodered_gui_leds.KEY_LED_2
  112. #
  113. KEY_POWERPLUG_AMPLIFIER = devices.my_powerplug.KEY_OUTPUT_0
  114. KEY_POWERPLUG_CD_PLAYER = devices.my_powerplug.KEY_OUTPUT_2
  115. KEY_POWERPLUG_DESK_LIGHT = devices.my_powerplug.KEY_OUTPUT_1
  116. KEY_POWERPLUG_PC_DOCK = devices.my_powerplug.KEY_OUTPUT_3
  117. #
  118. AUDIO_SOURCE_PC = 0
  119. AUDIO_SOURCE_CD = 1
  120. AUDIO_SOURCE_RASPI = 2
  121. def __init__(self, mqtt_client):
  122. #
  123. # Device initialisation
  124. #
  125. # http://shelly1l-3C6105E44F27
  126. self.main_light_shelly = devices.shelly(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_SHELLY)
  127. self.main_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_ZIGBEE)
  128. self.powerplug_common = devices.my_powerplug(mqtt_client, config.TOPIC_GFW_DIRK_POWERPLUG)
  129. self.desk_light_tradfri = devices.tradfri_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_ZIGBEE)
  130. self.button_tradfri = devices.tradfri_button(mqtt_client, config.TOPIC_GFW_DIRK_INPUT_DEVICE)
  131. self.remote_amplifier = devices.remote(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_REMOTE)
  132. self.heating_valve = devices.brennenstuhl_heatingvalve(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_ZIGBEE)
  133. super().__init__(mqtt_client)
  134. #
  135. # Functionality initialisation
  136. #
  137. # Button - Brightness functionality
  138. self.brightness_functions = brightness_choose_n_action(self.button_tradfri)
  139. self.brightness_functions.add(self.main_light_tradfri, self.main_light_shelly, devices.shelly.KEY_OUTPUT_0)
  140. self.brightness_functions.add(self.desk_light_tradfri, self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT)
  141. self.brightness_functions.add(self.remote_amplifier, self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER)
  142. # Button - Main light
  143. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_TOGGLE,
  144. self.main_light_shelly.toggle_output_0_mcb)
  145. # Button - Desk light
  146. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT,
  147. self.powerplug_common.toggle_output_1_mcb)
  148. # Button - Amplifier
  149. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT_LONG,
  150. self.powerplug_common.toggle_output_0_mcb)
  151. # Button - CD player
  152. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_RIGHT_LONG,
  153. self.powerplug_common.toggle_output_2_mcb)
  154. # Button - PC dock
  155. self.button_tradfri.add_callback(devices.tradfri_button.KEY_ACTION, devices.tradfri_button.ACTION_LEFT,
  156. self.powerplug_common.toggle_output_3_mcb)
  157. # Mediaplayer - Spotify / MPD state
  158. self.spotify_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_SPOTIFY)
  159. self.mpd_state = devices.audio_status(mqtt_client, config.TOPIC_GFW_DIRK_MPD)
  160. # Mediaplayer - Amplifier auto on
  161. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.powerplug_common.set_output_0_mcb, True)
  162. self.spotify_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
  163. self.mpd_state.add_callback(devices.status.KEY_STATE, None, self.powerplug_common.set_output_0_mcb, True)
  164. # Mediaplayer - Audio source selection
  165. self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, True, self.audio_source_selector, True)
  166. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, True, self.audio_source_selector, True)
  167. self.spotify_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
  168. self.mpd_state.add_callback(devices.status.KEY_STATE, True, self.audio_source_selector, True)
  169. self.audio_source = self.AUDIO_SOURCE_PC
  170. # heating function
  171. self.heating_function = heating_function(self.heating_valve, config.DEFAULT_TEMPERATURE_GFW_DIRK)
  172. ##### TEMPORARY ###################################################################################################################
  173. self.gui_main_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_GUI)
  174. self.gui_desk_light = devices.nodered_gui_light(mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_GUI)
  175. self.gui_amplifier = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_GUI)
  176. self.gui_cd_player = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_GUI)
  177. self.gui_pc_dock = devices.nodered_gui_switch(mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_GUI)
  178. # Callback initialisation
  179. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.main_light_shelly.set_output_0_mcb)
  180. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
  181. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_state_mcb)
  182. self.main_light_shelly.add_callback(devices.shelly.KEY_OUTPUT_0, None, self.gui_main_light.set_enable_mcb)
  183. self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_main_light.set_brightness_mcb)
  184. self.main_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_main_light.set_color_temp_mcb)
  185. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.main_light_tradfri.set_brightness_mcb)
  186. self.gui_main_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.main_light_tradfri.set_color_temp_mcb)
  187. self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_STATE, None, self.powerplug_common.set_output_1_mcb)
  188. self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_desk_light.set_state_mcb)
  189. self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_BRIGHTNESS, None, self.desk_light_tradfri.set_brightness_mcb)
  190. self.gui_desk_light.add_callback(devices.nodered_gui_light.KEY_COLOR_TEMP, None, self.desk_light_tradfri.set_color_temp_mcb)
  191. self.powerplug_common.add_callback(self.KEY_POWERPLUG_DESK_LIGHT, None, self.gui_desk_light.set_enable_mcb)
  192. self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_BRIGHTNESS, None, self.gui_desk_light.set_brightness_mcb)
  193. self.desk_light_tradfri.add_callback(devices.tradfri_light.KEY_COLOR_TEMP, None, self.gui_desk_light.set_color_temp_mcb)
  194. self.gui_amplifier.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_0_mcb)
  195. self.powerplug_common.add_callback(self.KEY_POWERPLUG_AMPLIFIER, None, self.gui_amplifier.set_state_mcb)
  196. self.gui_cd_player.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_2_mcb)
  197. self.powerplug_common.add_callback(self.KEY_POWERPLUG_CD_PLAYER, None, self.gui_cd_player.set_state_mcb)
  198. self.gui_pc_dock.add_callback(devices.nodered_gui_switch.KEY_STATE, None, self.powerplug_common.set_output_3_mcb)
  199. self.powerplug_common.add_callback(self.KEY_POWERPLUG_PC_DOCK, None, self.gui_pc_dock.set_state_mcb)
  200. self.gui_heating = devices.nodered_gui_radiator(mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_GUI)
  201. def set_heating_setpoint(device, key, data):
  202. self.heating_function.set(heating_function.KEY_USER_TEMPERATURE_SETPOINT, data)
  203. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TEMP, None, set_heating_setpoint)
  204. self.heating_function.add_callback(heating_function.KEY_TEMPERATURE_SETPOINT, None, self.gui_heating.set_setpoint_temperature_mcb, True)
  205. def boost(device, key, data):
  206. self.heating_function.set(heating_function.KEY_START_BOOST, data)
  207. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_BOOST, None, boost)
  208. def setpoint_to_default(device, key, data):
  209. self.heating_function.set(heating_function.KEY_SET_DEFAULT_TEMPERATURE, data)
  210. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SETPOINT_TO_DEFAULT, None, setpoint_to_default)
  211. def away_mode(device, key, data):
  212. self.heating_function.set(heating_function.KEY_AWAY_MODE, data)
  213. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_AWAY, None, away_mode)
  214. self.heating_function.add_callback(heating_function.KEY_AWAY_MODE, None, self.gui_heating.set_away_mcb)
  215. def summer_mode(device, key, data):
  216. self.heating_function.set(heating_function.KEY_SUMMER_MODE, data)
  217. self.gui_heating.add_callback(devices.nodered_gui_radiator.KEY_SUMMER, None, summer_mode)
  218. self.heating_function.add_callback(heating_function.KEY_SUMMER_MODE, None, self.gui_heating.set_summer_mcb)
  219. self.heating_function.add_callback(heating_function.KEY_BOOST_TIMER, None, self.gui_heating.set_timer_mcb)
  220. self.gui_led_active_device = devices.nodered_gui_leds(mqtt_client, config.TOPIC_GFW_DIRK_DEVICE_CHOOSER_LED)
  221. def update_active_device_led(device, key, data):
  222. for i in range(0, len(self.brightness_functions.brightness_device_list)):
  223. self.gui_led_active_device.set_led(devices.nodered_gui_leds.KEY_LED_LIST[i], data == i)
  224. self.brightness_functions.add_callback(brightness_choose_n_action.KEY_ACTIVE_DEVICE, None, update_active_device_led, True)
  225. ##### TEMPORARY ###################################################################################################################
  226. #
  227. # Virtual Device Interface
  228. #
  229. self.main_light_videv = videv_switch_brightness_color_temp(
  230. mqtt_client, config.TOPIC_GFW_DIRK_MAIN_LIGHT_VIDEV,
  231. self.main_light_shelly, devices.shelly.KEY_OUTPUT_0,
  232. self.main_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  233. self.main_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  234. )
  235. self.desk_light_videv = videv_switch_brightness_color_temp(
  236. mqtt_client, config.TOPIC_GFW_DIRK_DESK_LIGHT_VIDEV,
  237. self.powerplug_common, self.KEY_POWERPLUG_DESK_LIGHT,
  238. self.desk_light_tradfri, devices.tradfri_light.KEY_BRIGHTNESS,
  239. self.desk_light_tradfri, devices.tradfri_light.KEY_COLOR_TEMP
  240. )
  241. self.amplifier_videv = videv_switching(
  242. mqtt_client, config.TOPIC_GFW_DIRK_AMPLIFIER_VIDEV,
  243. self.powerplug_common, self.KEY_POWERPLUG_AMPLIFIER
  244. )
  245. self.cd_player_videv = videv_switching(
  246. mqtt_client, config.TOPIC_GFW_DIRK_CD_PLAYER_VIDEV,
  247. self.powerplug_common, self.KEY_POWERPLUG_CD_PLAYER
  248. )
  249. self.pc_dock_videv = videv_switching(
  250. mqtt_client, config.TOPIC_GFW_DIRK_PC_DOCK_VIDEV,
  251. self.powerplug_common, self.KEY_POWERPLUG_PC_DOCK
  252. )
  253. self.heating_function_videv = videv_heating(
  254. mqtt_client, config.TOPIC_GFW_DIRK_HEATING_VALVE_VIDEV,
  255. self.heating_function
  256. )
  257. self.brightness_functions_device_videv = videv_multistate(
  258. mqtt_client, config.TOPIC_GFW_DIRK_ACTIVE_BRIGHTNESS_DEVICE_VIDEV,
  259. brightness_choose_n_action.KEY_ACTIVE_DEVICE, self.brightness_functions, 3
  260. )
  261. #
  262. # Other stuff
  263. #
  264. self.delayed_task_remote = task.delayed(1.0, self.send_audio_source)
  265. def all_off(self, device=None, key=None, data=None):
  266. super().all_off(device, key, data)
  267. self.powerplug_common.set_output_all(False)
  268. def audio_source_selector(self, device, key, data):
  269. if device == self.powerplug_common and key == self.KEY_POWERPLUG_CD_PLAYER:
  270. # switch on of cd player
  271. self.audio_source = self.AUDIO_SOURCE_CD
  272. elif device in [self.spotify_state, self.mpd_state]:
  273. # switch on raspi-source
  274. self.audio_source = self.AUDIO_SOURCE_RASPI
  275. elif device == self.powerplug_common and key == self.KEY_POWERPLUG_AMPLIFIER:
  276. # switch on of amplifier -> select source and reset stored source value
  277. self.delayed_task_remote.run()
  278. def send_audio_source(self):
  279. if self.audio_source == self.AUDIO_SOURCE_PC:
  280. logger.info("Sending IR command to change audio source to pc")
  281. self.remote_amplifier.set_line3()
  282. elif self.audio_source == self.AUDIO_SOURCE_CD:
  283. logger.info("Sending IR command to change audio source to cd")
  284. self.remote_amplifier.set_cd()
  285. elif self.audio_source == self.AUDIO_SOURCE_RASPI:
  286. logger.info("Sending IR command to change audio source to raspi")
  287. self.remote_amplifier.set_line1()
  288. self.audio_source = self.AUDIO_SOURCE_PC