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

 找回密码
 立即注册
查看: 22853|回复: 31

小米空气净化器2代接入HA控制面板问题

[复制链接]

4

主题

92

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
226
HASS币
0
发表于 2019-1-10 04:47:19 | 显示全部楼层 |阅读模式
本帖最后由 lywcl2003 于 2019-1-10 04:48 编辑

看到Jones神的:[环境健康] 最新小米空气净化器2代接入HASS方法及HA控制面板》一贴根据提示又看了好几篇文章

大概都弄好了,界面也出来了,但是只能控制开关和提示音,模式和灯光不能控制。我的版本Home Assistant 0.84.6
已经安装了python-miio:

源文件我基本都没动,就修改了token和把airpurifier.替换成fan.xiaomi_miio_
检查配置提示:
Invalid config for [automation]: required key not provided @ data['action']. Got Nonerequired key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/


只有把automation:那部分的所有代码都删除,就不提示了,但是还是控制不了“模式”和“灯光”
而且界面显示里有个自动化面板,几个开关也不起作用。

无标题a.png


请帮我看看什么问题,谢谢

下面是我的代码:



#fan:
# - platform: xiaomi_airpurifier
# name: Xiaomi Air Purifier 2
# host: 192.168.6.143
# token: xxxxxxxxxxx

fan:
- platform: xiaomi_miio
name: Xiaomi Air Purifier 2
host: 192.168.1.206
token: 6042ccbb45811c7160fad1d9eec4d921


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: fan.xiaomi_miio_set_buzzer_on
entity_id: fan.xiaomi_air_purifier_2
turn_off:
service: fan.xiaomi_miio_set_buzzer_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
#- 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: 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:
platform: state
entity_id: input_select.xiaomi_ap_led
action:
service: fan.xiaomi_miio_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: 空净开关
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: 提示音
sensor.xiaomi_ap_aqi:
icon: mdi:blur
sensor.xiaomi_ap_humid:
icon: mdi:water-percent





回复

使用道具 举报

10

主题

680

帖子

5648

积分

论坛元老

Rank: 8Rank: 8

积分
5648
金钱
4963
HASS币
50
发表于 2019-1-10 08:11:19 | 显示全部楼层
platform改回来就可以了。
回复

使用道具 举报

1

主题

90

帖子

1066

积分

金牌会员

Rank: 6Rank: 6

积分
1066
金钱
976
HASS币
0
发表于 2019-1-10 10:42:53 | 显示全部楼层
楼主的是2还是2S?我的2S连基本的功能都无法控制啊
回复

使用道具 举报

4

主题

92

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
226
HASS币
0
 楼主| 发表于 2019-1-10 12:16:05 | 显示全部楼层
缥缈的孤鸿 发表于 2019-1-10 08:11
platform改回来就可以了。

1.在configuration.yaml增加packages: !include_dir_named packages
2.新建packages文件夹
3.在homeassistant配置文件夹下新建www/custom_ui文件夹,将官方组件文件里的 state-card-custom-ui.html 和 state-card-custom-ui.html.gz 放到/www/custom_ui/下
4.在homeassistant/custom_components文件夹下新建customizer文件夹,将官方组件文件放到customizer文件夹下;再将官方组件包里的state-card-custom-ui-es5.html 和 state-card-custom-ui-es5.html.gz 文件放到/www/custom_ui/ 文件夹下
5.在configuration.yaml里的packages: !include_dir_named packages行下面添加代码:
customize_glob:
  "*.*":
    custom_ui_state_card: state-card-custom-ui
以及下面代码:
frontend:
  extra_html_url:
     - /local/custom_ui/state-card-custom-ui.html
  extra_html_url_es5:
    - /local/custom_ui/state-card-custom-ui-es5.html
到这此检测配置是成功的。

6.在configuration.yaml文件里写入:
fan:
    #小屋空气净化器
  - platform: xiaomi_miio
    name: xiaowukongqijinghuaqi
    host: 192.168.1.206
    token: 6042ccbb45811c7160fad1d9eec4d921
    model: zhimi.airpurifier.m1

7.复制xiaomi_air_purifier.yaml文件到packages文件夹
8.修改token和IP地址
9.修改后的前几行:
fan:
  - platform: xiaomi_airpurifier
    name: Xiaomi Air Purifier 2
    host: 192.168.1.206
    token: 6042ccbb45811c7160fad1d9eec4d921
