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

Support for AirPurifier 2H #6

Closed
dontobi opened this issue Jan 25, 2021 · 15 comments
Closed

Support for AirPurifier 2H #6

dontobi opened this issue Jan 25, 2021 · 15 comments

Comments

@dontobi
Copy link

dontobi commented Jan 25, 2021

I own an AirPurifier 2H and run it through the iobroker-miio adapter. I find your script very promising. I also plan to buy more MiHome devices, so I would like to switch to your script.

Unfortunately, the 2H does not yet work with your script and is rightly still on the status "in Progress".

I would therefore be happy to support you and provide you with all the necessary data. I will therefore start with a few logs and screenshots.

2021-01-25 08:07:46.166 - info: javascript.0 (11444) Start javascript script.js.common.mihome
2021-01-25 08:07:46.305 - info: javascript.0 (11444) script.js.common.mihome: Starting AllMyMi V.0.2.5
2021-01-25 08:07:46.306 - info: javascript.0 (11444) script.js.common.mihome: Reaching init
2021-01-25 08:07:46.355 - info: javascript.0 (11444) script.js.common.mihome: registered 0 subscriptions and 0 schedules
2021-01-25 08:07:48.269 - info: javascript.0 (11444) script.js.common.mihome: Retrieving your in de registered MiHome Devices
2021-01-25 08:07:48.405 - info: javascript.0 (11444) script.js.common.mihome: Found 1 MiHome Devices, those are:
2021-01-25 08:07:48.405 - info: javascript.0 (11444) script.js.common.mihome: Mi Luftreiniger 2H
2021-01-25 08:07:48.407 - info: javascript.0 (11444) script.js.common.mihome: Now searching for supported Devices...
2021-01-25 08:07:48.407 - info: javascript.0 (11444) script.js.common.mihome: Device Mi Luftreiniger 2H is supported, creating DataPoints
2021-01-25 08:07:48.408 - info: javascript.0 (11444) script.js.common.mihome: Reaching PrepareDeviceDps, did=314913106 model=zhimi.airpurifier.mc2
2021-01-25 08:07:48.409 - info: javascript.0 (11444) script.js.common.mihome: Reaching CreateStates()
2021-01-25 08:07:48.745 - info: javascript.0 (11444) script.js.common.mihome: 20 States created, now setting up channels!
2021-01-25 08:07:48.747 - info: javascript.0 (11444) script.js.common.mihome: Reaching main
2021-01-25 08:07:48.747 - info: javascript.0 (11444) script.js.common.mihome: Reaching WriteGenericDpValues()
2021-01-25 08:07:48.749 - info: javascript.0 (11444) script.js.common.mihome: Reaching CreateDevices
2021-01-25 08:07:48.749 - info: javascript.0 (11444) script.js.common.mihome: Now creating device for zhimi.airpurifier.mc2 / 314913106 / 192.168.0.37 / f5928f188fc3b791f0c0c31caace5dee / 10000
2021-01-25 08:07:48.751 - info: javascript.0 (11444) script.js.common.mihome: Created device {"_events":{},"_eventsCount":0,"_maxListeners":100,"id":"314913106","address":"192.168.0.37","token":"f5928f188fc3b791f0c0c31caace5dee","protocol":"local","refresh":10000,"_properties":{},"_propertiesToMonitor":["air-purifier:fault","air-purifier:on","air-purifier:fan-level","air-purifier:mode","environment:pm2.5-density","environment:relative-humidity","environment:temperature","filter:filter-life-level","alarm:alarm","indicator-light:brightness","indicator-light:on","physical-controls-locked:physical-controls-locked"],"_miotSpec":null,"_miotSpecType":"urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-mc2:1","model":"zhimi.airpurifier.mc2","setter":{},"definition":{"info":[{"id":"localip","initial":"","forceCreation":false,"common":{"read":true,"write":true,"name":"Ip Adress","type":"string","role":"value","def":""}},{"id":"token","initial":"","forceCreation":false,"common":{"read":true,"write":true,"name":"Token","type":"string","role":"value","def":""}},{"id":"did","initial":"","forceCreation":false,"common":{"read":true,"write":true,"name":"Device Id","type":"string","role":"value","def":""}},{"id":"model","initial":"","forceCreation":false,"common":{"read":true,"write":true,"name":"Model","type":"string","role":"value","def":""}},{"id":"rssi","initial":0,"forceCreation":false,"common":{"read":true,"write":false,"name":"rssi","type":"number","role":"value.rssi","def":0}},{"id":"name","initial":"","forceCreation":false,"common":{"read":true,"write":true,"name":"Name","type":"string","role":"value","def":""}},{"id":"isOnline","initial":false,"forceCreation":false,"common":{"read":true,"write":true,"name":"Is online","type":"boolean","role":"value","def":false}}],"model":"zhimi.airpurifier.mc2","description":"Purifier 2H","setter":{},"common":[{"name":"air-purifier.on","format":"boolean","read":true,"write":true,"min":false,"max":true,"role":"state","type":"mixed"},{"name":"air-purifier.fault","format":"number","read":true,"write":false,"min":0,"max":5,"states":{"0":"No faults","1":"m1_run","2":"m1_stuck","3":"no_sensor","4":"error_hum","5":"error_temp"},"role":"state","type":"mixed"},{"name":"air-purifier.mode","format":"number","read":true,"write":true,"min":0,"max":3,"states":{"0":"auto","1":"sleep","2":"favorite"},"role":"state","type":"mixed"},{"name":"air-purifier.fan-level","format":"number","read":true,"write":true,"min":1,"max":3,"role":"state","type":"mixed"},{"name":"alarm.alarm","format":"boolean","read":true,"write":true,"min":false,"max":true,"role":"state","type":"mixed"},{"name":"indicator-light.brightness","format":"number","read":true,"write":true,"min":0,"max":2,"role":"state","type":"mixed"},{"name":"indicator-light.on","format":"boolean","read":true,"write":true,"min":false,"max":true,"role":"state","type":"mixed"},{"name":"environment.temperature","format":"number","read":true,"write":false,"min":-40,"max":125,"unit":"°C","role":"state","type":"mixed"},{"name":"environment.relative-humidity","format":"number","read":true,"write":false,"min":0,"max":100,"unit":"%","role":"state","type":"mixed"},{"name":"environment.pm2_5-density","format":"number","read":true,"write":false,"min":0,"max":600,"role":"state","type":"mixed"},{"name":"filter.filter-life-level","format":"number","read":true,"write":false,"min":0,"max":100,"unit":"%","role":"state","type":"mixed"},{"name":"filter.filter-used-time","format":"number","read":true,"write":false,"unit":"h","role":"state","type":"mixed"},{"name":"physical-controls-locked.physical-controls-locked","format":"boolean","read":true,"write":true,"min":false,"max":true,"role":"state","type":"mixed"}]}} now fetching data
2021-01-25 08:07:49.200 - info: javascript.0 (11444) script.js.common.mihome: Init Device# 0 - device="zhimi.airpurifier.mc2"
2021-01-25 08:07:49.200 - info: javascript.0 (11444) script.js.common.mihome: Setting trigger #0 for zhimi.airpurifier.mc2
2021-01-25 08:07:49.202 - info: javascript.0 (11444) script.js.common.mihome: Reaching CreateDpTrigger
2021-01-25 08:07:49.202 - info: javascript.0 (11444) script.js.common.mihome: Setting DataPointTrigger #0 for zhimi.airpurifier.mc2
2021-01-25 08:07:49.203 - info: javascript.0 (11444) script.js.common.mihome: Setting Datapoint Trigger for javascript.0.MiHome.314913106.air-purifier.on / read=true write=true
2021-01-25 08:07:49.204 - info: javascript.0 (11444) script.js.common.mihome: No Datapoint Trigger set for air-purifier.fault because its readonly.
2021-01-25 08:07:49.205 - info: javascript.0 (11444) script.js.common.mihome: Setting Datapoint Trigger for javascript.0.MiHome.314913106.air-purifier.mode / read=true write=true
2021-01-25 08:07:49.205 - info: javascript.0 (11444) script.js.common.mihome: Setting Datapoint Trigger for javascript.0.MiHome.314913106.air-purifier.fan-level / read=true write=true
2021-01-25 08:07:49.206 - info: javascript.0 (11444) script.js.common.mihome: Setting Datapoint Trigger for javascript.0.MiHome.314913106.alarm.alarm / read=true write=true
2021-01-25 08:07:49.207 - info: javascript.0 (11444) script.js.common.mihome: Setting Datapoint Trigger for javascript.0.MiHome.314913106.indicator-light.brightness / read=true write=true
2021-01-25 08:07:49.207 - info: javascript.0 (11444) script.js.common.mihome: Setting Datapoint Trigger for javascript.0.MiHome.314913106.indicator-light.on / read=true write=true
2021-01-25 08:07:49.208 - info: javascript.0 (11444) script.js.common.mihome: No Datapoint Trigger set for environment.temperature because its readonly.
2021-01-25 08:07:49.209 - info: javascript.0 (11444) script.js.common.mihome: No Datapoint Trigger set for environment.relative-humidity because its readonly.
2021-01-25 08:07:49.209 - info: javascript.0 (11444) script.js.common.mihome: No Datapoint Trigger set for environment.pm2_5-density because its readonly.
2021-01-25 08:07:49.211 - info: javascript.0 (11444) script.js.common.mihome: No Datapoint Trigger set for filter.filter-life-level because its readonly.
2021-01-25 08:07:49.211 - info: javascript.0 (11444) script.js.common.mihome: No Datapoint Trigger set for filter.filter-used-time because its readonly.
2021-01-25 08:07:49.212 - info: javascript.0 (11444) script.js.common.mihome: Setting Datapoint Trigger for javascript.0.MiHome.314913106.physical-controls-locked.physical-controls-locked / read=true write=true
2021-01-25 08:13:34.183 - info: javascript.0 (11444) script.js.common.mihome: Triggered i=0 x=0 ack=false
2021-01-25 08:13:34.186 - info: javascript.0 (11444) script.js.common.mihome: Reaching SetDevice - i=0 key=0 keyvalue=true
2021-01-25 08:13:34.186 - info: javascript.0 (11444) script.js.common.mihome: Keyvalue=true key=0
2021-01-25 08:13:34.187 - info: javascript.0 (11444) script.js.common.mihome: Reaching SetDevice i=0
2021-01-25 08:13:34.196 - info: javascript.0 (11444) script.js.common.mihome: {}
2021-01-25 08:13:34.268 - error: javascript.0 (11444) An error happened which is most likely from one of your scripts, but the originating script could not be detected.
2021-01-25 08:13:34.269 - error: javascript.0 (11444) Error: Method not found.
2021-01-25 08:13:34.270 - error: javascript.0 (11444) Error: Method not found.
at Object.reject (/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-mihome/lib/protocol-miio.js:343:19)
at MiIOProtocol._onData (/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-mihome/lib/protocol-miio.js:239:11)
at MiIOProtocol._onMessage (/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-mihome/lib/protocol-miio.js:110:14)
at Socket. (/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-mihome/lib/protocol-miio.js:40:12)
at Socket.emit (events.js:314:20)
at UDP.onMessage (dgram.js:921:8)

