Pittini / iobroker-nodemihome

Steuerung von bisher nicht unterstützten Xiaomi Geräten in Iobroker via node-mihome
MIT License
27 stars 15 forks source link

Installation #63

Open waterchill opened 1 year ago

waterchill commented 1 year ago

Hi, in point 3 you have to fill in the xiaomi credentials in the script settings. My problem is, where are the scriptsettings? Sorry I cannot find these

dontobi commented 1 year ago

Have a look at lines 6 to 8 of the script.

waterchill commented 1 year ago

ok I understand. Now I have under objects the mihomeall and my 2 devices. These are dmaker.fan.p220 also known as bplds05dm. Which plugin do I need now? Thank you

waterchill commented 1 year ago

Ich ahbe die dmaker.fan.p15 und p18 in das Verzeichnis reinkopiert und mit iob restart alles neugestartet. Wo kann ich den Lüfter jetzt sehen? Unter Objekte oder woanders? Oder gar nicht weil ich für das Modell das Skript selber schreiben muss? Wäre für eine Hilfe dankbar

Pittini commented 1 year ago

Did you find your fan model in the list of supported devices? I think no, the script doesnt know a dmaker.fan.p220, so its normal that is not working. You can copy whatever you want, if its not for your device, it doesnt works.

waterchill commented 1 year ago

So I have to go now for this description right?

https://github.com/Pittini/iobroker-nodemihome/blob/main/HowToAddNewDevices.md

Pittini commented 1 year ago

Yes. But you havent found the scriptsettings, so I assume, maybe your skills are not enough.

waterchill commented 1 year ago

We will see, I will take look on this later.

waterchill commented 1 year ago

So I have tried two versions, in both cases objects created, but cannot power on the fan. There is "false" in red. Here are my examples:

The filename is always which is uploaded correctly: dmaker.fan.p220.js

In the script:

DefineDevice[28] = { // Untestet
    info: {},
    model: "dmaker.fan.p220",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1
    description: "Mi Smart Standing Fan (with Battery)",
    setter: {
        "fan.on": async function (obj, val) { await device[obj].setPower(val) }
    },
    common:
        [{ name: "fan.on", type: "boolean", role: "switch", read: true, write: true }]
};

In the file:

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

module.exports = class extends Device {

static model = 'dmaker.fan.p220';
static name = 'Mi Smart Standing Fan (with Battery)';
static image = 'http://static.home.mi.com/app/image/get/file/developer_1543307568u9wu6wij.png';

  constructor(opts) {
    super(opts);

    this._miotSpecType = 'urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1';
    this._propertiesToMonitor = [
        'fan:on'
    ];
  }

   getPower() {
     return this.properties['fan:on'];
  }

};

Second try:

In the script:

DefineDevice[28] = { // Untestet
    info: {},
    model: "dmaker.fan.p220",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1
    description: "Mi Smart Standing Fan (with Battery)",
    setter: {
        "power": async function (obj, val) { await device[obj].setPower(val) }
    },
    common:
        [{ name: "power", type: "boolean", role: "switch", read: true, write: true, min: false, max: true }]
};

In the File:

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

module.exports = class extends Device {

static model = 'dmaker.fan.p220';
static name = 'Mi Smart Standing Fan (with Battery)';
static image = 'http://static.home.mi.com/app/image/get/file/developer_1543307568u9wu6wij.png';

constructor(opts) {
  super(opts);

  this._propertiesToMonitor = [
      'power'
  ];
}

setPower(v) {
  return this.miotSetProperty('power', v);
}

};

There are no errors in th the log. Any thoughts? By the way I have two of exact same fans here, maybe this is a problem?

waterchill commented 1 year ago

ok I got it to work 😊

File:

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

 module.exports = class extends Device {

   static model = 'dmaker.fan.p220';
   static name = 'Mi Smart Standing Fan (with Battery)';
   static image = 'http://static.home.mi.com/app/image/get/file/developer_1541408255kg3xtr1j.png';

   constructor(opts) {
     super(opts);

     this._miotSpecType = 'urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1';
     this._propertiesToMonitor = [
      'fan:on',
      'fan:fan-level'
      ];
  }

  getPower() {
    return this.properties['fan:on'];
  }

  setPower(v) {
    return this.miotSetProperty('fan:on', v);
  }

  setFanLevel(v) {
    return this.miotSetProperty('fan:fan-level', v);
  }

};

File:

DefineDevice[28] = { // Untestet
    info: {},
    model: "dmaker.fan.p220",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1
    description: "Mi Smart Standing Fan (with Battery)",
    setter: {
        "fan.on": async function (obj, val) { await device[obj].setPower(val) },
        "fan.fan-level": async function (obj, val) { await device[obj].setFanLevel(val) }

    },
    common:
        [{ name: "fan.on", type: "boolean", role: "switch", read: true, write: true },
        { name: "fan.fan-level", type: "number", role: "switch", read: true, write: true, min: 1, max: 4, states: { 1: "Slow", 2: "Middle", 3: "High", 4: "Turbo" } }
        ]
};
Pittini commented 1 year ago

Congratulations, well done. Does this fan have only two settings?

waterchill commented 1 year ago

Thanks. This fans has a lot of functions but I need for iobroker only speed and power.

waterchill commented 1 year ago

This fan can also adjust speed level by 1% from 0% to 100%. I would like to add this feature, so I spotted in the urn file this part:

{
      "iid": 8,
      "type": "urn:dmaker-spec:service:dm-service:00007802:dmaker-p220:1",
      "description": "dm-service",
      "properties": [
        {
          "iid": 1,
          "type": "urn:dmaker-spec:property:speed-level:00000001:dmaker-p220:1",
          "description": "speed-level",
          "format": "uint8",
          "access": [
            "write",
            "read",
            "notify"
          ],
          "value-range": [
            1,
            100,
            1
          ]
        },

I added this to the script:

DefineDevice[28] = { // Untestet
    info: {},
    model: "dmaker.fan.p220",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1
    description: "Mi Smart Standing Fan (with Battery)",
    setter: {
        "fan.on": async function (obj, val) { await device[obj].setPower(val) },
        "fan.speed-level": async function (obj, val) { await device[obj].setFanLevel(val) },
        "fan.fan-level": async function (obj, val) { await device[obj].setFanLevel(val) }

    },
    common:
        [{ name: "fan.on", type: "boolean", role: "switch", read: true, write: true },
        { name: "fan.speed-level", type: "number", read: true, write: true, min: 1, max: 100, unit: "%" },
        { name: "fan.fan-level", type: "number", role: "switch", read: true, write: true, min: 1, max: 4, states: { 1: "Slow", 2: "Middle", 3: "High", 4: "Turbo" } }
        ]
};

And to the definition file:

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

 module.exports = class extends Device {

   static model = 'dmaker.fan.p220';
   static name = 'Mi Smart Standing Fan (with Battery)';
   static image = 'http://static.home.mi.com/app/image/get/file/developer_1541408255kg3xtr1j.png';

   constructor(opts) {
     super(opts);

     this._miotSpecType = 'urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1';
     this._propertiesToMonitor = [
      'fan:on',
      'fan:fan-level',
      'fan:speed-level'
      ];
  }

  getPower() {
    return this.properties['fan:on'];
  }

  setPower(v) {
    return this.miotSetProperty('fan:on', v);
  }

  setFanLevel(v) {
    return this.miotSetProperty('fan:fan-level', v);
  }

  setSpeedLevel(v) {
    return this.miotSetProperty('fan:speed-level', v);
  }

};

But it will not work. Please can you help me to fix this? Thank you

waterchill commented 1 year ago

Maybe this will help

Bildschirmfoto 2022-10-05 um 13 12 06

Pittini commented 1 year ago

fan:speed-level is not shown. You have to use fan:fan-level OR dm-service:speed-level (I dont know the difference between those two)

waterchill commented 1 year ago

fan-level is only 4 steps. slow - middle - high - turbo speed speed-level has 100steps in 1% from 0% to 100% fan speed

I tried this now and it looks good now so far:

DefineDevice[28] = { // Untestet
    info: {},
    model: "dmaker.fan.p220",// https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1
    description: "Mi Smart Standing Fan (with Battery)",
    setter: {
        "fan.on": async function (obj, val) { await device[obj].setPower(val) },
        "dm-service:speed-level": async function (obj, val) { await device[obj].setSpeedLevel(val) },
        "fan.fan-level": async function (obj, val) { await device[obj].setFanLevel(val) }

    },
    common:
        [{ name: "fan.on", type: "boolean", role: "switch", read: true, write: true },
        { name: "dm-service:speed-level", type: "number", read: true, write: true, min: 1, max: 100, unit: "%" },
        { name: "fan.fan-level", type: "number", role: "switch", read: true, write: true, min: 1, max: 4, states: { 1: "Slow", 2: "Middle", 3: "High", 4: "Turbo" } }
        ]
};

And in the File:

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

 module.exports = class extends Device {

   static model = 'dmaker.fan.p220';
   static name = 'Mi Smart Standing Fan (with Battery)';
   static image = 'http://static.home.mi.com/app/image/get/file/developer_1541408255kg3xtr1j.png';

   constructor(opts) {
     super(opts);

     this._miotSpecType = 'urn:miot-spec-v2:device:fan:0000A005:dmaker-p220:1';
     this._propertiesToMonitor = [
      'fan:on',
      'fan:fan-level',
      'dm-service:speed-level'
      ];
  }

  getPower() {
    return this.properties['fan:on'];
  }

  setPower(v) {
    return this.miotSetProperty('fan:on', v);
  }

  setFanLevel(v) {
    return this.miotSetProperty('fan:fan-level', v);
  }

  setSpeedLevel(v) {
    return this.miotSetProperty('dm-service:speed-level', v);
  }

};

I have no idea if the syntax is ok. Can you check please? Thank you

Pittini commented 1 year ago

I have no idea if the syntax is ok. Can you check please? Thank you

Looks good for me. And if it works, the syntax is ok, every error leads to malfunktions.

waterchill commented 1 year ago

It seems to work, but the numbers are always shown in red color. So I can set every number and the fan is reacting. But when I set on level for example level 2 the numbers in speed level do not change. Maybe there is something missing, something like a backchannel or a refresh for this object.

Pittini commented 1 year ago

Red color is ok, that means there is no ack flag set, what is normal for manual written values. The not synched values behaviour maybe will set the right value at next refresh (10seks if not changed). If not...how is the behaviour in the orig app?

waterchill commented 1 year ago

When set in iobroker for example 27% it goes in the app within 1 second to 27% and so on. When I change the value in the app nothing happens in iobroker.

waterchill commented 1 year ago

So far it has worked very well. Today I rebooted my Raspi and now I get this error, I donÄt understand it:

Bildschirmfoto 2022-10-18 um 17 15 46

waterchill commented 1 year ago

I found out for some reason the file dmaker.fan.p220 was deleted. I copied again and now it works.