How to use miio - 10 common examples

To help you get started, we’ve selected a few miio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ssut / make-mi-air-purifier-great-again / device.js View on Github external
async connect() {
    const address = this.ip;

    this.ref = await miio.device({ address });
    if (!this.ref.matches('type:air-purifier')) {
      throw new Error(`Not an air purifier given: ${address}`);
    }

    // patch for usages
    this.ref.aqi = this.ref.pm2_5;

    return true;
  }
github seikan / homebridge-mi-air-purifier / index.js View on Github external
discover: function() {
        var log = this.log;
        var that = this;

        miio.device({
                address: this.ip,
                token: this.token
            })
            .then(device => {
                if (device.matches('type:air-purifier')) {
                    that.device = device;
                    console.log('Discovered Mi Air Purifier (%s) at %s', device.miioModel, this.ip);

                    log.debug('Model       : ' + device.miioModel);
                    log.debug('Power       : ' + device.property('power'));
                    log.debug('Mode        : ' + device.property('mode'));
                    log.debug('Temperature : ' + device.property('temperature'));
                    log.debug('Humidity    : ' + device.property('humidity'));
                    log.debug('Air Quality : ' + device.property('aqi'));
                    log.debug('LED         : ' + device.property('led'));
github LASER-Yi / homebridge-mi-acpartner / lib / connectUtil.js View on Github external
_search(thisIp, thisToken, index) {
        if (!this.platform.syncLock._enterSyncState(() => {
            this._search(thisIp, thisToken, index);
        })) {
            return;
        }

        this.retryCount[index]++;
        //Try to connect to miio device
        this.log.info("[INFO]Device %s -> Connecting", thisIp);
        miio.device({
            address: thisIp,
            token: thisToken
        }).then((retDevice) => {
            this.platform.devices[index] = retDevice;
            this.log.info("[INFO]Device %s -> Connected", thisIp);
            this.platform.startEvent.emit(index);
        }).catch((err) => {
            this.log.error("[ERROR]Device %s -> %s", thisIp, err);
            setTimeout((() => {
                if (this.retryCount[index] <= 3) {
                    this._search(thisIp, thisToken, index);
                } else {
                    this.log.warn("[WARN]Cannot connect to device %s!", thisIp);
                    this.retryCount[index] = 0;
                }
            }), 30 * 1000);
github rench / homebridge-smarthome / kit / mijia / powerstrip.js View on Github external
browser.on('available', (reg) => {
      if (!reg.token) { //power strip support Auto-token
        return;
      }
      miio.device(reg).then((device) => {
        if (device.type != this.model) {
          return;
        }
        this.devices[reg.id] = device;
        this.mijia.log.debug('find model->%s with hostname->%s id->%s  @ %s:%s.', device.model, reg.hostname, device.id, device.address, device.port);
        this.setPowerStrip(reg, 0, device);
      });
    });
github rench / homebridge-smarthome / kit / mijia / yeelight.js View on Github external
browser.on('available', (reg) => {
      if (!reg.token) { //support Auto-token
        return;
      }
      miio.device(reg).then((device) => {
        this.devices[reg.id] = device;
        this.mijia.log.debug('find model->%s with hostname->%s id->%s  @ %s:%s.', device.model, reg.hostname, device.id, device.address, device.port);
        this.setLightbulb(reg, device);
      });
    });
github rench / homebridge-smarthome / kit / mijia / airpurifier.js View on Github external
browser.on('available', (reg) => {
      if (!reg.token) { //airpurifier support Auto-token
        return;
      }
      miio.device(reg).then((device) => {
        if (device.type != this.model) {
          return;
        }
        this.devices[reg.id] = device;
        this.mijia.log.debug('find model->%s with hostname->%s id->%s  @ %s:%s.', device.model, reg.hostname, device.id, device.address, device.port);
        this.setAirPurifier(reg, device);
      });
    });
github LASER-Yi / homebridge-mi-acpartner / XiaoMiAcPartner.js View on Github external
//Init
    this.log = log;
    this.config = config;

    this.Accessory = Accessory;
    this.PlatformAccessory = PlatformAccessory;
    this.Service = Service;
    this.Characteristic = Characteristic;
    this.UUIDGen = UUIDGen;

    var that = this;
    
    if(null != this.config['ip'] && null != this.config['token']){
        this.device = 1;
        miio.device({ address: this.config['ip'], token: this.config['token'] })
            .then(function(device){
                that.device = device;
                that.log("[XiaoMiAcPartner][INFO]Discovered Device(Global)!");
            }).catch(function(err){
                that.log.error("[XiaoMiAcPartner][ERROR]Cannot connect to AC Partner. " + err);
            })
    }

    this.log.info("[XiaoMiAcPartner][INFO]Plugin start successful");
}
github jghaanstra / com.xiaomi-miio / drivers / mi-airpurifier / device.js View on Github external
createDevice() {
    miio.device({
      address: this.getSetting('address'),
      token: this.getSetting('token')
    }).then(miiodevice => {
      if (!this.getAvailable()) {
        this.setAvailable();
      }
      this.miio = miiodevice;

      var interval = this.getSetting('polling') || 60;
      this.pollDevice(interval);
    }).catch((error) => {
      this.log(error);
      this.setUnavailable(Homey.__('unreachable'));
      setTimeout(() => {
        this.createDevice();
      }, 10000);
github jghaanstra / com.xiaomi-miio / drivers / philips-bulb / device.js View on Github external
createDevice() {
    miio.device({
      address: this.getSetting('address'),
      token: this.getSetting('token')
    }).then(miiodevice => {
      if (!this.getAvailable()) {
        this.setAvailable();
      }
      this.miio = miiodevice;

      this.miio.on('colorChanged', c => {
        var colortemp = util.normalize(c.values[0], 3000, 5700);
        if (this.getCapabilityValue('light_temperature') != colortemp) {
          this.setCapabilityValue('light_temperature', colortemp);
        }
      });

      var interval = this.getSetting('polling') || 60;
github jghaanstra / com.xiaomi-miio / drivers / mi-power-strip / device.js View on Github external
createDevice() {
    miio.device({
      address: this.getSetting('address'),
      token: this.getSetting('token')
    }).then(miiodevice => {
      if (!this.getAvailable()) {
        this.setAvailable();
      }
      this.miio = miiodevice;

      var interval = this.getSetting('polling') || 30;
      this.pollDevice(interval);
    }).catch((error) => {
      this.log(error);
      this.setUnavailable(Homey.__('unreachable'));
      setTimeout(() => {
        this.createDevice();
      }, 10000);

miio

Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more

MIT
Latest version published 7 years ago

Package Health Score

42 / 100
Full package analysis

Popular miio functions