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.temp_property = HomieNodeProperty( id="temperature", name="Temperature", datatype="float", format="-40:80", unit="°C", ) self.add_property(self.temp_property) self.hum_property = HomieNodeProperty( id="humidity", name="Humidity", datatype="float", format="0:100", unit="%", ) self.add_property(self.hum_property) loop = get_event_loop() loop.create_task(self.update_data())
def __init__(self, pin=5, leds=60): super().__init__( id="ambientlight", name="Ambient Light", type="WS2812B" ) self.np = neopixel.NeoPixel(Pin(pin), leds) self.light_property = HomieNodeProperty( id="power", name="Ambient Light Power", settable=True, retained=True, restore=True, datatype="boolean", default=FALSE, ) self.add_property(self.light_property) self.color_property = HomieNodeProperty( id="color", name="RGB Color", settable=True, retained=True, restore=True, datatype="rgb", default=b"254,128,40", ) self.add_property(self.color_property)
def __init__(self, name="bme280", device=None): super().__init__(id="bme280", name=name, type="sensor") self.device = device self.i2c = I2C(scl=Pin(5), sda=Pin(4)) self.bme280 = BME280(i2c=self.i2c) self.temperature = HomieNodeProperty( id="temperature", name="temperature", unit="°C", settable=False, datatype=FLOAT, default=0, ) self.add_property(self.temperature) self.humidity = HomieNodeProperty( id="humidity", name="humidity", unit="%", settable=False, datatype=FLOAT, default=0, ) self.add_property(self.humidity) self.pressure = HomieNodeProperty( id="pressure", name="pressure", unit="Pa", settable=False, datatype=FLOAT, default=0, ) self.add_property(self.pressure) self.uptime = HomieNodeProperty( id="uptime", name="uptime", settable=False, datatype=STRING, default="PT0S" ) self.add_property(self.uptime) self.ip = HomieNodeProperty( id="ip", name="ip", settable=False, datatype=STRING, default="", ) self.add_property(self.ip) self.led = Pin(0, Pin.OUT) self.online_led = Pin(12, Pin.OUT) self.online_led.off() self.last_online = time.time() self.start = time.time() print("start time", self.start) loop = get_event_loop() loop.create_task(self.update_data())
def __init__(self, pin=5, leds=3): super().__init__(id="light", name="Ambient Light", type="WS2812B") self._brightness = 53 self.np = neopixel.NeoPixel(Pin(pin), leds) self.power_property = HomieNodeProperty( id="power", name="Light power", settable=True, retained=True, restore=True, datatype=BOOLEAN, default=FALSE, ) self.add_property(self.power_property, self.on_power_msg) self.color_property = HomieNodeProperty( id="color", name="RGB Color", settable=True, retained=True, restore=True, datatype=COLOR, default=DEFAULT, format=RGB, ) self.add_property(self.color_property, self.on_color_msg) self.brightness_property = HomieNodeProperty( id="brightness", name="LED brightness", settable=True, retained=True, restore=True, datatype=ENUM, format="1,2,3,4,5,6,7,8", default=4, ) self.add_property(self.brightness_property, self.on_brightness_msg)
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.active = True self.pir_property = HomieNodeProperty( id="active", name="PIR Status", settable=True, datatype="boolean", restore=True, default=TRUE, )
def __init__(self, name="k30", device=None): super().__init__(id="k30", name=name, type="sensor") self.device = device self.co2 = HomieNodeProperty( id="co2", name="co2", unit="ppm", settable=False, datatype=FLOAT, default=0, ) self.add_property(self.co2) self.uptime = HomieNodeProperty(id="uptime", name="uptime", settable=False, datatype=STRING, default="PT0S") self.add_property(self.uptime) loop = get_event_loop() loop.create_task(self.update_data()) loop.create_task(self.reset()) self.led = Pin(0, Pin.OUT) self.start = time.time() self.last_onine = 0
def __init__(self, name="Onboard LED", pin=2): super().__init__(id="led", name=name, type="LED") self.pin = pin self.led = Pin(pin, Pin.OUT, value=0) self.btn = Pushbutton(Pin(0, Pin.IN, Pin.PULL_UP)) self.btn.press_func(self.toggle_led) self.power_property = HomieNodeProperty( id="power", name="LED Power", settable=True, datatype=BOOLEAN, default=TRUE, ) self.add_property(self.power_property, self.on_power_msg)
def __init__(self, name="Device LED", pin=2): super().__init__(id="led", name=name, type="LED") self.pin = pin self.led = Pin(pin, Pin.OUT, value=0) self.led_property = HomieNodeProperty( id="power", name="LED", settable=True, datatype="enum", format="true,false,toggle", restore=True, default=TRUE, ) self.add_property(self.led_property)
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.power_property = HomieNodeProperty( id=id, name="Power", settable=True, datatype=BOOLEAN, default=FALSE, ) self.add_property(self.power_property, self.on_power_msg) self.switch.open_func(self.toggle, ()) self.switch.close_func(self.toggle, ())
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.response_property = HomieNodeProperty(id="response", name="HTTP response") self.add_property(self.response_property) loop = get_event_loop() loop.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.relay_property = HomieNodeProperty( id="power", name=id, settable=True, retained=True, datatype="boolean", default=FALSE, restore=True, ) self.add_property(self.relay_property) self.switch.open_func(self.toggle, ()) self.switch.close_func(self.toggle, ())
def __init__(self): super().__init__(id="relay", name="Relay Board", type="relayboard") self.relais = [ Pin(2, Pin.OUT), Pin(4, Pin.OUT), ] self.relay_property = HomieNodeProperty( id="power", name="Relay", settable=True, retained=True, datatype="bool", default=TRUE, restore=True, range=2, ) self.add_property(self.relay_property)
def addProperty(self, id=None, name=None, unit=None, datatype=None, format=None, retained=True): if not id: logger.error("'id' required for HomieNodeProperty") return if id not in self.properties: homieNodeProperty = HomieNodeProperty(self, id, name, unit, datatype, format, retained) homieNodeProperty.setSubscribe(self.homie.subscribeProperty) if homieNodeProperty: self.properties[id] = homieNodeProperty return homieNodeProperty else: logger.warning("Property '{}' already created.".format(id)) return self.properties[id]
def __init__(self): super().__init__(id="relay", name="Relay 16A", type="Gosund SP1 v23") uos.dupterm(None, 1) # disable REPL so we can use the blue led self.led_b = Pin(1, Pin.OUT, value=1) self.led_r = Pin(13, Pin.OUT, value=1) self.relay = Pin(14, Pin.OUT) self.relay_property = HomieNodeProperty( id="power", name="Relay", settable=True, retained=True, datatype="boolean", default=FALSE, restore=True, ) self.add_property(self.relay_property) self.button = Pushbutton(Pin(3, Pin.IN)) self.button.release_func(self.toggle, ()) self.button.long_func(reset, (self.led_r,))
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.relay_property = HomieNodeProperty( id="power", name="Relay", settable=True, retained=True, datatype="bool", default=FALSE, restore=True, ) self.add_property(self.relay_property) 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.power_property = HomieNodeProperty( id="power", name="Power", settable=True, datatype=BOOLEAN, default=FALSE, ) self.add_property(self.power_property, self.on_power_msg) self.button = Pushbutton(Pin(3, Pin.IN)) self.button.release_func(self.toggle, ()) self.button.long_func(reset, (self.led_r,))
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.temperature = 0 self.interval = interval self.temp_property = HomieNodeProperty( id="temperature", name="Temperature", datatype="float", format="-40:80", unit="°F", ) self.add_property(self.temp_property) loop = get_event_loop() loop.create_task(self.update_data())