本帖最后由 缥缈的孤鸿 于 2019-5-16 14:58 编辑
我就是接的2台,下边所有的组件都要对应name
fan:
- platform: xiaomi_airpurifier
name: zhuwomiap
host: 192.168.***
token: *****
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: "%"
zhuwomiap_used:
friendly_name: 滤芯用量
value_template: "{{ states.fan.zhuwomiap.attributes.filter_hours_used }}"
unit_of_measurement: '小时'
zhuwomiap_life:
friendly_name: 滤芯剩余
value_template: "{{ states.fan.zhuwomiap.attributes.filter_life_remaining }}"
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_pattern
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_pattern
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: 主卧空净
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
|