image
image

@Pittini
Copy link
Owner

Pittini commented Jan 25, 2021

The 2H should work, but is completely untested. It was also recognized from the script I see, so, lets look where the errors come.
Take a look at "/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-mihome/lib/devices/" - is there a file called zhimi.airpurifier.mc2.js?
Take a look inside "/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-mihome/lib/devices/package.json"
Which version do you see in the third line?
What your JavaScript Adapter Version?
And please try the newest scriptversion 0.2.7

@dontobi
Copy link
Author

dontobi commented Jan 25, 2021

I have updated to version 0.2.7, however the function with the 2H is not yet given.

Here is the data you wanted.

  • zhimi.airpurifier.mc2.js is present
  • The version of node-mihome is 0.0.32

@Pittini
Copy link
Owner

Pittini commented Jan 25, 2021

You forgot one important answer: Whats your JavaScript Adapter Version?
and
What exactly you have done, while the error occurs. Seems you have tried to SET a value? Which one?

If you are an expirienced user, you can also take a look at #4
There you can see whats the way to determine whts not working

@dontobi
Copy link
Author

dontobi commented Jan 25, 2021

The JavaScript adapter is on version 4.10.13.

At the time of the error I tried to set the object "on" to true.

I'll take a look at your link and let you know if anything changes.

@dontobi
Copy link
Author

dontobi commented Jan 25, 2021

I tried a little more today. In the meantime, values are displayed and I can also switch the AirPurifier on and off. Only the temperature is not displayed correctly. This should be divided by 10, but it is not. Even changing the divisor to 100 did not change anything.

I have also added the units for some objects.

Maybe you can adjust the objects to the other AirPuriefiers (subfolders) and solve the temperature problem. I will test all other functions tomorrow and give feedback.

Attached are my changes.

Changes to the ioBroker script:

DefineDevice[8] = {  // in progress, untested
    info: {},
    model: "zhimi.airpurifier.mc2",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-mc2:1
    description: "Purifier 2H",
    setter: {
        "power": async function (obj, val) { await device[obj].setPower(val ? 'on' : 'off') },
        "mode": async function (obj, val) { await device[obj].setMode(val) },
        "favorite_level": async function (obj, val) { await device[obj].setFavoriteLevel(val) },
        "led": async function (obj, val) { await device[obj].setDisplay(val) },
        "led_b": async function (obj, val) { await device[obj].setLedB(val) },
        "buzzer": async function (obj, val) { await device[obj].setBuzzer(val) },
        "child_lock": async function (obj, val) { await device[obj].setChildLock(val ? 'on' : 'off') }
    },
    common:
        [{ name: "power", format: "boolean", read: true, write: true, min: false, max: true },
        { name: "mode", format: "string", read: true, write: true, states: { "auto": "auto", "silent": "silent", "favorite": "favorite" } },
        { name: "favorite_level", format: "number", read: true, write: false, min: 0, max: 16 },
        { name: "temp_dec", format: "number", read: true, write: false, min: -40, max: 125, unit: "°C" },
        { name: "humidity", format: "number", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "aqi", format: "number", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "average_aqi", format: "number", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "led", format: "boolean", read: true, write: true, min: false, max: true },
        { name: "led_b", format: "number", read: true, write: true, min: 0, max: 2, states: { 0: "bright", 1: "dim", 2: "off" } },
        { name: "buzzer", format: "boolean", read: true, write: true, min: false, max: true },
        { name: "filter1_life", format: "number", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "f1_hour", format: "number", read: true, write: false, unit: "h" },
        { name: "f1_hour_used", format: "number", read: true, write: false, unit: "h" },
        { name: "motor1_speed", format: "number", read: true, write: false, unit: "u/min" },
        { name: "child_lock", format: "boolean", read: true, write: true, min: false, max: true }]
};

