『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 13824|回复: 13

两台净化器接入

[复制链接]

3

主题

78

帖子

467

积分

中级会员

Rank: 3Rank: 3

积分
467
金钱
389
HASS币
0
发表于 2018-3-9 16:58:42 | 显示全部楼层 |阅读模式
本帖最后由 lyibai 于 2018-3-16 14:46 编辑

参考Jones发表的[url=[环境健康] 最新小米空气净化器2代接入HASS方法及HA控制面板][环境健康] 最新小米空气净化器2代接入HASS方法及HA控制面板[/url]的帖子,实现了一台设备接入,但是家里有两台空净,自己是个编程小白,研究了半天并且咨询了论坛里的大牛,现实现两台空气净化使用帖子里的方法同时接入,但是模式无法调整,现发出来大家共同讨论参考一下,如那位可以看出问题烦请予以指导。---问题已经解决,感谢Jones的帖子。
无标题.png
代码如下:代码做了标注防止其他兄弟再走弯路。
# 空气净化器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状态设置








回复

使用道具 举报

25

主题

687

帖子

3630

积分

论坛元老

Rank: 8Rank: 8

积分
3630
金钱
2937
HASS币
219

活跃会员

发表于 2018-3-10 07:22:50 | 显示全部楼层
模式代码也要两个
input_select:
  xiaomi_ap_mode2:
    name: 模式
    icon: mdi:fan
    options:
      - "自动"
      - "睡眠"
      - "最爱"
      - "待机"
  xiaomi_ap_led2:
    name: LED灯
    icon: mdi:led-on
    options:
      - "亮光"
      - "微光"
      - "关闭"
回复

使用道具 举报

3

主题

78

帖子

467

积分

中级会员

Rank: 3Rank: 3

积分
467
金钱
389
HASS币
0
 楼主| 发表于 2018-3-10 12:04:55 | 显示全部楼层
aktifin 发表于 2018-3-10 07:22
模式代码也要两个
input_select:
  xiaomi_ap_mode2:

试了以下还是不行
回复

使用道具 举报

4

主题

76

帖子

636

积分

高级会员

Rank: 4

积分
636
金钱
560
HASS币
0
发表于 2018-4-7 21:58:11 | 显示全部楼层
你们的automation会不会报错
回复

使用道具 举报

3

主题

78

帖子

467

积分

中级会员

Rank: 3Rank: 3

积分
467
金钱
389
HASS币
0
 楼主| 发表于 2018-4-8 18:10:31 | 显示全部楼层
xihulu 发表于 2018-4-7 21:58
你们的automation会不会报错

刚开始会,排查一下,简单修改一下就好了
回复

使用道具 举报

4

主题

76

帖子

636

积分

高级会员

Rank: 4

积分
636
金钱
560
HASS币
0
发表于 2018-4-8 21:27:02 | 显示全部楼层
lyibai 发表于 2018-4-8 18:10
刚开始会,排查一下,简单修改一下就好了

Invalid config for [automation]: required key not provided @ data['action']. Got None required key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/

这个怎样解决的呢
回复

使用道具 举报

0

主题

9

帖子

71

积分

注册会员

Rank: 2

积分
71
金钱
62
HASS币
0
发表于 2019-3-2 18:29:11 | 显示全部楼层
trigger的platform写法不对,
  trigger:
    platform: time_pattern
    seconds: '/5'
回复

使用道具 举报

0

主题

9

帖子

71

积分

注册会员

Rank: 2

积分
71
金钱
62
HASS币
0
发表于 2019-3-2 18:34:09 | 显示全部楼层
    - sensor.xiaomi_ap_filter_usedpro
    - sensor.xiaomi_ap_filter_lifepro

这两个获取不到,提示实例不存在,有人知道是因为什么吗?
回复

使用道具 举报

4

主题

47

帖子

203

积分

中级会员

Rank: 3Rank: 3

积分
203
金钱
156
HASS币
0
发表于 2020-2-27 02:53:48 | 显示全部楼层
自己摸索的,模式可以选择。


屏幕快照 2020-02-27 上午2.49.14.png


回复

使用道具 举报

0

主题

4

帖子

28

积分

新手上路

Rank: 1

积分
28
金钱
24
HASS币
0
发表于 2020-4-17 00:50:23 | 显示全部楼层
解决了吗?我有3台要接入
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-26 18:24 , Processed in 0.107746 second(s), 41 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表