保存后检测配置提示:
Invalid config for [automation]: required key not provided @ data['action']. Got Nonerequired key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/Platform not found: fan.xiaomi_airpurifier

10.再次修改xiaomi air_purifier.yaml文件:
把  - platform: xiaomi_airpurifier改成:  - platform: xiaomi_miio保存后检测配置提示:
Invalid config for [automation]: required key not provided @ data['action']. Got Nonerequired key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/


11.把xiaomi air_purifier.yaml文件中的三处airpurifier.替换成fan.xiaomi_miio_
保存后检测配置提示:(跟没改一样)
Invalid config for [automation]: required key not provided @ data['action']. Got Nonerequired key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/


说了这么多,请问platform在哪里改回来,怎么改?
回复

使用道具 举报

4

主题

92

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
226
HASS币
0
 楼主| 发表于 2019-1-10 12:22:20 | 显示全部楼层
本帖最后由 lywcl2003 于 2019-1-10 12:24 编辑
kleinsoul 发表于 2019-1-10 10:42
楼主的是2还是2S?我的2S连基本的功能都无法控制啊

我的是小米空气净化器2,你需要参考如下帖子:
最新小米空气净化器2代接入HASS方法及HA控制面板
HA0.57【及以上版本】的custom UI简易安装教程
新手必备技能 【package】【检测配置】





回复

使用道具 举报

4

主题

92

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
226
HASS币
0
 楼主| 发表于 2019-1-10 12:37:34 | 显示全部楼层
本帖最后由 lywcl2003 于 2019-1-10 12:44 编辑
缥缈的孤鸿 发表于 2019-1-10 08:11
platform改回来就可以了。

最新发现:就按照我4楼的操作后重启后,小米空净的面板上的功能都可以用了,自动化一栏的开关也有效了,但是:重启服务失效了,只能去群晖里关掉容器开关再打开才能重启?
无标题b.png

无标题c.png
回复

使用道具 举报

10

主题

680

帖子

5648

积分

论坛元老

Rank: 8Rank: 8

积分
5648
金钱
4963
HASS币
50
发表于 2019-1-10 13:22:57 | 显示全部楼层
贴上我的配置供参考
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: 卧室空净
      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


回复

使用道具 举报

4

主题

92

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
226
HASS币
0
 楼主| 发表于 2019-1-10 14:34:13 | 显示全部楼层
本帖最后由 lywcl2003 于 2019-1-10 14:35 编辑
缥缈的孤鸿 发表于 2019-1-10 13:22
贴上我的配置供参考[code]fan:
  - platform: xiaomi_airpurifier
    name: zhuw ...

非常感谢。
你的文件当中与我的有几处不同
1.你的:platform: xiaomi_airpurifier;我的:platform: xiaomi_miio
2.你的:name: zhuwomiap;我的:name: Xiaomi Air Purifier 2
3.你的缺少这一段:
group:
  xiaomi_air_purifier:
    name: 小米空净
    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

4.你的最后几行比我多了两行:

      device_class: pm25

      device_class: humidity

5.根据你的文件逐条更改尝试,均无效、
一直提示:
Invalid config for [automation]: required key not provided @ data['action']. Got Nonerequired key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/
6.如去掉group:这一段的话,我的前台界面就改变了,开关分部到好几个位置,有些开关失效同样无法重启服务



回复

使用道具 举报

10

主题

680

帖子

5648

积分

论坛元老

Rank: 8Rank: 8

积分
5648
金钱
4963
HASS币
50
发表于 2019-1-10 14:35:29 | 显示全部楼层
你需要改动的就是1和2,我的group在单独的文件里,4是为了让homekit识别传感器类型,你这个应该是自动化的问题
回复

使用道具 举报

4

主题

92

帖子

318

积分

中级会员

Rank: 3Rank: 3

积分
318
金钱
226
HASS币
0
 楼主| 发表于 2019-1-10 14:40:42 | 显示全部楼层
缥缈的孤鸿 发表于 2019-1-10 14:35
你需要改动的就是1和2,我的group在单独的文件里,4是为了让homekit识别传感器类型,你这个应该是自动化的 ...

是啊我看提示也是说自动化的问题。如果删除自动化那一段就显示配置有效,并且可以重启服务,但是模式调整和LED灯调整两项失效
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-23 15:49 , Processed in 0.119171 second(s), 34 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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