File: zhimi.airpurifier.mc2.js

const Device = require('../device-miio');

module.exports = class extends Device {

  static model = 'zhimi.airpurifier.mc2';
  static name = 'Mi Air Purifier 2H';
  static image = 'https://static.home.mi.com/app/image/get/file/developer_15470144879uw2ei4h.png';

  constructor(opts) {
    super(opts);

    this._propertiesToMonitor = [
      'power',
      'mode',
      'favorite_level',
      'temp_dec',
      'humidity',
      'aqi',
      'average_aqi',
      'buzzer',
      'led',
      'led_b',
      'filter1_life',
      'f1_hour',
      'f1_hour_used',
      'motor1_speed',
      'child_lock',
    ];
  }

  getPower() {
    return this.properties['power'] === 'on';
  }

  getMode() {
    return this.properties['mode'];
  }

  getFavoriteLevel() {
    return this.properties['favorite_level'];
  }

  getTemperature() {
    return this.properties['temp_dec'] / 10;
  }

  getHumidity() {
    return this.properties['humidity'];
  }

  getPM2_5() {
    return this.properties['aqi'];
  }

  getAveragePM2_5() {
    return this.properties['average_aqi'];
  }

  getLed() {
    return this.properties['led'] === 'on';
  }

  getLedB() {
    return this.properties['led_b'];
  }

  getBuzzer() {
    return this.properties['buzzer'] === 'on';
  }

  getFilterRemaining() {
    return this.properties['filter1_life'];
  }

  getFilterTotal() {
    return this.properties['f1_hour'];
  }

  getFilterUsed() {
    return this.properties['f1_hour_used'];
  }

  getMotorSpeed() {
    return this.properties['motor1_speed'];
  }

  getChildLock() {
    return this.properties['child_lock'] === 'on';
  }

  setPower(v) {
    return this.miioCall('set_power', [v ? 'on' : 'off']);
  }

  setMode(v) {
    return this.miioCall('set_mode', [v]);
  }

  setFavoriteLevel(v) {
    return this.miioCall('set_level_favorite', [v]);
  }

  setLed(v) {
    return this.miioCall('set_led', [v ? 'on' : 'off']);
  }

  setLedB(v) {
    return this.miioCall('set_led_b', [v]);
  }

  setBuzzer(v) {
    return this.miioCall('set_buzzer', [v]);
  }

  setChildLock(v) {
    return this.miioCall('set_child_lock', [v ? 'on' : 'off']);
  }

};

