本帖最后由 myron412 于 2020-12-11 06:35 编辑
先上成果图:
本人是超级小白,所以写法都是以小白的经验来写,大神们直接PASS,若有不对,冗余之处请帮忙优化,指正! 小白我0.54以后就没玩HA,后来HB瘫痪又懒得搞,所以直接换了树莓派4B安装HASSOS,我开始接触是从0.118开始。。但是因为插件在0.118有BUG,所以升级到0.119。因此,你想添加加湿器,请update你的系统,若0.119没有,请用beta版本,但因升级导致的其他问题,自行解决,反正我目前是没有问题 。
此贴的lovelace参考:https://bbs.hassbian.com/thread-9731-1-1.html 而来。因此你想直接使用本贴内的仪表盘代码请安装参考贴内的card-mod、card-tools、vertical-stack-in-card、layout-card、slider-entity-row、fold-entity-row、secondaryinfo-entity-row插件。
插件地址:https://github.com/syssi/xiaomi_airpurifier 。可以通过HACS安装,也可以手动安装。手动安装自行在config下建立custom_component文件夹,考入插件。理论上本插件支持目前为止小米,智米的空气净化器,加湿器,风扇,台扇等。方法类似,可以自行研究。
代码configuration.yaml部分(目前我加入的东西少,所以能直接在这里加的都直接写在这里,强迫症的可以自行修改):
1.
fan:
- platform: xiaomi_miio_airpurifier
name: Xiaomi Air Humidifier
host: 192.168.1.13
token: YOUR_TOKEN
model: deerma.humidifier.mjjsq
复制代码
2.传感器定义
sensor:
- platform: template
sensors:
airhumidifier_humidity:
friendly_name: 环境湿度
value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.humidity }}'
unit_of_measurement: '%'
airhumidifier_temperature:
friendly_name: 环境温度
value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.temperature }}'
unit_of_measurement: '°C'
airhumidifier_target_humidity:
friendly_name: Target humidity
value_template: '{{ states.fan.xiaomi_air_humidifier.attributes.target_humidity }}'
unit_of_measurement: '%'
icon_template: mdi:water-percent
xiaomi_hu_water:
friendly_name: 缺水
value_template: "{{ states.fan.xiaomi_air_humidifier.attributes.no_water }}"
unit_of_measurement: "。"
xiaomi_hu_waterdet:
friendly_name: 水箱分离
value_template: "{{ states.fan.xiaomi_air_humidifier.attributes.water_tank_detached }}"
unit_of_measurement: "。"
复制代码
3.定义switch
switch:
- platform: template
switches:
xiaomi_airpurifier_buzzer:
friendly_name: "Buzzer"
value_template: "{{ is_state_attr('fan.xiaomi_air_humidifier', 'buzzer', True) }}"
turn_on:
service: xiaomi_miio_airpurifier.fan_set_buzzer_on
data:
entity_id: fan.xiaomi_air_humidifier
turn_off:
service: xiaomi_miio_airpurifier.fan_set_buzzer_off
data:
entity_id: fan.xiaomi_air_humidifier
icon_template: "mdi:volume-off"
xiaomi_airpurifier_led:
friendly_name: "LED"
value_template: "{{ is_state_attr('fan.xiaomi_air_humidifier', 'led', True) }}"
turn_on:
service: xiaomi_miio_airpurifier.fan_set_led_on
data:
entity_id: fan.xiaomi_air_humidifier
turn_off:
service: xiaomi_miio_airpurifier.fan_set_led_off
data:
entity_id: fan.xiaomi_air_humidifier
icon_template: "mdi:lightbulb-outline"
复制代码
4.选择模式定义
input_select:
airpurifier_mode:
name: 模式
options:
- "小雾"
- "中雾"
- "大雾"
- "恒湿"
复制代码
5.恒湿数据定义
input_number:
airhumidifier_target_humidity:
name: Target humidity
min: 40
max: 70
step: 1
unit_of_measurement: "%"
复制代码
customize.yaml代码:
fan.xiaomi_air_humidifier:
friendly_name: 米家除菌加湿器S
switch.xiaomi_airpurifier_buzzer:
icon: mdi:volume-high
friendly_name: 提示音
switch.xiaomi_airpurifier_led:
icon: mdi:led-on
friendly_name: 指示灯
sensor.airhumidifier_humidity:
icon: mdi:water-percent
sensor.xiaomi_hu_water:
icon: mdi:store-24-hour
sensor.xiaomi_hu_waterdet:
icon: mdi:brightness-percent
复制代码
automations.yaml代码:
- alias: airpurifier_set_mode
initial_state: true
trigger:
platform: state
entity_id: input_select.airpurifier_mode
action:
service: fan.set_speed
data_template:
entity_id: fan.xiaomi_air_humidifier
speed: >
{% if states.input_select.airpurifier_mode.state == "小雾" %}Low
{% elif states.input_select.airpurifier_mode.state == "中雾" %}Medium
{% elif states.input_select.airpurifier_mode.state == "大雾" %}High
{% elif states.input_select.airpurifier_mode.state == "恒湿" %}Humidity
{% endif %}
- alias: airpurifier_get_mode
initial_state: true
trigger:
platform: time_pattern
seconds: /5
action:
service: input_select.select_option
data_template:
entity_id: input_select.airpurifier_mode
option: >
{% if states.fan.xiaomi_air_humidifier.attributes.speed == "Low" %}小雾
{% elif states.fan.xiaomi_air_humidifier.attributes.speed == "Medium" %}中雾
{% elif states.fan.xiaomi_air_humidifier.attributes.speed == "High" %}大雾
{% elif states.fan.xiaomi_air_humidifier.attributes.speed == "Humidity" %}恒湿
{% endif %}
- alias: Select target humidity by slider
trigger:
platform: state
entity_id: input_number.airhumidifier_target_humidity
action:
- service: xiaomi_miio_airpurifier.fan_set_target_humidity
data_template:
entity_id: fan.xiaomi_air_humidifier
humidity: '{{ states.input_number.airhumidifier_target_humidity.state|int }}'
- alias: Monitor target humidity and update slider
trigger:
platform: state
entity_id: sensor.airhumidifier_target_humidity
action:
service: input_number.set_value
entity_id: input_number.airhumidifier_target_humidity
data_template:
value: '{{ states.fan.xiaomi_air_humidifier.attributes.target_humidity }}'
复制代码
以上代码录入完毕后,请重新启动HA,再进仪表盘自定义卡片进行lovelace编辑。(概览-顶上最右边竖着的三个点-编辑仪表盘-添加卡片-拉倒最后选择手动模式选择)。
卡片配置左边代码栏清空,直接考入下面代码:(考入代码后,右边立刻会有预览图片,若转圈,表示拷贝时有缩进没弄对,根据拷贝代码的地方底部提示调整。)PS: 我写的这个没什么经验,目前有黄字提示,但可以使用。有大神路过请帮忙修改下
cards:
- content: |
<br>
style: |
ha-card {
--paper-item-icon-color: Gainsboro;
--primary-text-color: ##104E8B;
--secondary-text-color: #B3E5FC;
background:rgba(255,255,255,0);
}
.card-header{
background: url(/local/images/card/mjjs2.jpg);
color: white;
}
title: 加湿器
type: markdown
- entities:
- entity: fan.xiaomi_air_humidifier
secondary_info: >-
缺水:[[ fan.xiaomi_air_humidifier.attributes.no_water ]], 水箱分离:[[
fan.xiaomi_air_humidifier.attributes.water_tank_detached ]]
type: 'custom:secondaryinfo-entity-row'
- entity: input_select.airpurifier_mode
icon: 'mdi:air-conditioner'
name: 档位选择:
type: 'custom:slider-entity-row'
- entity: input_number.airhumidifier_target_humidity
icon: 'mdi:air-conditioner'
name: 恒湿控制:
type: 'custom:slider-entity-row'
show_header_toggle: false
style: |
ha-card {
--paper-item-icon-color: Gainsboro;
--primary-text-color: black;
--secondary-text-color: gray;
background:rgba(255,255,255,0);
}
}
type: entities
- aspect_ratio: '492:232'
entities:
- entity: switch.xiaomi_airpurifier_buzzer
tap_action:
action: toggle
- entity: switch.xiaomi_airpurifier_led
tap_action:
action: toggle
- entity: sensor.airhumidifier_humidity
- entity: sensor.airhumidifier_temperature
show_state: ture
style: |
ha-card {
--paper-item-icon-color: Black;
background:rgba(255,255,255,0);
}
type: glance
type: 'custom:vertical-stack-in-card'
复制代码
lovelace内的顶部图片在我附件,目录路径为/config/www/images/card下。没有www文件夹的自己建一个。
顶部图
手动安装附件在最后。
xiaomi_airpurifier-develop.zip
(222.21 KB, 下载次数: 68)
分享完毕!