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

Xiaomi purifier support #2755

Open
3 tasks done
theundefined opened this issue Dec 3, 2024 · 7 comments
Open
3 tasks done

Xiaomi purifier support #2755

theundefined opened this issue Dec 3, 2024 · 7 comments
Labels
enhancement New feature or request new-device-type

Comments

@theundefined
Copy link
Contributor

Checklist

  • I have filled out the template to the best of my ability.
  • This only contains 1 feature request (if you have multiple feature requests, open one feature request for each feature request).
  • This issue is not a duplicate feature request of previous feature requests.

Is your feature request related to a problem? Please describe.

There is lack of support of fan / purifier

Describe the solution you'd like

Add purifier to library

Describe alternatives you've considered

Just add it... An alternative is calculate power usage independent for every motor and group it (?)

Additional context

There is something like xiaomi purifer. I use model Xiaomi Air Purifier Pro, which identify in home assistant as zhimi.airpurifier.v7.
It have have two motors inside, which works partly independent. I've stored power usage of it in https://docs.google.com/spreadsheets/d/19eC3LRcdEiU-u6yyms163hdAFy7Xp63k73F2aA55OyQ/edit?usp=sharing. Motor speed is under sensor.oczyszczacz_motor_speed and secondary motor speed under sensor oczyszczacz_second_motor_speed

@theundefined theundefined added the enhancement New feature or request label Dec 3, 2024
@bramstroker
Copy link
Owner

Need to give it a thought.
But I also wanted to suggest to just create 2 seperate linear sensor and group them.

Or you might use the composite mode:
https://docs.powercalc.nl/strategies/composite/
Which will probably also be the solution I want to investigate.
Would be nice to have a possibility to use composite configuration in model.json so a profile can be made for this and eventually also be submitted to the library, so everyone with this device can use the profile.

@bramstroker
Copy link
Owner

bramstroker commented Dec 3, 2024

Looking at your sheet it just seems a mapping between state and power would be sufficient.
So you can just use states_power:

https://docs.powercalc.nl/strategies/fixed/#power-per-state

Not sure if mode is the actual state of the entity, or some attribute of the entity?
When you can share from developer tools I might give you an example how to configure it.

@theundefined
Copy link
Contributor Author

theundefined commented Dec 3, 2024

States aren't useful here. favorite etc - are only manual modes where I can control motors to measuer power :). Apart of manual mode there is the most usefull auto mode where speed of motors depends on the pollution in room.

in developer tools i have for fan.oczyszczacz:

preset_modes:
  - Auto
  - Silent
  - Favorite
preset_mode: Auto
extra_features: 0
turbo_mode_supported: false
button_pressed: null
friendly_name: Oczyszczacz
supported_features: 56

and for sensor.oczyszczacz_motor_speed:

state_class: measurement
unit_of_measurement: rpm
icon: mdi:fast-forward
friendly_name: Oczyszczacz Motor speed

(simmilar for second_motor)

for number.oczyszczacz_favorite_level:

min: 0
max: 17
step: 1
mode: auto
icon: mdi:star-cog
friendly_name: Oczyszczacz Favorite level

(but it's only settable and used when fan is in "favorite" state - not when is in "auto" mode)

@bramstroker
Copy link
Owner

I'm not understanding fully.
Essentially you want to calculate power depending on the speed of both motors right?
So when the mode is auto HA will constantly be updated with the actual motor speeds and we can calculate power accordingly.

You have made the favorite settings only to measure the power?
I would suggest to do that more structured so you can determine a linear scale for them.

So for example:

motor1 | motor2
0 | 600
0 | 700
0 | 800
...
0 | 2000
300 | 0
310 | 0
320 | 0
...
500 | 0

When you have the values for each motor you could use linear strategies with the calibrate feature in conjunction with group logic.

powercalc:
  sensors:
    - create_group: Humidifier
      hide_members: true
      entities:
        - entity_id: sensor.oczyszczacz_motor_speed
          linear:
            calibrate:
              - 300 -> 1
              - 310 -> 1.5
              - 320 -> 2
              - 500 -> 5
        - entity_id: sensor.oczyszczacz_second_motor_speed
          linear:
            calibrate:
              - 600 -> 2.5
              ...

You can also do this with the GUI flow, then you'll need to create 3 sensors.

I might have a look into supporting some mode for the composite strategy: https://docs.powercalc.nl/strategies/composite/, so you the strategies can be combined (summed). Currently only one strategy will apply depending on matching condition.
Advantage is we can create a single sensor this way, and don't need to use grouping functionality.

But with current possibilities you can use the configuration as explained above.

@theundefined
Copy link
Contributor Author

theundefined commented Dec 7, 2024

"favorite" modes are defined - I can't controll every fan. I can only setup modes:

  • favorite (from 0 do 17) - where fans speed are more or less predefined (and here is possible to measure power)
  • auto - where fans speed depend on pollution
  • silent - simmilar to auto, but with reduced speed

I know more or less that I need to group power of:

  1. fan1
    1.2W W linear as 1.2W for 0 rpm
    2W linear when 330W
    10W linear when 500W
  2. fan2 - vaules from 2 column minus 2W

I can do it manually, but I think that there would be great to add such possibility basing on 2 linear sensors for models in library :)

@bramstroker
Copy link
Owner

@theundefined Could you setup the sensor as suggested with the calibration values you mentioned in your latest reply and see how it goes?
Let it run a few days and try different settings and see if the power consumption of virtual sensor matches the consumption records by smart plug closely.

When it's working fine I will see what development is needed to get it integrated in a profile for the library.

@bramstroker
Copy link
Owner

@theundefined Just wanted to let you know I've worked on some development to facilitate your use case.

I have implemented sum_all mode for composite strategy:
https://docs.powercalc.nl/strategies/composite/#sum-all-mode

Which essentially allows you to combine multiple calculations in one sensor. The resulting power calculation will be the sum of all underlying strategies which match the conditions.

This configuration is also supported in library profiles model.json files:

{
  "name": "My device",
  "measure_method": "manual",
  "measure_device": "xx",
  "device_type": "generic_iot",
  "calculation_strategy": "composite",
  "composite_config": {
    "mode": "sum_all",
    "strategies": [
      {
        "condition": {
          "condition": "numeric_state",
          "above": 70
        },
        "fixed": {
          "power": 20
        }
      },
      {
        "fixed": {
          "power": 2
        }
      }
    ]
  }
}

Only challenge left is the entity_id's which are variable.
So when we want to add profile to the library sensor.oczyszczacz_motor_speed is different for other users.
We might have a look at using some wildcard, but that's also error prone.

Maybe I will implement some possibility for variables in model.json where the form is dynamically extended with extra fields.
Similarly as in HA scripts and blueprints.
In this scenario there will be 2 variables: motor_1_speed_entity and motor_2_speed_entity
Will give it some more thought.

Are you able to test if the new composite sum_all mode works for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new-device-type
Projects
None yet
Development

No branches or pull requests

2 participants