Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide basic implementation examples #186

Open
bkanuka opened this issue Dec 1, 2019 · 7 comments
Open

Provide basic implementation examples #186

bkanuka opened this issue Dec 1, 2019 · 7 comments

Comments

@bkanuka
Copy link

bkanuka commented Dec 1, 2019

I would love to see some small sample programs that implement the Homie spec in different languages. For example a sample project that shows a Homie device implemented in Python + Paho MQTT. The same small program written in Node, etc.

I would imagine this as a totally seperate "examples" repository under the homieiot group on github with a directory for each language. I don't mean just a list of libraries (this exists already), rather a "from scratch" implementation of the spec. This would help a lot of people (like myself...) who learn better from examples, and could also serve as a prototype for developing Homie-compliant programs.

@davidgraeff
Copy link
Member

True. Would be nice having some simple examples.

@mjcumming
Copy link
Contributor

Here is a simple python example using the homie4 library


import time

from homie.device_dimmer import Device_Dimmer

import logging

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)



mqtt_settings = {
    "MQTT_BROKER": "OpenHAB",
    "MQTT_PORT": 1883,
}


class My_Dimmer(Device_Dimmer):
    def set_dimmer(self, percent):
        print(
            "Received MQTT message to set the dimmer to {}. Must replace this method".format(
                percent
            )
        )
        super().set_dimmer(percent)


try:

    dimmer = My_Dimmer(
        name="Test Dimmer", device_id="testdimmer", mqtt_settings=mqtt_settings
    )

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

except (KeyboardInterrupt, SystemExit):
    print("Quitting.")
    dimmer.close()

@rroemhild
Copy link
Contributor

Here a simple MicroPython LED example with Microhomie: https://github.com/microhomie/microhomie/blob/master/examples/led/main.py

We have more examples in the example directory.

@ThomDietrich
Copy link
Collaborator

Might also be related: #51

@2bndy5
Copy link

2bndy5 commented Aug 16, 2020

+1 for an example. Though I'm hoping for something more like a library-agnostic flowchart. The list of libraries are helpful, but their APIs tend to differ which makes interpreting the specs harder.

@bggardner
Copy link

Since the OP requested an example with Python + Paho MQTT, I just rewrote my Python module and the README has an example: https://github.com/bggardner/pyhomie

@2bndy5
Copy link

2bndy5 commented Jan 19, 2024

I have since wrote/published the Circuitpython_Home library. In its docs, I detail the Homie topology in comparison to equivalent representations of API and MQTT topics.

FYI it also works with paho-mqtt as adafruit_minimqtt was designed to be a minimal drop-in replacement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants