Xiaomi mi wifi plug & air purifier

There is no service to change the mode in the current air purifier component.
You can do it with a shell command like the below.
With them, you can make a automation what you want.

shell_command:
mi_air_mode_auto: /srv/homeassistant/bin/mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35555 raw_command set_mode ‘[“auto”]’
mi_air_mode_silent: /srv/homeassistant/bin/mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35555 raw_command set_mode ‘[“silent”]’
mi_air_mode_favorite: /srv/homeassistant/bin/mirobo --ip 192.168.0.15 --token 2a4d39a5721f983fdceae9193fc35555 raw_command set_mode ‘[“favorite”]’

@hkrob You found a bug! I just fixed the set_speed service. This is the code change:

https://github.com/syssi/xiaomi_airpurifier/commit/8bc091f03cfaaea6ffff2b823bb52b6103f6508b

You could use the custom component in the meantime. I will provide an official fix for home assistant soon!

@syssi you’re awesome, working fine now!

@af950833 thanks for the work-around, but you might want to correct your statement “There is no service to change the mode in the current air purifier component”

cheers guys

As I mentioned, there is no service to change a mode in current air purifier.
The fan.turn_on (you tried) is not a service of air purifier.
Syssi is making a new code and he will add it but not available now.

I rethink my fix. This wasn’t a bug. The change broke the dropdown of the UI. Please revert the fix. The payload of the service was wrong. This will work:

{“entity_id”: “fan.air_purifier”, “speed”:“Auto”}
{“entity_id”: “fan.air_purifier”, “speed”:“Favorite”}

etc.

Could someone of the powerstrip owners (@hangy?) provide the output of following commands:

mirobo raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']"
mirobo raw_command set_power_price "[1.55]"
mirobo raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']"
mirobo raw_command set_power_price "[2]"
mirobo raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']"

mirobo raw_command set_wifi_led "['off']"
mirobo raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']"
mirobo raw_command set_wifi_led "['on']"
mirobo raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']"

Thanks in advance!

here it is @syssi :slight_smile:

mirobo raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']" ->
['on', 44.07, 0.22, None, 26.29, 'on', 8]

raw_command set_power_price "[1.55]" ->
Sending cmd set_power_price with params [1.55]
['ok']

raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']" ->
['on', 44.0, 0.22, None, 26.29, 'on', 1]

raw_command set_power_price "[2]" ->
Sending cmd set_power_price with params [2]
['ok']

raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']" ->
['on', 43.93, 0.22, None, 26.39, 'on', 2]

raw_command set_wifi_led "['off']" ->
Sending cmd set_wifi_led with params ['off']
['ok']

raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']" ->
['on', 43.86, 0.22, None, 26.6, 'off', 2]

raw_command set_wifi_led "['on']" ->
Sending cmd set_wifi_led with params ['on']
['ok']

raw_command get_prop "['power', 'temperature', 'current', 'mode', 'power_consume_rate', 'wifi_led', 'power_price']" ->
['on', 43.72, 0.22, None, 25.89, 'on', 2]

i’ve understand that the electricity power can not be set with decimal value… i think because in china is not needed :wink:

Thanks for your support! I will introduce the additional properties into the official component soon.

2 Likes

Sorry for dumb question, can someone help me with setting the speed/mode for the air purifier.

- alias: 'xiaomi fan test silent'        
  trigger:
  action:
    - service: persistent_notification.create
      data:
        message: "I just turned the fan onto silent mode"
        title: "Fan Notification"
    - service: FAN.XIAOMI_MIIO_SET_OPERATION_MODE
      data:
        mode: 'silent'
        
- alias: 'xiaomi fan test favorite'        
  trigger:
  action:
    - service: persistent_notification.create
      data:
        message: "I just turned the fan onto favorite mode"
        title: "Fan Notification"
    - service: FAN.XIAOMI_MIIO_SET_OPERATION_MODE
      data:
        mode: 'favorite'

The service is called fan.set_speed and the parameter must be speed:

