Skip to content

Instantly share code, notes, and snippets.

@Rainsting
Created December 2, 2020 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rainsting/a3261da600314f11ed7ff1c0f34647be to your computer and use it in GitHub Desktop.
Save Rainsting/a3261da600314f11ed7ff1c0f34647be to your computer and use it in GitHub Desktop.
小米空氣濾清器 2 with Home HA 設定檔
fan:
- platform: xiaomi_airpurifier
name: zhuwomiap
host: 192.168.*0.*
token: bf4*******************
sensor:
- platform: template
sensors:
zhuwomiap_aqi:
friendly_name: 空氣品質
value_template: "{{ states.fan.zhuwomiap.attributes.aqi }}"
unit_of_measurement: AQI
zhuwomiap_temp:
friendly_name: 溫度
value_template: "{{ states.fan.zhuwomiap.attributes.temperature }}"
unit_of_measurement: °C
zhuwomiap_humid:
friendly_name: 濕度
value_template: "{{ states.fan.zhuwomiap.attributes.humidity }}"
unit_of_measurement: "%"
switch:
- platform: template
switches:
zhuwomiap_buzzer:
value_template: "{{ is_state_attr('fan.zhuwomiap', 'buzzer', true) }}"
turn_on:
service: airpurifier.set_buzzer_on
entity_id: fan.zhuwomiap
turn_off:
service: airpurifier.set_buzzer_off
entity_id: fan.zhuwomiap
input_select:
zhuwomiap_mode:
name: 模式
icon: mdi:fan
options:
- "自動"
- "睡眠"
- "最愛"
- "待機"
zhuwomiap_led:
name: LED燈
icon: mdi:led-on
options:
- "亮光"
- "微光"
- "關閉"
automation:
- alias: zhuwomiap_get_mode
initial_state: true
trigger:
platform: time
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.zhuwomiap_mode
option: >
{% if states.fan.zhuwomiap.attributes.mode == "auto" %}自動
{% elif states.fan.zhuwomiap.attributes.mode == "silent" %}睡眠
{% elif states.fan.zhuwomiap.attributes.mode == "favorite" %}最愛
{% elif states.fan.zhuwomiap.attributes.mode == "idle" %}待機
{% endif %}
- alias: zhuwomiap_set_mode
initial_state: true
trigger:
platform: state
entity_id: input_select.zhuwomiap_mode
action:
service: fan.turn_on
data_template:
entity_id: fan.zhuwomiap
speed: >
{% if states.input_select.zhuwomiap_mode.state == "自動" %}Auto
{% elif states.input_select.zhuwomiap_mode.state == "睡眠" %}Silent
{% elif states.input_select.zhuwomiap_mode.state == "最愛" %}Favorite
{% elif states.input_select.zhuwomiap_mode.state == "待機" %}Idle
{% endif %}
- alias: zhuwomiap_get_led
initial_state: true
trigger:
platform: time
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.zhuwomiap_led
option: >
{% if states.fan.zhuwomiap.attributes.led_brightness == 0 %}亮光
{% elif states.fan.zhuwomiap.attributes.led_brightness == 1 %}微光
{% elif states.fan.zhuwomiap.attributes.led_brightness == 2 %}關閉
{% endif %}
- alias: zhuwomiap_set_led
initial_state: true
trigger:
platform: state
entity_id: input_select.zhuwomiap_led
action:
service: airpurifier.set_led_brightness
data_template:
entity_id: fan.zhuwomiap
brightness: >
{% if states.input_select.zhuwomiap_led.state == "亮光" %}0
{% elif states.input_select.zhuwomiap_led.state == "微光" %}1
{% elif states.input_select.zhuwomiap_led.state == "關閉" %}2
{% endif %}
homeassistant:
customize:
fan.zhuwomiap:
friendly_name: 小米空濾2
extra_badge:
entity_id: sensor.zhuwomiap_aqi
extra_data_template: 濾芯已用 ${attributes.filter_hours_used} 小時,剩餘 ${attributes.filter_life_remaining}%
switch.zhuwomiap_buzzer:
icon: mdi:volume-high
friendly_name: 提示音
sensor.zhuwomiap_aqi:
icon: mdi:blur
device_class: pm25
sensor.zhuwomiap_humid:
icon: mdi:water-percent
device_class: humidity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment