项目作者: mjcumming

项目描述 :
Homie V3 Implementation in Python
高级语言: Python
项目地址: git://github.com/mjcumming/HomieV3.git
创建时间: 2019-03-11T19:44:17Z
项目社区:https://github.com/mjcumming/HomieV3

开源协议:MIT License

下载


Use the Homie4 https://github.com/mjcumming/homie4 implementation. This library not actively being maintained.

Homie

Python implementation of Homie 3.0.1

Class based system to easily add Homie 3.0.1 support to devices.

Install

  1. pip install Homie3

EG. To create a dimmer device requires that a set_dimmer method be provided. When creating a device, all that is required is to provide the MQTT settings. All other requirements of the Homie specification are automatically handled.

  1. import time
  2. from homie.device_dimmer import Device_Dimmer
  3. mqtt_settings = {
  4. 'MQTT_BROKER' : 'QueenMQTT',
  5. 'MQTT_PORT' : 1883,
  6. }
  7. class My_Dimmer(Device_Dimmer):
  8. def set_dimmer(self,percent):
  9. print('Received MQTT message to set the dimmer to {}. Must replace this method'.format(percent))
  10. super().set_dimmer(percent)
  11. try:
  12. dimmer = My_Dimmer(name = 'Test Dimmer',mqtt_settings=mqtt_settings)
  13. while True:
  14. dimmer.update_dimmer(0)
  15. time.sleep(5)
  16. dimmer.update_dimmer(50)
  17. time.sleep(5)
  18. dimmer.update_dimmer(100)
  19. time.sleep(5)
  20. except (KeyboardInterrupt, SystemExit):
  21. print("Quitting.")

If creating multiple homie devices, you can specify Homie to only use one MQTT connection. This can be an issue on devices with limited resources. For MQTT_SETTINGS add MQTT_SHARE_CLIENT: True.