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

Add dmaker.airfresh.t2017 support #32

Closed
mapledxf opened this issue Feb 15, 2019 · 82 comments
Closed

Add dmaker.airfresh.t2017 support #32

mapledxf opened this issue Feb 15, 2019 · 82 comments

Comments

@mapledxf
Copy link

Unsupported device found! Please create an issue at https://github.com/syssi/xiaomi_airpurifier/issues and provide the following data: dmaker.airfresh.t2017

@syssi
Copy link
Owner

syssi commented Feb 18, 2019

Could you provide some details about the device?

@mapledxf
Copy link
Author

It is a Mijia Air Fresher
https://www.mi.com/fresh-air-ventilator/

@unixko
Copy link

unixko commented Mar 10, 2019

I also have this device. Please let me know if I can help anything @syssi .

@benny2yu
Copy link

I also have this device. @syssi .

@axingblog
Copy link

axingblog commented Apr 27, 2019

php miio-cli.php --ip 192.168.2.230 --info --token xxx
{"id":7,"result":{"life":33055,"uid":1070947982,"model":"dmaker.airfresh.t2017","token":"xxx","fw_ver":"2.0.3","mcu_fw_ver":"0014","miio_ver":"0.0.3","hw_ver":"esp32","mmfree":68980,"mac":"7C:49:EB:58:D4:BF","wifi_fw_ver":"v3.1.3-8-gce4d3fe10","ap":{"rssi":-68,"ssid":"xxx","primary":11,"bssid":"D0:17:C2:DF:AE:68"},"netif":{"localIp":"192.168.2.230","mask":"255.255.255.0","gw":"192.168.2.1"},"miio_times":[33055,3,2,33050]}}

php miio-cli.php --ip 192.168.2.230 --token xxx --sendcmd '{"method":"get_prop",,"params":[],"id":1}'
{"id":1,"result":[2,550,24,241,100,90,100,180,241,true,"favourite",false,"low",false,false,true,false,"forward"]}

php miio-cli.php --ip 192.168.2.230 --token xxx --sendcmd '{"method":"get_prop",,"params":["pm25","co2","temperature_outside","favourite_speed","filter_intermediate","filter_inter_day","filter_efficient","filter_effi_day","control_speed","power","mode","ptc_on","ptc_level","ptc_status","child_lock","sound","display","screen_direction"],"id":1}'

{"id":1,"result":[1,550,24,241,100,90,100,180,241,true,"favourite",false,"low",false,false,true,false,"forward"]}

properties = ["pm25","co2","temperature_outside","favourite_speed","filter_intermediate","filter_inter_day","filter_efficient","filter_effi_day","control_speed","power","mode","ptc_on","ptc_level","ptc_status","child_lock","sound","display","screen_direction"]

set_mode
set_power
set_ptc_level
set_ptc_on
set_ptc_timer
set_room_area
set_child_lock
set_display
set_sound
set_screen_direction
set_favorite
set_favorite_area
set_favourite_speed
set_filter_reset
set_increase_speed

@voynovia
Copy link

I also have this device. @syssi .

@StanislavBolshakov
Copy link

Came accross the same issue. @syssi kindly ask you to add dmaker.airfresh.t2017 support.

@ps1x
Copy link

ps1x commented Sep 24, 2019

Subscribe!

@d-litvinov
Copy link

I also have that device. @syssi, if you need any information I would be happy to provide it

@lazzzrus
Copy link

lazzzrus commented Nov 4, 2019

Also wait desperatelly! This device needs smarter automation via HA.
If I can be of help contact me please.

@lazzzrus
Copy link

lazzzrus commented Nov 5, 2019

Got it!
https://bbs.hassbian.com/thread-8218-1-1.html
This works!

@syssi
Copy link
Owner

syssi commented Dec 7, 2019

@syssi
Copy link
Owner

syssi commented Dec 7, 2019

Could somebody explain the get_timer, get_ptc_timer and the property ptc_level and ptc_status?

@StanislavBolshakov
Copy link

StanislavBolshakov commented Dec 8, 2019

Could somebody explain the get_timer, get_ptc_timer and the property ptc_level and ptc_status?

