jaromeyer / mipurifier-esphome

ESPHome for the Xiaomi Mi Air Purifier 3H (and similar devices using the same protocol)
The Unlicense
90 stars 12 forks source link

Migrate to fan-template platform #19

Closed ireun closed 3 weeks ago

ireun commented 5 months ago

https://esphome.io/components/fan/template This allows to use https://github.com/denysdovhan/purifier-card

image

ireun commented 5 months ago

Few commits that have implemented that platform:

https://github.com/esphome/esphome/pull/6310 https://github.com/esphome/esphome-docs/pull/3655 https://github.com/esphome/esphome/pull/6112

ireun commented 5 months ago

For now it seems that everything works, with the exception of presets auto, night, manual being lost in HA after turning the fan off and on again .

jaromeyer commented 5 months ago

sorry ive been very busy. i'll try to have a look at it in the following days

Xploder commented 3 months ago

For me, it doesn't sync the fan percentage to the actual value at all but having this setup as a fan entity is the right way in general.

leonardpitzu commented 1 month ago

It works but the fan speed slider has no effect. Does it work for you?

ireun commented 1 month ago

Have you set the mode to manual?

leonardpitzu commented 1 month ago

I guess so. Clicked the fan and moved the slider up and down - nothing.

ireun commented 1 month ago

image

leonardpitzu commented 1 month ago

still nothing...

ireun commented 1 month ago

Will check if the code here is the same as mine, or weather I have made any changes. Though it works for me..

leonardpitzu commented 1 month ago

only looked at it from hi up in the sky but after XiaomiPurifierFan->speed = atof(val)+1; isn't there supposed to be a call.perform(); ?

ireun commented 1 month ago

I've found some differences between what I use in HA and what was in this draft, could You try that?

leonardpitzu commented 1 month ago

it's on now but one suggestion - whenever the slider is moved just change the preset automatically to manual in this case you do not need to firstly change the preset and then move the slider

ireun commented 1 month ago

I've tried to do that, but I wasn't able to achieve that, since than I have not worked on it, maybe @jaromeyer could figure it out ;)

Xploder commented 1 month ago

Yeah that'd be great. Right now if you're in let's say the Medium preset and change the percentage slider, the unit itself stays in that preset and doesn't actually change the speed and on Home-Assistant it goes to an unknown/bogus state for the mode selection

Before adjusting %: grafik

After adjusting % from the medium preset: grafik

Xploder commented 1 month ago
    on_speed_set:
      - lambda: |-
          auto c = static_cast<MiPurifier *>(mipurifier);
          c->set_mode("manual");
      - delay: 1s
      - lambda: |-
          auto c = static_cast<MiPurifier *>(mipurifier);
          c->set_manualspeed((int)x-1);

I've changed the on_speed_set function to set manual mode every time I change the speed. There needed to be a delay so the send_buffer can loop twice.

ireun commented 1 month ago

Thanks @Xploder! I've swapped these lambada, so first the speed is set and than the mode, to prevent going it to a previous speed for that split second :)

Let me know if it works okay for you this way

Xploder commented 1 month ago

Thanks! Works fine within the usual limitations of it not being able to read current mode later etc. But now we're at least able to easily set percentage from Alexa from any mode!

leonardpitzu commented 1 month ago

works great. like this, enough for getting things done

jaromeyer commented 3 weeks ago

Finally got to test your PR and it works great! Thanks @ireun