homieiot / convention

🏡 The Homie Convention: a lightweight MQTT convention for the IoT
https://homieiot.github.io/
Other
715 stars 60 forks source link

common device profiles #161

Closed mjcumming closed 4 years ago

mjcumming commented 5 years ago

I have reviewed other posts on this. I think it would be helpful if we defined some standard device profiles and how they should be setup. Ie. a switch, dimmer, contact, push button, etc.

I have put together a python library for 3.0.1 that makes it very easy to add homie devices to any existing code. Its a WIP but would be interested in any feedback. I have made several assumptions about common device profiles in this library - it would be good to have a discussion about best practices. Ie. should a switch be a boolean or should it be an enum with on,off values?

https://github.com/mjcumming/HomieV3



from homie.device_dimmer import Device_Dimmer

mqtt_settings = {
    'MQTT_BROKER' : 'QueenMQTT',
    'MQTT_PORT' : 1883,
}

class My_Dimmer(Device_Dimmer):

    def set_value(self,topic,payload):
        print('Received MQTT message to set the dimmer to {}. Must replace this method'.format(payload))

try:

    dimmer = My_Dimmer(name = 'Test Dimmer',mqtt_settings=mqtt_settings)

    while True:
        time.sleep(5)
        dimmer.update_dimmer(50)
        time.sleep(5)
        dimmer.update_dimmer(100)

except (KeyboardInterrupt, SystemExit):
    print("Quitting.")   ~~~
mjcumming commented 5 years ago

Library is now available on PyPi at https://pypi.org/project/Homie3/

Would appreciate any feedback... good or bad :)