Unlike the XFXT01ZM model, this device has a built-in PTC (Positive Temperature Coefficient) heater. So I assume these values related to heater control. Unfortunately, my fresh air system still in transit and I can't assist with troubleshooting.

@unixko
Copy link

unixko commented Dec 8, 2019

get_timer: unit can set a weekly operation timer [Daily, Working days, Weekends, Custom MON-SUN], power-on time and power-off time.

PTC is auxiliary heater for inlet air.

get_ptc_level: unit has 3 heating level [Level 1 (less heat), Level 2, Level 3 (more heat)].

get_ptc_timer: auxiliary heater can set a weekly timer [Daily, Working days, Weekends, Custom MON-SUN], power-on time and power-off time.

ptc_status: auxiliary heat function will be temporary turned off if outside temperature is above 20c.

@syssi
Copy link
Owner

syssi commented Dec 8, 2019

Could you provide some response examples for

miiocli device --ip IP --token TOKEN raw_command get_timer "[]"
miiocli device --ip IP --token TOKEN raw_command get_ptc_timer "[]"
miiocli device --ip IP --token TOKEN raw_command get_prop "['ptc_status', 'ptc_on', 'ptc_status']"

plus description? I want to understand the format of the responses. This is all in know:

        value = time.index + '-' +
            time.hexSum + '-' +
            time.startTime + '-' +
            time.ptcTimer.endTime + '-' +
            time.level + '-' +
            time.status;
        return self.send("set_ptc_timer", [value])

@unixko
Copy link

unixko commented Dec 8, 2019

raw_command get_timer "[]"
Running command raw_command
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
raw_command get_ptc_timer "[]"
Running command raw_command
[' ']

Currently I have no timer / ptc_timer set. I will set various timer and get value again to find a format.

raw_command get_prop "['pm25', 'co2', 'temperature_outside', 'favourite_speed', 'filter_intermediate', 'filter_inter_day', 'filter_efficient', 'filter_effi_day', 'control_speed', 'power', 'mode', 'ptc_on', 'ptc_level', 'ptc_status', 'child_lock', 'sound', 'display', 'screen_direction']"              
Running command raw_command
[25, 649, 27, 240, 70, 63, 85, 153, 240, True, 'auto', False, 'low', False, False, True, True, 'forward']

fresh_air_1

fresh_air_2

fresh_air_3

@syssi
Copy link
Owner

syssi commented Dec 8, 2019

Could you set some timer just for testing? If you change the favorite area setting which property changes?

@unixko
Copy link

unixko commented Dec 8, 2019