@dontobi
Copy link
Author

dontobi commented Jan 26, 2021

I have just been able to test everything. The buzzer does not work. Neither the read out, nor the set. I'll have to check again when I have time.
In addition, the setting of the favoritelevels had not worked. But I could fix that.

Here is the current state.

DefineDevice[8] = {  // in progress, untested
    info: {},
    model: "zhimi.airpurifier.mc2",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-mc2:1
    description: "Purifier 2H",
    setter: {
        "power": async function (obj, val) { await device[obj].setPower(val ? 'on' : 'off') },
        "mode": async function (obj, val) { await device[obj].setMode(val) },
        "favorite_level": async function (obj, val) { await device[obj].setFavoriteLevel(val) },
        "led": async function (obj, val) { await device[obj].setDisplay(val) },
        "led_b": async function (obj, val) { await device[obj].setLedB(val) },
        "buzzer": async function (obj, val) { await device[obj].setBuzzer(val) },
        "child_lock": async function (obj, val) { await device[obj].setChildLock(val ? 'on' : 'off') }
    },
    common:
        [{ name: "power", format: "boolean", read: true, write: true, min: false, max: true },
        { name: "mode", format: "string", read: true, write: true, states: { "auto": "auto", "silent": "silent", "favorite": "favorite" } },
        { name: "favorite_level", format: "number", read: true, write: true, min: 0, max: 16 },
        { name: "temp_dec", format: "number", read: true, write: false, min: -40, max: 125, unit: "°C" },
        { name: "humidity", format: "number", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "aqi", format: "number", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "average_aqi", format: "number", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "led", format: "boolean", read: true, write: true, min: false, max: true },
        { name: "led_b", format: "number", read: true, write: true, min: 0, max: 2, states: { 0: "bright", 1: "dim", 2: "off" } },
        { name: "buzzer", format: "boolean", read: true, write: true, min: false, max: true },
        { name: "filter1_life", format: "number", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "f1_hour", format: "number", read: true, write: false, unit: "h" },
        { name: "f1_hour_used", format: "number", read: true, write: false, unit: "h" },
        { name: "motor1_speed", format: "number", read: true, write: false, unit: "u/min" },
        { name: "child_lock", format: "boolean", read: true, write: true, min: false, max: true }]
};
const Device = require('../device-miio');

