def main(): # Initialize the Homie device device = HomieDevice(settings) # Initialize the Homie node for the onboard LED led_node = HomieNode( id="led", name="Onboard LED", type="LED", ) # Initialize the Homie property to power on/off the led led_power = HomieProperty( id="power", name="Power", settable=True, datatype=BOOLEAN, default=FALSE, on_message=toggle_led, ) # Add the power property to the node led_node.add_property(led_power) # Add the led node to the device device.add_node(led_node) # Run device.run_forever()
def __init__(self, name="Temp & Humid", pin=4, interval=60, pull=-1): super().__init__(id="dht22", name=name, type="dht22") self.dht22 = dht.DHT22(Pin(pin, Pin.IN, pull)) self.interval = interval self.p_temp = HomieProperty( id="temperature", name="Temperature", datatype=FLOAT, format="-40:80", unit="°C", ) self.add_property(self.p_temp) self.p_humid = HomieProperty( id="humidity", name="Humidity", datatype=FLOAT, format="0:100", unit="%", ) self.add_property(self.p_humid) asyncio.create_task(self.update_data())
def __init__(self, pin, leds): super().__init__(id="light", name="Ambient Light", type="WS2812B") self._np = neopixel.NeoPixel(Pin(pin), leds) self._brightness = 53 self.p_power = HomieProperty( id="power", name="Power", settable=True, datatype=BOOLEAN, default=FALSE, on_message=self.on_power_msg, ) self.add_property(self.p_power) self.p_color = HomieProperty( id="color", name="RGB Color", settable=True, datatype=COLOR, default=DEFAULT, format=RGB, on_message=self.on_color_msg, ) self.add_property(self.p_color) self.p_brightness = HomieProperty( id="brightness", name="Brightness", settable=True, datatype=ENUM, format="1,2,3,4,5,6,7,8", default=4, on_message=self.on_brightness_msg, ) self.add_property(self.p_brightness)
def __init__(self, name="Motion sensor", pin=4): super().__init__(id="pir", name=name, type="PIR") self.pir = Pin(pin, Pin.IN, pull=Pin.PULL_UP) self.task = None self.p_active = HomieProperty( id="active", name="PIR Status", settable=True, datatype=BOOLEAN, restore=True, default=TRUE, on_message=self.on_active_msg, ) self.add_property(self.active)
def __init__( self, id, name, bmp280, interval=60*5): super().__init__(id=id, name=name, type="sensor", interval=interval) # BMP280 self.bmp280 = bmp280 self.property_temerature = HomieProperty( id="temperature", name="Temperatur", datatype=FLOAT, unit="°C", ) self.add_property(self.property_temerature) self.property_pressure = HomieProperty( id="pressure", name="Druck", datatype=FLOAT, unit="Pa", ) self.add_property(self.property_pressure)
def __init__(self, url, headers={}, method="GET", name="HTTP request", interval=60): super().__init__(id="http", name=name, type="http") self.url = url self.headers = headers self.method = method self.interval = interval self.p_response = HomieProperty(id="response", name="HTTP response") self.add_property(self.p_response) asyncio.create_task(self.update_data())
def __init__(self, id, rpin, swpin, name="Light Switch", type="Shelly"): super().__init__(id=id, name=name, type=type) self.relay = Pin(rpin, Pin.OUT, value=0) self.switch = Switch(Pin(swpin, Pin.IN)) self.p_power = HomieProperty( id=id, name="Power", settable=True, datatype=BOOLEAN, default=FALSE, ) self.add_property(self.p_power, self.on_power_msg) self.switch.open_func(self.toggle, ()) self.switch.close_func(self.toggle, ())
def __init__(self, name="Onboard LED", pin=0): super().__init__(id="led", name=name, type="LED") self.led = Pin(pin, Pin.OUT, value=1) # Boot button on some dev boards self.btn = Pushbutton(Pin(pin, Pin.IN, Pin.PULL_UP)) self.btn.press_func(self.toggle_led) self.p_power = HomieProperty( id="power", name="LED Power", settable=True, datatype=BOOLEAN, default=FALSE, on_message=self.on_power_msg, ) self.add_property(self.p_power)
def __init__(self, id, name, type, interval=60 * 5, interval_short=0.1): super().__init__(id=id, name=name, type=type) self.interval_changed = False self.interval_short = interval_short # Update Interval self._interval = interval self.property_interval = HomieProperty( id="update_interval", name="Aktualisierungsrate", datatype=FLOAT, # TODO ISO8601 settable=True, on_message=self._set_interval, unit="s", ) self.add_property(self.property_interval) asyncio.create_task(self._update_data_async())
def __init__(self, name="One Wire DS18B20", pin=12, interval=10, pull=-1): super().__init__(id="ds18b20", name=name, type="ds18b20") self.ds18b20 = DS18X20(OneWire(Pin(pin))) addrs = self.ds18b20.scan() if not addrs: raise Exception("no DS18B20 found at bus on pin %d" % pin) # save what should be the only address found self.addr = addrs.pop() self.interval = interval self.p_temp = HomieProperty( id="temperature", name="Temperature", datatype=FLOAT, format="-40:80", unit="°F", default=0, ) self.add_property(self.p_temp) asyncio.create_task(self.update_data())
def __init__(self): super().__init__(id="relay", name="Wifi Power Socket", type="OW8266-02Q") self.led = Pin(4, Pin.OUT, value=1) self.r_on = Pin(12, Pin.OUT) self.r_off = Pin(5, Pin.OUT) self.p_power = HomieProperty( id="power", name="Relay", settable=True, retained=True, datatype=BOOLEAN, default=FALSE, restore=True, on_message=self.on_power_msg, ) self.add_property(self.p_power) self.button = Pushbutton(Pin(14, Pin.IN, Pin.PULL_UP)) self.button.release_func(self.toggle, ()) self.button.long_func(reset, (self.led, ))
def __init__(self, name="Relay 16A"): super().__init__(id="relay", name=name, type="Gosund SP1") # disable REPL so we can use the blue led uos.dupterm(None, 1) self.led_b = Pin(1, Pin.OUT, value=1) # Blue LED self.led_r = Pin(13, Pin.OUT, value=1) # Red LED self.relay = Pin(14, Pin.OUT) self.p_power = HomieProperty( id="power", name="Power", settable=True, datatype=BOOLEAN, default=FALSE, on_message=self.on_power_msg, ) self.add_property(self.p_power) self.button = Pushbutton(Pin(3, Pin.IN)) self.button.release_func(self.toggle, ()) self.button.long_func(reset, (self.led_r, ))
def __init__(self, id, name, pin_up, pin_down, leds): super().__init__(id=id, name=name, type="colorlight") pin_up.init(mode=Pin.IN, pull=Pin.PULL_UP) pin_down.init(mode=Pin.IN, pull=Pin.PULL_UP) button_up = Pushbutton(pin_up, suppress=True, sense=1) button_down = Pushbutton(pin_down, suppress=True, sense=1) self.buttons = (button_up, button_down) self.on_buttons_pressed = [None, None] self.on_buttons_released = [None, None] self.leds = leds self.properties_button_pressed = [None, None] for i, button_name in enumerate(self.button_names): self.properties_button_pressed[i] = HomieProperty( id="button_{0}_pressed".format(button_name), name="Knöpgen \"{0}\" gedrückt".format(button_name), settable=True, default=FALSE, on_message=self._on_button_pressed_msg, datatype=BOOLEAN, ) self.add_property(self.properties_button_pressed[i]) self.buttons[i].press_func(self._on_buttons_pressed, args=(i, )) self.buttons[i].release_func(self._on_buttons_released, args=(i, )) self._power = False self.property_power = HomieProperty( id="power", name="Power", settable=True, datatype=BOOLEAN, default=FALSE, on_message=self.on_power_msg, ) self.add_property(self.property_power) self.brightness = 0.7 self.property_brightness = HomieProperty( id="brightness", name="Helligkeit", settable=True, datatype=FLOAT, default=70, format="0:100", unit="%", on_message=self.on_brightness_msg, ) self.add_property(self.property_brightness) self.anims = dict([(a.name, (a, i + 1)) for i, a in enumerate(ANIMS)]) self._animation_num = 0 self._animation = None self.property_animation = HomieProperty( id="animation", name="Animation", settable=True, datatype=ENUM, format=",".join(["-"] + list(self.anims.keys())), default="-", on_message=self.on_change_anim_msg, ) self.add_property(self.property_animation) self.color = (0, 0, 0) self.property_color = HomieProperty( id="color", name="Solide Farbe", settable=True, datatype=COLOR, format=RGB, default="0,0,0", on_message=self.on_change_color_msg, ) self.add_property(self.property_color) self.change = False asyncio.create_task(self._update_data_async())
def __init__( self, id, name, watering_motor, moisture_sensor, pin_water_tank, waterlevel_sensor, interval=60*5, interval_watering=0.2): super().__init__( id=id, name=name, type="watering", interval=interval, interval_short=interval_watering) # Update Interval self.interval_normal = interval self.interval_watering = interval_watering # WaterLevelSensor self.waterlevel_sensor = waterlevel_sensor self.property_waterlevel = HomieProperty( id="waterlevel", name="Wassertankstand", datatype=FLOAT, unit="L", ) self.add_property(self.property_waterlevel) self.property_waterlevel_percent = HomieProperty( id="waterlevel_percent", name="Wassertankstand [%]", datatype=FLOAT, format="0.00:100.00", unit="%", ) self.add_property(self.property_waterlevel_percent) self.property_waterlevel_volume_liter = HomieProperty( id="waterlevel_volume_max", name="Wassertankgröße", settable=True, datatype=FLOAT, unit="L", on_message=self._set_waterlevel_volume ) self.add_property(self.property_waterlevel_volume_liter) # Moisture self.moisture_sensor = moisture_sensor self.property_moisture = HomieProperty( id="moisture", name="Feuchte", datatype=FLOAT, format="0.00:100.00", unit="%", ) self.add_property(self.property_moisture) # Watering Motor self.watering_motor = watering_motor self.watering_motor.add_motor_stop_callback( self.on_watering_motor_stop) self.watering_motor.add_motor_start_callback( self.on_watering_motor_start) self.property_watering_power = HomieProperty( id="power", name="Bewässerung", settable=True, datatype=BOOLEAN, default=FALSE, on_message=self.toggle_motor, ) self.add_property(self.property_watering_power) self.property_watering_max_duration = HomieProperty( id="watering_duration", name="Bewässerungszeit", settable=True, datatype=FLOAT, default=3, on_message=lambda t, p, r: self.watering_motor.set_watering_duration(float(p)), unit="s", ) self.add_property(self.property_watering_max_duration)