raw_command get_timer "[]"
Running command raw_command
['3e-08:00-09:00-enable', 'c0-09:30-10:30-enable', 'fe-11:00-99:99-enable', '2a-99:99-12:00-enable', '02-13:00-99:99-disable', '04-99:99-14:00-disable', '08-16:00-99:99-disable', '80-99:99-17:00-disable', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']

fresh_air_4

raw_command get_ptc_timer "[]"
Running command raw_command
['fe-21:00-08:00-null-enable']

fresh_air_5

@unixko
Copy link

unixko commented Dec 8, 2019

Favorite area settings will change favourite_speed. Value range is from 60 to 300, same as OperationMode (0=OFF).

@syssi
Copy link
Owner

syssi commented Dec 8, 2019

Good job! Thanks for your support!

@unixko
Copy link

unixko commented Dec 14, 2019

I tested each command and here are results.

commands that work:
get_ptc_timer get_timer info set_display_orientation

commands with errors:

miiocli airfresht2017 --ip IP --token TOKEN on
Powering on
Error: {'code': -9999, 'message': 'user ack timeout'}
miiocli airfresht2017 --ip IP --token TOKEN off
Powering off
Error: {'code': -9999, 'message': 'user ack timeout'}
miiocli airfresht2017 --ip IP --token TOKEN set_buzzer true
Turning on buzzer
Error: {'code': -9999, 'message': 'user ack timeout'}
miiocli airfresht2017 --ip IP --token TOKEN set_buzzer false
Turning off buzzer
Error: {'code': -9999, 'message': 'user ack timeout'}
miiocli airfresht2017 --ip IP --token TOKEN set_child_lock true
Turning on child lock
Error: {'code': -9999, 'message': 'user ack timeout'}
cset_child_lock false
Turning off child lock
Error: {'code': -9999, 'message': 'user ack timeout'}
miiocli airfresht2017 --ip IP --token TOKEN set_display true
Traceback (most recent call last):
  File "/usr/local/bin/miiocli", line 11, in <module>
    sys.exit(create_cli())
  File "/usr/local/lib/python3.6/dist-packages/miio/cli.py", line 44, in create_cli
    return cli(auto_envvar_prefix="MIIO")
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 59, in __call__
    return self.main(*args, **kwargs)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 275, in wrap
    msg = msg_fmt(**kwargs)
TypeError: <lambda>() got an unexpected keyword argument 'display'

miiocli airfresht2017 --ip IP --token TOKEN set_display false
Traceback (most recent call last):
  File "/usr/local/bin/miiocli", line 11, in <module>
    sys.exit(create_cli())
  File "/usr/local/lib/python3.6/dist-packages/miio/cli.py", line 44, in create_cli
    return cli(auto_envvar_prefix="MIIO")
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 59, in __call__
    return self.main(*args, **kwargs)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 275, in wrap
    msg = msg_fmt(**kwargs)
TypeError: <lambda>() got an unexpected keyword argument 'display'

set_ptc_level to low medium high are ok, error only to off.

miiocli airfresht2017 --ip IP --token TOKEN set_ptc_level off
Setting ptc level to 'off'
Error: {'code': -9999, 'message': 'user ack timeout'}
miiocli airfresht2017 --ip IP --token TOKEN set_ptc_timer
Running command set_ptc_timer
Traceback (most recent call last):
  File "/usr/local/bin/miiocli", line 11, in <module>
    sys.exit(create_cli())
  File "/usr/local/lib/python3.6/dist-packages/miio/cli.py", line 44, in create_cli
    return cli(auto_envvar_prefix="MIIO")
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 59, in __call__
    return self.main(*args, **kwargs)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 280, in wrap
    kwargs["result"] = func(*args, **kwargs)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/home/administrator/.local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 245, in command_callback
    return miio_command.call(miio_device, *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/miio/click_common.py", line 193, in call
    return method(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/miio/airfresh_t2017.py", line 408, in set_ptc_timer
    raise NotImplementedError()
NotImplementedError

Some status has extra prefix. This Airfresh has 2 filters, in APP they are called Filter and Filter Pro. If we call one filter as Upper, shall we call another as Lower? (Both are dust filters.)

miiocli airfresht2017 --ip IP --token TOKEN status
Power: on
Mode: OperationMode.Favorite
PM2.5: 17
CO2: 565
Temperature: 24
Favorite speed: 240
Control speed: 240
Dust filter life: 70 %, 63 days
Upper filter life remaining: 85 %, 153 days
PTC: False
PTC level: PtcLevel.Medium
PTC status: False
Child lock: False
Buzzer: True
Display: True
Display orientation: DisplayOrientation.Portrait

Spelling is not inline with other usage (should map raw returned favourite to favorite).

miiocli airfresht2017 --ip IP --token TOKEN set_mode favorite
Setting mode to 'favourite'
['ok']

No help text explain possible value (60-300)

miiocli airfresht2017 --ip IP --token TOKEN set_favorite_speed
Usage: miiocli airfresht2017 set_favorite_speed [OPTIONS] SPEED
Try "miiocli airfresht2017 set_favorite_speed --help" for help.

Error: Missing argument "SPEED".

miiocli airfresht2017 --ip IP --token TOKEN set_favorite_speed 301
Setting favorite speed to 301
Error: Invalid favorite speed: 301

Command that not test yet:
reset_dust_filter reset_upper_filter

Missing command set_timer ?

@ps1x
Copy link

ps1x commented Mar 12, 2020

Any update on this one?

edit: Seems that python-miio has full support of dmaker.airfresh.t2017 now. Only lack of time to learn python stops me currently of making merge request :_(

@ps1x
Copy link

ps1x commented Aug 25, 2020

Excuse me, just to make things clear: you plan no support for this model?

@syssi
Copy link
Owner

syssi commented Aug 25, 2020

The device will be supported some day.

@syssi syssi reopened this Aug 25, 2020
@syssi syssi changed the title Unsupported device found: dmaker.airfresh.t2017 Add dmaker.airfresh.t2017 support Oct 18, 2020
@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

If I send a command
./miiocli --debug airfresht2017 --ip --token raw_command "set_power" '["off"]'
I get this answer
Error: {'code': -9999, 'message': 'user ack timeout'}

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

2020-11-05 19:05:11 DEBUG (SyncWorker_6) [miio.miioprotocol] 192.168.1.108:54321 >>: {'id': 1266, 'method': 'set_power', 'params': ['true']}
2020-11-05 19:05:11 DEBUG (SyncWorker_6) [miio.miioprotocol] 192.168.1.108:54321 (ts: 1970-01-08 21:48:44, id: 1266) << {'id': 1266, 'result': ['ok']}

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

Alright. I've fixed all toggles at python-miio.

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

I can't understand why the 'power' status is not displayed in the HA.
value_template: "{{ state_attr('fan.xiaomi_airfresh', 'power') }}"For example, this value_template: "{{ state_attr('fan.xiaomi_airfresh', 'co2') }}" works fine.

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

Because it's not exposed as attribute. It's the state of the entity.

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

@syssi You're right. Added.

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

@syssi Added more commands vartom@a80be99

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

@syssi Can you see what's wrong here?

2020-11-05 20:18:17 ERROR (MainThread) [homeassistant.components.automation.air_fresh_ptc_level_change] Air Fresh ptc level change: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['level']

- alias: Air Fresh ptc level change
  trigger:
    entity_id: input_select.xiaomi_airfresh_level
    platform: state
  action:
    service: xiaomi_miio_airpurifier.fan_set_ptc_level
    data_template:
      entity_id: fan.xiaomi_airfresh
      level: '{{ states(''input_select.xiaomi_airfresh_level'') | capitalize }}'
- alias: Air Fresh ptc level changed
  trigger:
    platform: state
    entity_id: fan.xiaomi_airfresh
  action:
    service: input_select.select_option
    entity_id: input_select.xiaomi_airfresh_level
    data_template:
      option: '{{ state_attr(''fan.xiaomi_airfresh'', ''level'') | capitalize }}'

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

The component doesn't have a fan_set_ptc_level service right now and the T2017 isn't supported too. What did you do to support your device? Did you change the compoent or do you use another model name?

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

Added more commands to fan.py vartom/xiaomi_airpurifier@a80be99

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

Got it. You are working with a fork. You have to implement a new service to control the PTC.

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

set_favorite_speed works fine

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

If you prepare a PR already as draft I can help to bring your feature branch forward.

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

If you prepare a PR already as draft I can help to bring your feature branch forward.

What do you have in mind?

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

Goto "https://github.com/syssi/xiaomi_airpurifier/pulls" and create a new pull request of your feature branch. As soon you have created a PR I've access to your repository to improve your code.

@vartom
Copy link
Contributor

vartom commented Nov 5, 2020

input_select:

Xiaomi Air Fresh

xiaomi_airfresh_level:
name: "Level"
options:
- Low
- Medium
- High
icon: "mdi:animation-outline"

  • alias: Air Fresh ptc level change
    trigger:
    entity_id: input_select.xiaomi_airfresh_level
    platform: state
    action:
    service: xiaomi_miio_airpurifier.fan_set_ptc_level
    data_template:
    entity_id: fan.xiaomi_airfresh
    level: '{{ states(''input_select.xiaomi_airfresh_level'') | capitalize }}'
  • alias: Air Fresh ptc level changed
    trigger:
    platform: state
    entity_id: fan.xiaomi_airfresh
    action:
    service: input_select.select_option
    entity_id: input_select.xiaomi_airfresh_level
    data_template:
    option: '{{ state_attr(''fan.xiaomi_airfresh'', ''ptc_level'') | capitalize }}'

2020-11-06 00:55:59 ERROR (MainThread) [homeassistant.components.automation.air_fresh_ptc_level_change] Air Fresh ptc level change: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['level']

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

I will fix this issue in the next hour or two.

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

I've pushed a fix. Please give it a try.

@syssi
Copy link
Owner

syssi commented Nov 5, 2020

We are done. I've added a fan_set_display_orientation service. I don't want to implement the ptc_timer right now. So this device support is nearly feature complete now. Could you care about the testing?

@vartom
Copy link
Contributor

vartom commented Nov 6, 2020

We are done. I've added a fan_set_display_orientation service. I don't want to implement the ptc_timer right now. So this device support is nearly feature complete now. Could you care about the testing?

I can check in ten to eleven hours.

@vartom
Copy link
Contributor

vartom commented Nov 6, 2020

It worked twice right after the fix and after the next restart the server stopped working.
Something is wrong, heating control does not work( set_ptc_level). No errors in logs.

@syssi
Copy link
Owner

syssi commented Nov 7, 2020

@vartom Thanks for the fix! Good catch!

@ps1x
Copy link

ps1x commented Nov 8, 2020

Any idea why i'm getting this? I tried both fan and climate platform. I'm on latest develop branch.

Invalid config for [climate.xiaomi_miio_airpurifier]: value is not allowed for dictionary value @ data['model']. Got 'dmaker.airfresh.t2017'. (See ?, line ?).
14:48:38 – Hass.io (ERROR)

Tried to search for dmaker:

root@homeassistant:/usr/share/hassio/homeassistant/custom_components/xiaomi_airpurifier# ag dmaker ./
custom_components/xiaomi_miio_airpurifier/fan.py
117:MODEL_AIRFRESH_T2017 = "dmaker.airfresh.t2017"
125:MODEL_FAN_P5 = "dmaker.fan.p5"

Config entry:

fan:
  - platform: xiaomi_miio_airpurifier
    name: Xiaomi Air Fresh
    host: 192.168.31.36
    token: xxxxx
    model: dmaker.airfresh.t2017

@syssi
Copy link
Owner

syssi commented Nov 8, 2020

There is no official release supporting the device yet. I will prepare a new release as soon the underlying library (python-miio 0.5.4) is released.

@ps1x
Copy link

ps1x commented Nov 8, 2020

Oh :D that's pretty confusing as it is in the readme already, can't wait for release!

@skvalex
Copy link
Contributor

skvalex commented Nov 15, 2020

@syssi, thanks for the version 0.6.2. It works perfect with the config provided below. Although, few services are incorrect in the readme. They should be changed from
xiaomi_miio_airpurifier.async_set_favorite_speed to xiaomi_miio_airpurifier.fan_set_favorite_speed, from
xiaomi_miio_airpurifier.async_set_ptc_level to xiaomi_miio_airpurifier.fan_set_ptc_level.

fan:
  - platform: xiaomi_miio_airpurifier
    name: Xiaomi Fresh Air Ventilator
    host: <ip address>
    token: 00000000000000000000000000000000
    model: dmaker.airfresh.t2017

switch:
  - platform: template
    switches:
      xiaomi_fresh_air_ventilator_display:
        friendly_name: "Display"
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'display', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_display_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_display_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: "mdi:lightbulb-outline"
      xiaomi_fresh_air_ventilator_child_lock:
        friendly_name: "Child lock"
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'child_lock', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_child_lock_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_child_lock_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: "mdi:lock-outline"
      xiaomi_fresh_air_ventilator_buzzer:
        friendly_name: "Buzzer"
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'buzzer', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_buzzer_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_buzzer_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: "mdi:volume-off"
      xiaomi_fresh_air_ventilator_ptc:
        friendly_name: "PTC"
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'ptc', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_ptc_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_ptc_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: "mdi:fire"
  
sensor:
  - platform: template
    sensors:
      xiaomi_fresh_air_ventilator_co2:
        friendly_name: CO²
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.co2 }}'
        unit_of_measurement: 'ppm'
        icon_template: mdi:weather-windy
      xiaomi_fresh_air_ventilator_pm25:
        friendly_name: PM2.5
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.pm25 }}'
        unit_of_measurement: 'µg/m³'
        icon_template: mdi:weather-hail
      xiaomi_fresh_air_ventilator_temperature:
        friendly_name: Temperature
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.temperature }}'
        unit_of_measurement: '°C'
        icon_template: mdi:thermometer
      xiaomi_fresh_air_ventilator_favorite_speed:
        friendly_name: Favorite speed
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.favorite_speed }}'
      xiaomi_fresh_air_ventilator_ptc_status:
        friendly_name: PTC status
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.ptc_status }}'
      xiaomi_fresh_air_ventilator_dust_filter_life_remaining:
        friendly_name: Dust filter life remaining
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.dust_filter_life_remaining }}'
        unit_of_measurement: '%'
      xiaomi_fresh_air_ventilator_dust_filter_life_remaining_days:
        friendly_name: Dust filter life remaining days
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.dust_filter_life_remaining_days }}'
      xiaomi_fresh_air_ventilator_upper_filter_life_remaining:
        friendly_name: Upper filter life remaining
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.upper_filter_life_remaining }}'
        unit_of_measurement: '%'
      xiaomi_fresh_air_ventilator_upper_filter_life_remaining_days:
        friendly_name: Upper filter life remaining days
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.upper_filter_life_remaining_days }}'