- alias: 'xiaomi fan test silent'        
  trigger:
  action:
    - service: persistent_notification.create
      data:
        message: "I just turned the fan onto silent mode"
        title: "Fan Notification"
    - service: fan.set_speed
      entity_id: fan.MYAIRPURIFIER
      data:
        speed: 'silent'
1 Like

Thanks, just in case anyone searches into this thread, to set favorite level the syntax is:

- alias: 'set fan favorite level to 12'
  trigger:
  action:
    - service: FAN.XIAOMI_MIIO_SET_FAVORITE_LEVEL
      entity_id: fan.xiaomairpurifier
      data:
        level: '12'

@kiwijunglist Just a hint: The styling of a headline at the documentation is in uppercase. You can use the service name in lower case too: fan.xiaomi_miio_set_favorite_level

1 Like

cheers, I’m new to all of this, just started automations yesterday, and I’m not in the IT profession :stuck_out_tongue:

when I’m writing automations, I make frequent syntax mistakes (eg too many spaces, or forget a colon or something like that). To quick check my automation.yaml is correct I click reload automations and if there is an error then it shows up as a persistant notification is hass.

however I’d quite like to know what line # my error is on, when I use check config in hassio, it frequently only tells me the line # error in the configutation file that corresponds to automation: !include automations.yaml , is there a trick to making my life easier?

Try to use a YAML capable editor. Writing YAML files is error-prone if you are unfocused. :wink:

1 Like

im using notepad++

Here’s an example of a mistake i just made, took quite a while to figure it out

- alias: 'I couldn't find this mistake for a while'
# using ' inside '....' marks

Hey,

Thank you for setting up this component, it works fantastically!

I am trying to setup a pull down menu so I can set the mode for the fan.

Its all working with the following code:

Configuration:

input_select:
  xiaomi_mode:
    name: Air Purifier Mode
    options:
     - auto
     - favorite
     - silent
     - idle

Automation:

- id: xiaomi_mode
  alias: Xiaomi Mode
  trigger:
    platform: state
    entity_id: input_select.xiaomi_mode
  action:
    - service: FAN.SET_SPEED
      data_template:
        entity_id: fan.xiaomi_miio_device
        speed: '{{ states.input_select.xiaomi_mode.state }}'

The only thing left I’d like to do is have the pull down automatically changed if a automation or the mi home app changes the mode. I know this shouldn’t be too hard but Im having difficulties finding some good instructions or code to copy. Can someone point me in the right direction?

Edit: sinker1345 on the discord came up with this for me:

  • alias: Set input select on Xiaomi mode HIDE
    trigger:
    • platform: state
      entity_id: sensor.bedroom_air_purifier_mode
      to: ‘auto’
    • platform: state
      entity_id: sensor.bedroom_air_purifier_mode
      to: ‘favorite’
    • platform: state
      entity_id: sensor.bedroom_air_purifier_mode
      to: ‘silent’
    • platform: state
      entity_id: sensor.bedroom_air_purifier_mode
      to: ‘idle’
      action:
    • service: input_select.select_option
      data_template:
      entity_id: input_select.xiaomi_mode
      option: >
      {% if states.sensor.bedroom_air_purifier_mode.state == ‘auto’ %}
      auto
      {% endif %}
      {% if states.sensor.bedroom_air_purifier_mode.state == ‘favorite’ %}
      favorite
      {% endif %}
      {% if states.sensor.bedroom_air_purifier_mode.state == ‘silent’ %}
      silent
      {% endif %}
      {% if states.sensor.bedroom_air_purifier_mode.state == ‘idle’ %}
      idle
      {% endif %}

Thanks!

hi. i think it’s easier to just trigger on state change rather then including all different state for updating your input_select

  trigger:
    - platform: state
      entity_id: fan.air_purifier
  action:
    - service: input_select.select_option
      data_template:
        entity_id: input_select.xiaomi_mode
        option: '{{states.fan.air_purifier.state}}'

Thanks, that works better.

How do you get the token of ZNCZ02CM ?
I have the same but I’m spending my whole day to looking for a method.
Older versions of mi home doesn’t support for ZNCZ02CM, isnt it?