module.exports = class extends Device {

  static model = 'zhimi.airpurifier.mc2';
  static name = 'Mi Air Purifier 2H';
  static image = 'https://static.home.mi.com/app/image/get/file/developer_15470144879uw2ei4h.png';

  constructor(opts) {
    super(opts);

    this._propertiesToMonitor = [
      'power',
      'mode',
      'favorite_level',
      'temp_dec',
      'humidity',
      'aqi',
      'average_aqi',
      'buzzer',
      'led',
      'led_b',
      'filter1_life',
      'f1_hour',
      'f1_hour_used',
      'motor1_speed',
      'child_lock',
    ];
  }

  getPower() {
    return this.properties['power'] === 'on';
  }

  getMode() {
    return this.properties['mode'];
  }

  getFavoriteLevel() {
    return this.properties['favorite_level'];
  }

  getTemperature() {
    return this.properties['temp_dec'] / 10;
  }

  getHumidity() {
    return this.properties['humidity'];
  }

  getPM2_5() {
    return this.properties['aqi'];
  }

  getAveragePM2_5() {
    return this.properties['average_aqi'];
  }

  getLed() {
    return this.properties['led'] === 'on';
  }

  getLedB() {
    return this.properties['led_b'];
  }

  getBuzzer() {
    return this.properties['buzzer'] === 'on';
  }

  getFilterRemaining() {
    return this.properties['filter1_life'];
  }

  getFilterTotal() {
    return this.properties['f1_hour'];
  }

  getFilterUsed() {
    return this.properties['f1_hour_used'];
  }

  getMotorSpeed() {
    return this.properties['motor1_speed'];
  }

  getChildLock() {
    return this.properties['child_lock'] === 'on';
  }

  setPower(v) {
    return this.miioCall('set_power', [v ? 'on' : 'off']);
  }

  setMode(v) {
    return this.miioCall('set_mode', [v]);
  }

  setFavoriteLevel(v) {
    return this.miioCall('set_level_favorite', [v]);
  }

  setLed(v) {
    return this.miioCall('set_led', [v ? 'on' : 'off']);
  }

  setLedB(v) {
    return this.miioCall('set_led_b', [v]);
  }

  setBuzzer(v) {
    return this.miioCall('set_buzzer', [v]);
  }

  setChildLock(v) {
    return this.miioCall('set_child_lock', [v ? 'on' : 'off']);
  }

};

@dontobi
Copy link
Author

dontobi commented Jan 26, 2021

The buzzer works now, too. Only the problem with the temperature remains. This is still displayed incorrectly. At 20.7°C, 207°C is displayed. Any idea how I can change this? Could compensate for this on ioBroker side, but that is not the purpose.

@dontobi
Copy link
Author

dontobi commented Jan 27, 2021

I have now tried several things to read out the temperature correctly. However, I have the assumption that it is not at node-mihome, but at the script. Maybe your script can't handle comma numbers?

The situation looks like this:
In the MiHome app the temperature is displayed as follows: 17.6°C.
In the object "temp_dec" that is read by your script it says: 176°C

Enclosed my attempts on sides of node-mihome.

Test #1

  getTemperature() {
    return this.properties['temp_dec'] / 10;
  }

Test #2

  getTemperature() {
    const temperature = this.properties['temp_dec'];
    if (temperature > 0) {
      return Math.abs(temperature / 10);
    }
    return undefined;
  }

Test #3

  getTemperature() {
    const temperature = this.properties['temp_dec'];
    if (temperature > 0) {
      return Math.round(Math.abs(temperature / 10));
    }
    return undefined;
  }

@Pittini
Copy link
Owner

Pittini commented Jan 27, 2021

The Skript dont uses all that get Commands, it uses the raw data defined in this._propertiesToMonitor. The shown value is crazy but correct. temp_dec means 10th of temp and this means its *10. I'll try to write a function to watch for this temp_dec and correct it then, wait for next version. Good work btw.!

@dontobi
Copy link
Author

dontobi commented Jan 27, 2021