input_number:
  xiaomi_fresh_air_ventilator_favorite_speed:
    name: Favorite speed
    initial: 60
    min: 60
    max: 300
    step: 4

input_select:
  xiaomi_fresh_air_ventilator_ptc_level:
    name: PTC level
    options:
     - Low
     - Medium
     - High

automation:
  - alias: Select favorite speed by slider
    trigger:
      platform: state
      entity_id: input_number.xiaomi_fresh_air_ventilator_favorite_speed
    action:
      - service: xiaomi_miio_airpurifier.fan_set_favorite_speed
        data_template:
          entity_id: fan.xiaomi_fresh_air_ventilator
          speed: '{{ states.input_number.xiaomi_fresh_air_ventilator_favorite_speed.state|int }}'

  - alias: Monitor favorite speed and update slider
    trigger:
      platform: state
      entity_id: sensor.xiaomi_fresh_air_ventilator_favorite_speed
    action:
      service: input_number.set_value
      entity_id: input_number.xiaomi_fresh_air_ventilator_favorite_speed
      data_template:
        value: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.favorite_speed }}'

  - alias: Select PTC level by input select
    trigger:
      entity_id: input_select.xiaomi_fresh_air_ventilator_ptc_level
      platform: state
    action:
      service: xiaomi_miio_airpurifier.fan_set_ptc_level
      data_template:
        entity_id: fan.xiaomi_fresh_air_ventilator
        level: '{{ states.input_select.xiaomi_fresh_air_ventilator_ptc_level.state }}'

  - alias: Monitor PTC level and update input select
    trigger:
      platform: state
      entity_id: fan.xiaomi_fresh_air_ventilator
    action:
      service: input_select.select_option
      entity_id: input_select.xiaomi_fresh_air_ventilator_ptc_level
      data_template:
        option: >
          {{ states.fan.xiaomi_fresh_air_ventilator.attributes.ptc_level.capitalize() }}

