MQTT Home Emulation
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

home_emulation.py 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import config
  2. import devdi
  3. import devdi.props as props
  4. #import function
  5. #import json
  6. import logging
  7. import mqtt
  8. import os
  9. import report
  10. #import subprocess
  11. import time
  12. logger = logging.getLogger(config.APP_NAME)
  13. if __name__ == "__main__":
  14. #
  15. # Logging
  16. #
  17. if config.DEBUG:
  18. report.appLoggingConfigure(None, 'stdout', ((config.APP_NAME, logging.DEBUG), ),
  19. target_level=logging.WARNING, fmt=report.SHORT_FMT, host='localhost', port=19996)
  20. else:
  21. report.stdoutLoggingConfigure(((config.APP_NAME, logging.WARNING), ), report.SHORT_FMT)
  22. #
  23. # MQTT Client
  24. #
  25. mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
  26. password=config.MQTT_PASSWORD, name=config.APP_NAME)
  27. #
  28. # Smarthome Devices
  29. #
  30. ddi = devdi.devices(mc)
  31. #
  32. # Smart Home Functionality
  33. #
  34. #######
  35. # GFW #
  36. #######
  37. loc = props.LOC_GFW
  38. # DIRK
  39. roo = props.ROO_DIR
  40. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  41. tml = ddi.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
  42. sml.register_power_on_instance(tml)
  43. # FLOOR
  44. roo = props.ROO_FLO
  45. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  46. tml = ddi.get(props.STG_ZGW, loc, roo, props.FUN_MAL, 1)
  47. sml.register_power_on_instance(tml)
  48. tml = ddi.get(props.STG_ZGW, loc, roo, props.FUN_MAL, 2)
  49. sml.register_power_on_instance(tml)
  50. #######
  51. # FFW #
  52. #######
  53. loc = props.LOC_FFW
  54. # JULIAN
  55. roo = props.ROO_JUL
  56. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  57. tml = ddi.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
  58. sml.register_power_on_instance(tml)
  59. # LIVINGROOM
  60. roo = props.ROO_LIV
  61. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  62. tml = ddi.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
  63. sml.register_power_on_instance(tml)
  64. # SLEEP
  65. roo = props.ROO_SLP
  66. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  67. tml = ddi.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
  68. sml.register_power_on_instance(tml)
  69. #######
  70. # FFE #
  71. #######
  72. loc = props.LOC_FFE
  73. # KITCHEN
  74. roo = props.ROO_KIT
  75. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_CIR)
  76. sml.auto_off(600)
  77. # LIVINGROOM
  78. roo = props.ROO_LIV
  79. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  80. tml = ddi.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
  81. sml.register_power_on_instance(tml)
  82. # SLEEP
  83. roo = props.ROO_SLP
  84. sml = ddi.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  85. tml = ddi.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
  86. sml.register_power_on_instance(tml)
  87. while (True):
  88. time.sleep(1)