I have also changed something in your script. You use format: "boolean" etc., I would solve it with type: "boolean" etc..

I also added units.

Attached is my current version:

DefineDevice[8] = {  // in progress
    info: {},
    model: "zhimi.airpurifier.mc2",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-mc2:1
    description: "Purifier 2H",
    setter: {
        "power": async function (obj, val) { await device[obj].setPower(val) },
        "mode": async function (obj, val) { await device[obj].setMode(val) },
        "favorite_level": async function (obj, val) { await device[obj].setFavoriteLevel(val) },
        "led": async function (obj, val) { await device[obj].setLed(val) },
        "led_b": async function (obj, val) { await device[obj].setLedB(val) },
        "buzzer": async function (obj, val) { await device[obj].setBuzzer(val) },
        "child_lock": async function (obj, val) { await device[obj].setChildLock(val) }
    },
    common:
        [{ name: "power", type: "boolean", role: "switch", read: true, write: true, min: false, max: true },
        { name: "mode", type: "string", role: "state", read: true, write: true, states: { "auto": "auto", "silent": "silent", "favorite": "favorite" } },
        { name: "favorite_level", type: "number", role: "state", read: true, write: true, min: 0, max: 16 },
        { name: "temp_dec", type: "number", role: "value.temperature", read: true, write: false, min: -40.0, max: 525.0, unit: "°C" },
        { name: "humidity", type: "number", role: "value.humidity", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "aqi", type: "number", role: "value", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "average_aqi", type: "number", role: "value", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "led", type: "boolean", role: "switch", read: true, write: true, min: false, max: true },
        { name: "led_b", type: "number", role: "state", read: true, write: true, min: 0, max: 2, states: { 0: "bright", 1: "dim", 2: "off" } },
        { name: "buzzer", type: "boolean", role: "switch", read: true, write: true, min: false, max: true },
        { name: "filter1_life", type: "number", role: "value", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "f1_hour", type: "number", role: "value", read: true, write: false, unit: "h" },
        { name: "f1_hour_used", type: "number", role: "value", read: true, write: false, unit: "h" },
        { name: "motor1_speed", type: "number", role: "value", read: true, write: false, unit: "u/min" },
        { name: "child_lock", type: "boolean", role: "switch", read: true, write: true, min: false, max: true }]
};
const Device = require('../device-miio');

module.exports = class extends Device {

  static model = 'zhimi.airpurifier.mc2';
  static name = 'Mi Air Purifier 2H';
  static image = 'https://static.home.mi.com/app/image/get/file/developer_15470144879uw2ei4h.png';

  constructor(opts) {
    super(opts);

    this._propertiesToMonitor = [
      'power',
      'mode',
      'favorite_level',
      'temp_dec',
      'humidity',
      'aqi',
      'average_aqi',
      'buzzer',
      'led',
      'led_b',
      'filter1_life',
      'f1_hour',
      'f1_hour_used',
      'motor1_speed',
      'child_lock',
    ];
  }

  getPower() {
    return this.properties['power'] === 'on';
  }

  getMode() {
    return this.properties['mode'];
  }

  getFavoriteLevel() {
    return this.properties['favorite_level'];
  }

  getTemperature() {
    return this.properties['temp_dec'] / 10;
  }

  getHumidity() {
    return this.properties['humidity'];
  }

  getPM2_5() {
    return this.properties['aqi'];
  }

  getAveragePM2_5() {
    return this.properties['average_aqi'];
  }

  getLed() {
    return this.properties['led'] === 'on';
  }

  getLedB() {
    return this.properties['led_b'];
  }

  getBuzzer() {
    return this.properties['buzzer'] === 'on';
  }

  getFilterRemaining() {
    return this.properties['filter1_life'];
  }

  getFilterTotal() {
    return this.properties['f1_hour'];
  }

  getFilterUsed() {
    return this.properties['f1_hour_used'];
  }

  getMotorSpeed() {
    return this.properties['motor1_speed'];
  }

  getChildLock() {
    return this.properties['child_lock'] === 'on';
  }

  setPower(v) {
    return this.miioCall('set_power', [v ? 'on' : 'off']);
  }

  setMode(v) {
    return this.miioCall('set_mode', [v]);
  }

  setFavoriteLevel(v) {
    return this.miioCall('set_level_favorite', [v]);
  }

  setLed(v) {
    return this.miioCall('set_led', [v ? 'on' : 'off']);
  }

  setLedB(v) {
    return this.miioCall('set_led_b', [v]);
  }

  setBuzzer(v) {
    return this.miioCall('set_buzzer', [v ? 'on' : 'off']);
  }

  setChildLock(v) {
    return this.miioCall('set_child_lock', [v ? 'on' : 'off']);
  }

};