@syssi
Copy link
Owner

syssi commented Nov 16, 2020

@skvalex I added you advanced configuration example here: https://github.com/syssi/xiaomi_airpurifier/blob/develop/docs/dmaker-airfresh-t2017.md

I'm happy if you provide some YAML markup and a screenshot of your lovelace setup.

@syssi syssi closed this as completed Nov 16, 2020
@skvalex
Copy link
Contributor

skvalex commented Nov 16, 2020

@syssi here's the complete config for this device:

fan:
  - platform: xiaomi_miio_airpurifier
    name: Xiaomi Fresh Air Ventilator
    host: <IP_ADDRESS>
    token: <TOKEN>
    model: dmaker.airfresh.t2017

switch:
  - platform: template
    switches:
      xiaomi_fresh_air_ventilator_display:
        friendly_name: Display
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'display', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_display_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_display_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: mdi:lightbulb-outline
      xiaomi_fresh_air_ventilator_child_lock:
        friendly_name: Child lock
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'child_lock', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_child_lock_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_child_lock_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: mdi:lock-outline
      xiaomi_fresh_air_ventilator_buzzer:
        friendly_name: Buzzer
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'buzzer', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_buzzer_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_buzzer_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: mdi:volume-high
      xiaomi_fresh_air_ventilator_ptc:
        friendly_name: PTC
        value_template: "{{ is_state_attr('fan.xiaomi_fresh_air_ventilator', 'ptc', True) }}"
        turn_on:
          service: xiaomi_miio_airpurifier.fan_set_ptc_on
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        turn_off:
          service: xiaomi_miio_airpurifier.fan_set_ptc_off
          data:
            entity_id: fan.xiaomi_fresh_air_ventilator
        icon_template: mdi:fire
  
