Ejemplo n.º 1
0
    def run(self, hub):
        if hub.water:
            status_led.slow_blink()
        else:
            status_led.off()

        if hasattr(self, 'mqtt'):
            self.mqtt.wait()
Ejemplo n.º 2
0
 def pub_state(_):
     status_led.on()
     self._sched = False
     counter.set_state(state.count)
     if config.BATT:
         battery.set_state(state.battery)
         counter.set_attr('battery', state.battery)
     state.set(mqtt=self.mqtt.pub_state())
     status_led.off()
 def rotate(self, valve_open):
     ## TODO: Use timer to turn off motor
     status_led.fast_blink()
     for i in range(1000): ## try for 10 sec
         if valve_open == (self.contact.value() == config.VALVE_OPEN_VAL):
             break
         self.motor.on()
         sleep_ms(10)
     self.motor.off()
     if valve_open:
         status_led.on()
     else:
         status_led.off()
 def run(self, state):
     print(wifi.uid())
     status_led.slow_blink()
     wifi.connect(secrets.WIFI_NAME, secrets.WIFI_PASSWORD)
     status_led.fast_blink()
     if reset_cause() == DEEPSLEEP_RESET:
         self.mqtt.do_pub_cfg = False
         self.mqtt.connect()
     else:
         self.mqtt.try_pub_cfg()
     self.pub_state(None)
     status_led.off()
     self.mqtt.wait(led=status_led)
Ejemplo n.º 5
0
    def __init__(self, state):
        print(wifi.uid())

        if reset_cause() != DEEPSLEEP_RESET:
            status_led.slow_blink()
        wifi.connect(secrets.WIFI_NAME, secrets.WIFI_PASSWORD)
        status_led.off()

        mqtt = MQTT(config.NAME, secrets, uid=UID)

        opt = dict(exp_aft=config.FREQ * 2.5)

        if 'temp' in state:
            from home_assistant.sensors.temperature import Temperature
            mqtt.add('Temp', Temperature, **opt).set_state(state['temp'])

        if 'humid' in state:
            from home_assistant.sensors.humidity import Humidity
            mqtt.add('Humid', Humidity, **opt).set_state(state['humid'])

        if 'lux' in state:
            from home_assistant.sensors.illuminance import Illuminance
            mqtt.add('Lux', Illuminance, **opt).set_state(state['lux'])

        if 'analog' in state:
            mqtt.add('Analog', Sensor, unit="%", icon="mdi:gauge",
                     **opt).set_state(state['analog'])

        if 'battery' in state:
            from home_assistant.sensors.battery import Battery
            mqtt.add('Battery', Battery, key='bat',
                     **opt).set_state(state['battery'])
            mqtt.set_attr('battery', state['battery'])

        mqtt.set_attr("freq", config.FREQ)

        if wifi.is_connected():
            if reset_cause() != DEEPSLEEP_RESET:
                status_led.fast_blink()
            mqtt.connect()
            sleep(1)
            mqtt.pub_state()
            status_led.off()
            sleep(5)
            mqtt.discon()
            sleep(5)
Ejemplo n.º 6
0
    def __init__(self, state):
        self.update_on = ('count', 'battery_level')

        print(wifi.uid())

        status_led.slow_blink()
        wifi.connect(secrets.WIFI_NAME, secrets.WIFI_PASSWORD)
        status_led.off()

        self.mqtt = MQTT(config.NAME, secrets)

        counter = self.mqtt.add(
            'Counter',
            Sensor,
            unit=config.UNIT,
            icon='mdi:counter',
        )

        if config.BATT:
            battery = self.mqtt.add('Battery', Battery)

        status_led.fast_blink()
        state.mqtt = self.mqtt.try_pub_cfg()
        status_led.off()

        self._sched = False

        def pub_state(_):
            status_led.on()
            self._sched = False
            counter.set_state(state.count)
            if config.BATT:
                battery.set_state(state.battery)
                counter.set_attr('battery', state.battery)
            state.set(mqtt=self.mqtt.pub_state())
            status_led.off()

        self.pub_state = pub_state
Ejemplo n.º 7
0
    def start(self, hub):
        if hub.internet:
            status_led.fast_blink()
            wifi.connect(secrets.WIFI_NAME, secrets.WIFI_PASSWORD)
            status_led.off()
            sleep(2)

            if wifi.is_connected():
                status_led.fast_blink()

                self.mqtt = MQTT(config.NAME, secrets, uid=UID)

                self.mqtt.add('Water',
                              Moisture,
                              prim=True,
                              key='water',
                              off_dly=config.NORMAL_SLEEP).set_state(hub.water)

                enable = self.mqtt.add('Enable', Switch, icon="mdi:bell")

                def enable_rx(msg):
                    hub.set(enable=msg == enable.ON)

                self.mqtt.sub(enable.cmd_tpc(), enable_rx)

                self.mqtt.add('Battery', Battery,
                              key='bat').set_state(hub.battery)

                self.mqtt.set_attr('battery', hub.battery)
                self.mqtt.set_attr('rssi', wifi.rssi())

                self.mqtt.do_pub_cfg = self.do_pub_cfg
                self.mqtt.connect()
                sleep(1)
                self.mqtt.pub_state()
                sleep(1)
                status_led.off()
 def __init__(self, state):
     self.update_on = ('pump')
     self.pin = Pin(config.PUMP_GPIO, mode=Pin.OUT)
     self.pin.value(config.PUMP_OFF)
     status_led.off()
 def update(self, state, changed):
     status_led.led.value(state.pump == config.PUMP_ON)
     status_led.on() if state.pump == config.PUMP_ON else status_led.off()
Ejemplo n.º 10
0
 def stop(self, hub):
     if hasattr(self, 'mqtt'):
         self.mqtt.discon()
     wifi.disconnect()
     status_led.off()