@dontobi
Copy link
Author

dontobi commented Feb 1, 2021

What is the current status? Is there anything else I can do?

@Pittini
Copy link
Owner

Pittini commented Feb 1, 2021

If still everything works fine, nothing do to for you. I've integrated and modified the skript, and the next days make a pr to node-mihome.

@dontobi
Copy link
Author

dontobi commented Feb 1, 2021

Everything works for me so far, except for the problem with the temperature (instead of 17.6°C, 176°C is displayed).

@Pittini
Copy link
Owner

Pittini commented Feb 1, 2021

For the temp Problem there is an workaround in the new scriptversion, dont worry.

@dontobi
Copy link
Author

dontobi commented Feb 1, 2021

I just updated to version 0.2.8. The temperature is now displayed correctly. But I noticed one thing regarding the AirPurifier 2H. There are still changes to be made in the setter section. And the device is now Tested / Working!

DefineDevice[8] = {  // Tested and working
    info: {},
    model: "zhimi.airpurifier.mc2",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:air-purifier:0000A007:zhimi-mc2:1
    description: "Purifier 2H",
    setter: {
        "power": async function (obj, val) { await device[obj].setPower(val) },
        "mode": async function (obj, val) { await device[obj].setMode(val) },
        "favorite_level": async function (obj, val) { await device[obj].setFavoriteLevel(val) },
        "led": async function (obj, val) { await device[obj].setLed(val) },
        "led_b": async function (obj, val) { await device[obj].setLedB(val) },
        "buzzer": async function (obj, val) { await device[obj].setBuzzer(val) },
        "child_lock": async function (obj, val) { await device[obj].setChildLock(val) }
    },
    common:
        [{ name: "power", type: "boolean", role: "switch", read: true, write: true, min: false, max: true },
        { name: "mode", type: "string", role: "state", read: true, write: true, states: { "auto": "auto", "silent": "silent", "favorite": "favorite" } },
        { name: "favorite_level", type: "number", role: "state", read: true, write: true, min: 0, max: 16 },
        { name: "temp_dec", type: "number", role: "value.temperature", read: true, write: false, min: -40.0, max: 525.0, unit: "°C" },
        { name: "humidity", type: "number", role: "value.humidity", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "aqi", type: "number", role: "value", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "average_aqi", type: "number", role: "value", read: true, write: false, min: 0, max: 600, unit: "μg/m³" },
        { name: "led", type: "boolean", role: "switch", read: true, write: true, min: false, max: true },
        { name: "led_b", type: "number", role: "state", read: true, write: true, min: 0, max: 2, states: { 0: "bright", 1: "dim", 2: "off" } },
        { name: "buzzer", type: "boolean", role: "switch", read: true, write: true, min: false, max: true },
        { name: "filter1_life", type: "number", role: "value", read: true, write: false, min: 0, max: 100, unit: "%" },
        { name: "f1_hour", type: "number", role: "value", read: true, write: false, unit: "h" },
        { name: "f1_hour_used", type: "number", role: "value", read: true, write: false, unit: "h" },
        { name: "motor1_speed", type: "number", role: "value", read: true, write: false, unit: "rpm" },
        { name: "child_lock", type: "boolean", role: "switch", read: true, write: true, min: false, max: true }]
};

@Pittini Pittini closed this as completed Feb 24, 2021
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

2 participants