本帖最后由 lyibai 于 2018-3-16 14:46 编辑
参考Jones 发表的[url=[环境健康] 最新小米空气净化器2代接入HASS方法及HA控制面板][环境健康] 最新小米空气净化器2代接入HASS方法及HA控制面板[/url]的帖子,实现了一台设备接入,但是家里有两台空净,自己是个编程小白,研究了半天并且咨询了论坛里的大牛,现实现两台空气净化使用帖子里的方法同时接入,但是模式无法调整,现发出来大家共同讨论参考一下,如那位可以看出问题烦请予以指导。---问题已经解决,感谢Jones的帖子。
代码如下:代码做了标注防止其他兄弟再走弯路。
# 空气净化器2fan:
- platform: xiaomi_miio
name: Xiaomi Air Purifier 2
host:
token:
- platform: xiaomi_miio
name: Xiaomi Air Purifier Pro
host:
token:
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: "%"
# 空气净化器pro部分
xiaomi_ap_aqipro:
friendly_name: 空气质量
value_template: "{{ states.fan.xiaomi_air_purifier_pro.attributes.aqi }}"
unit_of_measurement: AQI
xiaomi_ap_temppro:
friendly_name: 温度
value_template: "{{ states.fan.xiaomi_air_purifier_pro.attributes.temperature }}"
unit_of_measurement: °C
xiaomi_ap_humidpro:
friendly_name: 湿度
value_template: "{{ states.fan.xiaomi_air_purifier_pro.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
#空气净化器pro部分
xiaomi_ap_buzzerpro:
value_template: "{{ is_state_attr('fan.xiaomi_air_purifier_pro', 'buzzer', true) }}"
turn_on:
service: airpurifier.set_buzzer_on
entity_id: fan.xiaomi_air_purifier_pro
turn_off:
service: airpurifier.set_buzzer_off
entity_id: fan.xiaomi_air_purifier_pro
input_select:
xiaomi_ap_mode:
name: 模式
icon: mdi:fan
options:
- "自动"
- "睡眠"
- "最爱"
- "待机"
xiaomi_ap_led:
name: LED灯
icon: mdi:led-on
options:
- "亮光"
- "微光"
- "关闭"
xiaomi_ap_modepro:
name: 模式
icon: mdi:fan
options:
- "自动"
- "睡眠"
- "最爱"
- "待机"
xiaomi_ap_ledpro:
name: LED灯
icon: mdi:led-on
options:
- "亮光"
- "微光"
- "关闭"
group:
xiaomi_air_purifier:
name: 小米空净2
view: no
control: hidden
entities:
- fan.xiaomi_air_purifier_2
- switch.xiaomi_ap_buzzer
- 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.xiaomi_ap_get_mode
- automation.xiaomi_ap_set_mode
- automation.xiaomi_ap_get_led
- automation.xiaomi_ap_set_led
#空气净化器Pro部分
xiaomi_air_purifiepro:
name: 小米空净Pro
view: no
control: hidden
entities:
- fan.xiaomi_air_purifier_pro
- switch.xiaomi_ap_buzzerpro
- sensor.xiaomi_ap_aqipro
- sensor.xiaomi_ap_temppro
- sensor.xiaomi_ap_humidpro
- sensor.xiaomi_ap_filter_usedpro
- sensor.xiaomi_ap_filter_lifepro
- input_select.xiaomi_ap_modepro
- input_select.xiaomi_ap_ledpro
- automation.xiaomi_ap_get_modepro
- automation.xiaomi_ap_set_modepro
- automation.xiaomi_ap_get_ledpro
- automation.xiaomi_ap_set_ledpro
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_get_modepro
initial_state: true
trigger:
platform: time
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.xiaomi_ap_modepro
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: xiaomi_ap_set_modepro
initial_state: true
trigger:
platform: state
entity_id: input_select.xiaomi_ap_modepro
action:
service: fan.turn_on
data_template:
entity_id: fan.xiaomi_air_purifier_pro
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: 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_get_ledpro
initial_state: true
trigger:
platform: time
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.xiaomi_ap_ledpro
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:
platform: state
entity_id: input_select.xiaomi_ap_led
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 %}
- alias: xiaomi_ap_set_ledpro
initial_state: true
trigger:
platform: state
entity_id: input_select.xiaomi_ap_ledpro
action:
service: airpurifier.set_led_brightness
data_template:
entity_id: fan.xiaomi_air_purifier_pro
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:
homebridge_hidden: true
friendly_name: 空净开关
extra_badge:
entity_id: sensor.xiaomi_ap_aqi
extra_data_template: 滤芯已用${attributes.filter_hours_used}小时,剩余${attributes.filter_life_remaining}%
switch.xiaomi_ap_buzzer:
homebridge_hidden: true
icon: mdi:volume-high
friendly_name: 提示音
sensor.xiaomi_ap_aqi:
homebridge_hidden: true
icon: mdi:blur
sensor.xiaomi_ap_humid:
homebridge_hidden: true
icon: mdi:water-percent
automation.xiaomi_ap_get_mode:
homebridge_hidden: true
friendly_name: 模式状态获取
automation.xiaomi_ap_set_mode:
homebridge_hidden: true
friendly_name: 模式状态设置
automation.xiaomi_ap_get_led:
homebridge_hidden: true
friendly_name: LED状态获取
automation.xiaomi_ap_set_led:
homebridge_hidden: true
friendly_name: LED状态设置
#空气净化器Pro
fan.xiaomi_air_purifier_pro:
friendly_name: 空净开关
homebridge_hidden: true
extra_badge:
entity_id: sensor.xiaomi_ap_aqipro
extra_data_template: 滤芯已用${attributes.filter_hours_used}小时,剩余${attributes.filter_life_remaining}%
switch.xiaomi_ap_buzzerpro:
homebridge_hidden: true
icon: mdi:volume-high
friendly_name: 提示音
sensor.xiaomi_ap_aqipro:
homebridge_hidden: true
icon: mdi:blur
sensor.xiaomi_ap_humidpro:
homebridge_hidden: true
icon: mdi:water-percent
automation.xiaomi_ap_get_modepro:
homebridge_hidden: true
friendly_name: 模式状态获取
automation.xiaomi_ap_set_modepro:
homebridge_hidden: true
friendly_name: 模式状态设置
automation.xiaomi_ap_get_ledpro:
homebridge_hidden: true
friendly_name: LED状态获取
automation.xiaomi_ap_set_ledpro:
homebridge_hidden: true
friendly_name: LED状态设置
复制代码