sensor:
  - platform: template
    sensors:
      xiaomi_fresh_air_ventilator_co2:
        friendly_name: CO²
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.co2 }}'
        unit_of_measurement: 'ppm'
        icon_template: mdi:molecule-co2
      xiaomi_fresh_air_ventilator_pm25:
        friendly_name: PM2.5
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.pm25 }}'
        unit_of_measurement: 'µg/m³'
        icon_template: mdi:grain
      xiaomi_fresh_air_ventilator_temperature:
        friendly_name: Temperature
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.temperature }}'
        unit_of_measurement: '°C'
        icon_template: mdi:thermometer
      xiaomi_fresh_air_ventilator_current_speed:
        friendly_name: Current speed
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.favorite_speed }}'
        icon_template: mdi:speedometer
      xiaomi_fresh_air_ventilator_ptc_status:
        friendly_name: PTC status
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.ptc_status }}'
        icon_template: mdi:lightning-bolt
      xiaomi_fresh_air_ventilator_dust_filter_life_remaining:
        friendly_name: Dust filter life remaining
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.dust_filter_life_remaining }}'
        unit_of_measurement: '%'
        icon_template: mdi:air-filter
      xiaomi_fresh_air_ventilator_dust_filter_life_remaining_days:
        friendly_name: Dust filter life remaining days
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.dust_filter_life_remaining_days }}'
        icon_template: mdi:air-filter
      xiaomi_fresh_air_ventilator_upper_filter_life_remaining:
        friendly_name: Upper filter life remaining
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.upper_filter_life_remaining }}'
        unit_of_measurement: '%'
        icon_template: mdi:air-filter
      xiaomi_fresh_air_ventilator_upper_filter_life_remaining_days:
        friendly_name: Upper filter life remaining days
        value_template: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.upper_filter_life_remaining_days }}'
        icon_template: mdi:air-filter

input_number:
  xiaomi_fresh_air_ventilator_favorite_speed:
    name: Favorite speed
    icon: mdi:weather-windy
    initial: 60
    min: 60
    max: 300
    step: 4

input_select:
  xiaomi_fresh_air_ventilator_mode:
    name: Operation mode
    options:
      - Auto
      - Sleep
      - Favorite
  xiaomi_fresh_air_ventilator_ptc_level:
    name: PTC level
    options:
     - Low
     - Medium
     - High
  xiaomi_fresh_air_ventilator_display_orientation:
    name: Display orientation
    icon: mdi:screen-rotation
    options:
      - Portrait
      - LandscapeLeft
      - LandscapeRight

automation:
  - alias: Select favorite speed by slider
    trigger:
      platform: state
      entity_id: input_number.xiaomi_fresh_air_ventilator_favorite_speed
    action:
      - service: xiaomi_miio_airpurifier.fan_set_favorite_speed
        data_template:
          entity_id: fan.xiaomi_fresh_air_ventilator
          speed: '{{ states.input_number.xiaomi_fresh_air_ventilator_favorite_speed.state|int }}'
          
  - alias: Select favorite speed by slider
    trigger:
      platform: state
      entity_id: input_number.xiaomi_fresh_air_ventilator_favorite_speed
    action:
      - service: xiaomi_miio_airpurifier.fan_set_favorite_speed
        data_template:
          entity_id: fan.xiaomi_fresh_air_ventilator
          speed: '{{ states.input_number.xiaomi_fresh_air_ventilator_favorite_speed.state|int }}'

  - alias: Monitor favorite speed and update slider
    trigger:
      platform: state
      entity_id: sensor.xiaomi_fresh_air_ventilator_favorite_speed
    action:
      service: input_number.set_value
      entity_id: input_number.xiaomi_fresh_air_ventilator_favorite_speed
      data_template:
        value: '{{ states.fan.xiaomi_fresh_air_ventilator.attributes.favorite_speed }}'

  - alias: Select PTC level by input select
    trigger:
      entity_id: input_select.xiaomi_fresh_air_ventilator_ptc_level
      platform: state
    action:
      service: xiaomi_miio_airpurifier.fan_set_ptc_level
      data_template:
        entity_id: fan.xiaomi_fresh_air_ventilator
        level: '{{ states.input_select.xiaomi_fresh_air_ventilator_ptc_level.state }}'

  - alias: Monitor PTC level and update input select
    trigger:
      platform: state
      entity_id: fan.xiaomi_fresh_air_ventilator
    action:
      service: input_select.select_option
      entity_id: input_select.xiaomi_fresh_air_ventilator_ptc_level
      data_template:
        option: >
          {{ states.fan.xiaomi_fresh_air_ventilator.attributes.ptc_level.capitalize() }}
  - alias: Select operation mode by input select
    trigger:
      entity_id: input_select.xiaomi_fresh_air_ventilator_mode
      platform: state
    action:
      service: fan.set_speed
      data_template:
        entity_id: fan.xiaomi_fresh_air_ventilator
        speed: '{{ states.input_select.xiaomi_fresh_air_ventilator_mode.state }}'
  - alias: Monitor operation mode and update input select
    trigger:
      platform: state
      entity_id: fan.xiaomi_fresh_air_ventilator
    action:
      service: input_select.select_option
      entity_id: input_select.xiaomi_fresh_air_ventilator_mode
      data_template:
        option: >
          {{ states.fan.xiaomi_fresh_air_ventilator.attributes.speed }}
  - alias: Select display orientation by input select
    trigger:
      entity_id: input_select.xiaomi_fresh_air_ventilator_display_orientation
      platform: state
    action:
      service: xiaomi_miio_airpurifier.fan_set_display_orientation
      data_template:
        entity_id: fan.xiaomi_fresh_air_ventilator
        display_orientation: '{{ states.input_select.xiaomi_fresh_air_ventilator_display_orientation.state }}'
  - alias: Monitor display orientation and update input select
    trigger:
      platform: state
      entity_id: fan.xiaomi_fresh_air_ventilator
    action:
      service: input_select.select_option
      entity_id: input_select.xiaomi_fresh_air_ventilator_display_orientation
      data_template:
        option: >
          {% if is_state_attr("fan.xiaomi_fresh_air_ventilator", "display_orientation", "left") -%}
            LandscapeLeft
          {%- elif is_state_attr("fan.xiaomi_fresh_air_ventilator", "display_orientation", "right") -%}
            LandscapeRight
          {%- else -%}
            Portrait
          {%- endif %}

Here's the lovelace screenshot and the config itself:

type: entities
entities:
  - entity: fan.xiaomi_fresh_air_ventilator
  - entity: input_select.xiaomi_fresh_air_ventilator_mode
  - entity: input_number.xiaomi_fresh_air_ventilator_favorite_speed
  - entity: switch.xiaomi_fresh_air_ventilator_ptc
  - entity: input_select.xiaomi_fresh_air_ventilator_ptc_level
  - entity: sensor.xiaomi_fresh_air_ventilator_ptc_status
  - entity: sensor.xiaomi_fresh_air_ventilator_current_speed
  - entity: sensor.xiaomi_fresh_air_ventilator_co2
  - entity: sensor.xiaomi_fresh_air_ventilator_pm25
  - entity: sensor.xiaomi_fresh_air_ventilator_temperature
  - entity: switch.xiaomi_fresh_air_ventilator_display
  - entity: switch.xiaomi_fresh_air_ventilator_child_lock
  - entity: switch.xiaomi_fresh_air_ventilator_buzzer
  - entity: input_select.xiaomi_fresh_air_ventilator_display_orientation
  - entity: sensor.xiaomi_fresh_air_ventilator_dust_filter_life_remaining
  - entity: sensor.xiaomi_fresh_air_ventilator_upper_filter_life_remaining
  - entity: sensor.xiaomi_fresh_air_ventilator_dust_filter_life_remaining_days
  - entity: sensor.xiaomi_fresh_air_ventilator_upper_filter_life_remaining_days

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

No branches or pull requests