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

Incorrect water level of air humidifiers #1135

Closed
OleksandrBerchenko opened this issue Sep 6, 2021 · 22 comments · Fixed by #1140
Closed

Incorrect water level of air humidifiers #1135

OleksandrBerchenko opened this issue Sep 6, 2021 · 22 comments · Fixed by #1140
Labels

Comments

@OleksandrBerchenko
Copy link

OleksandrBerchenko commented Sep 6, 2021

The water level of air humidifiers is incorrect (assuming that the value in Mi Home is correct).

You have the following code (https://github.com/rytilahti/python-miio/blob/master/miio/airhumidifier_miot.py#L135):

return int(self.data["water_level"] / 1.25)

1.25 here should be changed to 1.2. But you are right, 125 still means the full (actually, overflowing) tank.

UPDATE: The model of my air humidifiers is zhimi.humidifier.ca1.

@rytilahti
Copy link
Owner

Ping @bieniu

@bieniu
Copy link
Contributor

bieniu commented Sep 6, 2021

1.25 here should be changed to 1.2

Why? Do we have any specification for this?

@OleksandrBerchenko
Copy link
Author

We have the Mi Home application. If you change 1.25 to 1.2, you will get the identical value.

@bieniu
Copy link
Contributor

bieniu commented Sep 6, 2021

Not on my humidifier, I have 98-96% when depth is 120.

@OleksandrBerchenko
Copy link
Author

Oh, really? What model do you have? I have two zhimi.humidifier.ca1 with the latest firmware. They worked that way from the very beginning.

@bieniu
Copy link
Contributor

bieniu commented Sep 6, 2021

Really, my zhimi.humidifier.ca1 works that way.

@OleksandrBerchenko
Copy link
Author

OleksandrBerchenko commented Sep 6, 2021

Right now, I have the following values:
Humidifer 1: MI Home: 84%, python-miio: 81%
Humidifer 2: MI Home: 75%, python-miio: 72%

@bieniu
Copy link
Contributor

bieniu commented Sep 7, 2021

What are the depth values for these percentages?

@OleksandrBerchenko
Copy link
Author

What is the easiest way to print raw depth values? I'm using this library through Home Assistant.

@bieniu
Copy link
Contributor

bieniu commented Sep 7, 2021

Add this to the configuration.yaml file:

logger:
  default: warning
  logs:
    homeassistant.components.xiaomi_miio: debug

With this, the log will show full humidifier states, look for lines with text "Got new state".

@OleksandrBerchenko
Copy link
Author

Thanks, that works.

humidifier 1: depth: 68, water level: 54, mi home: 56
humidifier 2: depth: 95, water level: 76, mi home: 79

@bieniu
Copy link
Contributor

bieniu commented Sep 9, 2021

For your humidifiers 1.2 gives much better results. I'm curious why for mine 1.25 is better. I'll try to make some research in this case but I don't know when. There was an attempt to break into my apartment, so my world is turned upside down now.

@OleksandrBerchenko
Copy link
Author

Oh, I'm really sorry to hear that. That sounds awful!

No rush: I have already workarounded this issue by a correction formula in HA.

@OleksandrBerchenko
Copy link
Author

Just in case, one more observation:

When the tank is full, depth is 120 and Mi Home displays 100%. But if you continue to add water, suddenly depth jumps to 125, but Mi Home continues to display 100%. In HA I just translated 125 to 101% that means "overflow". And BTW, if you open the cover, depth becomes something like 127 (as far as I remember).

@bieniu
Copy link
Contributor

bieniu commented Sep 14, 2021

I made research and probably you're right, the depth value of 120 means full tank and 125 means tank overfilled. I'll prepare a fix.

@bieniu
Copy link
Contributor

bieniu commented Sep 17, 2021

I tried to find some info in decompiled Mi Home app but with no success. I'm not familiar with decompiling apk files. @syssi You have shown snippets of app code in another thread. Maybe you can help?
I don't want to change anything unless I'm 100% sure.

@syssi
Copy link
Collaborator

syssi commented Sep 17, 2021

@bieniu Could you tell me the model names (f.e. zhimi.humidifier.ca1) of the devices you want to know the behaviour of?

@bieniu
Copy link
Contributor

bieniu commented Sep 17, 2021

@syssi
zhimi.humidifier.ca1 (MIIO), depth value
zhimi.humidifier.ca4 (MIOT), water_level value

@syssi
Copy link
Collaborator

syssi commented Sep 17, 2021

# Mi Home react plugin of the CA1

[...]
    }, {
      key: "_isShortageWater",
      value: function _isShortageWater() {
        if (MainPage.isCModel()) {
          if (this.state.depth !== -1 && this.state.depth < 12) {
            return true;
          } else return false;
        } else {
          return false;
        }
      }
    }, {
      key: "_getPercentWaterDepth",
      value: function _getPercentWaterDepth(value) {
        if (value > 120) {
          if (value === 127) return "--";
          value = 120;
        } else if (value === -1) value = 0;

        var x = value / 120 * 100;
        return parseInt(x);
      }
    }, {
[...]

[...]
    }, {
      key: "_getCenterViewBodyText",
      value: function _getCenterViewBodyText() {
        if (MainPage.isCModel()) {
          return this.state.power ? "" + this.state.humidity : "" + this._getPercentWaterDepth(this.state.depth);
        } else {
          return "" + this.state.humidity;
        }
      }
    }, {
      key: "_getCenterViewBottomText",
      value: function _getCenterViewBottomText() {
        var string = "";

        if (MainPage.isCModel()) {
          if (this.state.power) {
            if (this.state.depth === 127) {
              string = (0, _LocalStrings.getLocalStrings)().ca1_cover_removed;
            } else {
              if (this._isShortageWater()) {
                string = (0, _LocalStrings.getLocalStrings)().ca1_low_water;
              } else {
                string = (0, _LocalStrings.getLocalStrings)().remainder_water + " " + this._getPercentWaterDepth(this.state.depth) + "%";
              }
            }
          } else {
            if (this._isShortageWater()) {
              string = (0, _LocalStrings.getLocalStrings)().ca1_low_water;
            } else {
              string = "";
            }
          }
        } else {
          if (this.state.child_lock) {
            string = (0, _LocalStrings.getLocalStrings)().child_locked;
          }
        }

        return string;
      }
[...]

[...]
    }, {
      key: "_isV1",
      value: function _isV1() {
        return _miot.Device.model === "zhimi.humidifier.v1";
      }
    }], [{
      key: "isCModel",
      value: function isCModel() {
        return _miot.Device.model === "zhimi.humidifier.ca1" || _miot.Device.model === "zhimi.humidifier.cb1" || _miot.Device.model === "zhimi.humidifier.cb2";
      }
    }, {
      key: "_isCb",
      value: function _isCb() {
        return _miot.Device.model === "zhimi.humidifier.cb1" || _miot.Device.model === "zhimi.humidifier.cb2";
      }
    }, {
      key: "_isCb1",
      value: function _isCb1() {
        return _miot.Device.model === "zhimi.humidifier.cb1";
      }
    }, {
      key: "_isCb2",
      value: function _isCb2() {
        return _miot.Device.model === "zhimi.humidifier.cb2";
      }
[...]

@syssi
Copy link
Collaborator

syssi commented Sep 17, 2021

# Mi Home react plugin of the CA4

[...]
    }, {
      key: "_isShortageWater",
      value: function _isShortageWater() {
        return this.state.depth !== -1 && this.state.depth < 13;
      }
    }, {
      key: "_getPercentWaterDepth",
      value: function _getPercentWaterDepth(value) {
        if (value > 120) {
          if (value === 127) {
            return "--";
          }

          value = 120;
        } else if (value === -1) {
          value = 0;
        }

        var x = value / 120 * 100;
        return Math.floor(x);
      }
    }, {
[...]

[...]
    }, {
      key: "_getCenterViewBodyText",
      value: function _getCenterViewBodyText() {
        return this.state.power ? "" + this.state.humidity : "" + this._getPercentWaterDepth(this.state.depth);
      }
    }, {
      key: "_getCenterViewBottomText",
      value: function _getCenterViewBottomText() {
        var string = "";

        if (this.state.power) {
          if (this.state.depth === 127) {
            string = (0, _LocalStrings.getLocalStrings)().ca1_cover_removed;
          } else if (this._isShortageWater()) {
            string = (0, _LocalStrings.getLocalStrings)().ca1_low_water;
          } else {
            string = (0, _LocalStrings.getLocalStrings)().remainder_water + " " + this._getPercentWaterDepth(this.state.depth) + "%";
          }
        } else if (this._isShortageWater()) {
          string = (0, _LocalStrings.getLocalStrings)().ca1_low_water;
        } else {
          string = "";
        }

        return string;
      }
    }, {

[...]

@syssi
Copy link
Collaborator

syssi commented Sep 17, 2021

Ping me if you have questions.

@bieniu
Copy link
Contributor

bieniu commented Sep 17, 2021

@syssi Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants