|
自从作为小白一名入坑以来,一直在论坛上学习,目前也初步有了一点小进步,基于Jones神的最新小米空气净化器2代接入HASS方法及HA控制面板(原帖地址:https://bbs.hassbian.com/thread-1657-1-1.html)。我在Jones神的基础上,改进了两点,也不知道对不对,发上来请大家批评。一是我个人觉得小米空净的led选择亮度意义不大,所以我改成了一个开关。二是我加了两个自动化,在AQI高于120的时候,空净自动打开为Auto模式,AQI低于80的时候,空净自动关闭,用来节电。三是把不用的自动化都给隐藏了。作为一名小白,从来不敢在论坛发帖子,也没发过帖子,不会上传附件,我直接把代码贴上来算了,排版不好,请大家批评。
sensor:
- platform: template
sensors:
xiaomi_ap_aqi:
friendly_name: 空气质量
value_template: "{{ states.fan.xiaomi_air_purifier_2.attributes.aqi }}"
unit_of_measurement: AQI
xiaomi_ap_temp:
friendly_name: 温度
value_template: "{{ states.fan.xiaomi_air_purifier_2.attributes.temperature }}"
unit_of_measurement: °C
xiaomi_ap_humid:
friendly_name: 湿度
value_template: "{{ states.fan.xiaomi_air_purifier_2.attributes.humidity }}"
unit_of_measurement: "%"
switch:
- platform: template
switches:
xiaomi_ap_buzzer:
value_template: "{{ is_state_attr('fan.xiaomi_air_purifier_2', 'buzzer', true) }}"
turn_on:
service: airpurifier.set_buzzer_on
entity_id: fan.xiaomi_air_purifier_2
turn_off:
service: airpurifier.set_buzzer_off
entity_id: fan.xiaomi_air_purifier_2
xiaomi_ap_led:
value_template: "{{ is_state_attr('fan.xiaomi_air_purifier_2', 'led', true) }}"
turn_on:
service: fan.xiaomi_miio_set_led_on
entity_id: fan.xiaomi_air_purifier_2
turn_off:
service: fan.xiaomi_miio_set_led_off
entity_id: fan.xiaomi_air_purifier_2
input_select:
xiaomi_ap_mode:
name: 模式
icon: mdi:fan
options:
- "自动"
- "睡眠"
- "最爱"
- "待机"
# xiaomi_ap_led:
# name: LED灯
# icon: mdi:led-on
# options:
# - "亮光"
# - "微光"
# - "关闭"
group:
xiaomi_air_purifier:
name: 小米空净
view: no
control: hidden
entities:
- fan.xiaomi_air_purifier_2
- switch.xiaomi_ap_buzzer
- switch.xiaomi_ap_led
#- sensor.xiaomi_ap_aqi
- sensor.xiaomi_ap_temp
- sensor.xiaomi_ap_humid
- sensor.xiaomi_ap_filter_used
- sensor.xiaomi_ap_filter_life
- input_select.xiaomi_ap_mode
# - input_select.xiaomi_ap_led
automation:
- alias: xiaomi_ap_get_mode
initial_state: true
trigger:
platform: time
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.xiaomi_ap_mode
option: >
{% if states.fan.xiaomi_air_purifier_2.attributes.mode == "auto" %}自动
{% elif states.fan.xiaomi_air_purifier_2.attributes.mode == "silent" %}睡眠
{% elif states.fan.xiaomi_air_purifier_2.attributes.mode == "favorite" %}最爱
{% elif states.fan.xiaomi_air_purifier_2.attributes.mode == "idle" %}待机
{% endif %}
- alias: xiaomi_ap_set_mode
initial_state: true
trigger:
platform: state
entity_id: input_select.xiaomi_ap_mode
action:
service: fan.turn_on
data_template:
entity_id: fan.xiaomi_air_purifier_2
speed: >
{% if states.input_select.xiaomi_ap_mode.state == "自动" %}Auto
{% elif states.input_select.xiaomi_ap_mode.state == "睡眠" %}Silent
{% elif states.input_select.xiaomi_ap_mode.state == "最爱" %}Favorite
{% elif states.input_select.xiaomi_ap_mode.state == "待机" %}Idle
{% endif %}
- alias: xiaomiap_aotu_turnon #api高于120自动启动,速度定位aoto
initial_state: true
trigger:
platform: numeric_state
entity_id: fan.xiaomi_air_purifier_2
value_template: '{{ state.attributes.aqi }}'
above: 120
condition:
- condition: state
entity_id: fan.xiaomi_air_purifier_2
state: 'off'
action:
service: fan.turn_on
data_template:
entity_id: fan.xiaomi_air_purifier_2
speed: Auto
- alias: xiaomiap_aotu_turnoff #api低于80自动关闭,节约用电
initial_state: true
trigger:
platform: numeric_state
entity_id: fan.xiaomi_air_purifier_2
value_template: '{{ state.attributes.aqi }}'
below: 80
condition:
- condition: state
entity_id: fan.xiaomi_air_purifier_2
state: 'on'
action:
service: fan.turn_off
data_template:
entity_id: fan.xiaomi_air_purifier_2
# - alias: xiaomi_ap_get_led
# initial_state: true
# trigger:
# platform: time
# seconds: /5
# action:
# service: input_select.select_option
# data_template:
# entity_id: input_select.xiaomi_ap_led
# option: >
# {% if states.fan.xiaomi_air_purifier_2.attributes.led_brightness == 0 %}亮光
# {% elif states.fan.xiaomi_air_purifier_2.attributes.led_brightness == 1 %}微光
# {% elif states.fan.xiaomi_air_purifier_2.attributes.led_brightness == 2 %}关闭
# {% endif %}
# - alias: xiaomi_ap_set_led
# initial_state: true
# trigger:
# action:
# service: airpurifier.set_led_brightness
# data_template:
# entity_id: fan.xiaomi_air_purifier_2
# brightness: >
# {% if states.input_select.xiaomi_ap_led.state == "亮光" %}0
# {% elif states.input_select.xiaomi_ap_led.state == "微光" %}1
# {% elif states.input_select.xiaomi_ap_led.state == "关闭" %}2
# {% endif %}
homeassistant:
customize:
fan.xiaomi_air_purifier_2:
friendly_name: 空净开关
homebridge_name: 空净开关
homebridge_visible: true
extra_badge:
entity_id: sensor.xiaomi_ap_aqi
extra_data_template: 滤芯已用${attributes.filter_hours_used}小时,剩余${attributes.filter_life_remaining}%
switch.xiaomi_ap_buzzer:
icon: mdi:volume-high
friendly_name: 提示音
switch.xiaomi_ap_led:
icon: mdi:led-on
friendly_name: 指示灯
sensor.xiaomi_ap_aqi:
icon: mdi:blur
homebridge_visible: true
homebridge_name: 客厅空气质量
sensor.xiaomi_ap_humid:
friendly_name: 客厅湿度
icon: mdi:water-percent
homebridge_visible: true
homebridge_name: 客厅湿度
sensor.xiaomi_ap_temp:
friendly_name: 客厅温度
homebridge_visible: true
homebridge_name: 客厅温度
automation.xiaomi_ap_get_mode:
hidden: true
automation.xiaomi_ap_set_mode:
hidden: true
automation.xiaomiap_aotu_turnon:
hidden: true
automation.xiaomiap_aotu_turnoff:
hidden: true
|
评分
-
查看全部评分
|