本帖最后由 yinjiong 于 2018-10-3 16:39 编辑
syssi大神miio空调插件时的痛点:
1,米家空调伴侣支持的风类、速度等参数有限,有些空调支持的特殊参数只能用学码实现,但发送学到的红外码后空调插件状态不同步。
2,学码虽然在ha中有通知,但是学一个记录一个来来回回太麻烦,一下子学再记录容易搞混。
此魔改版支持:
1,支持3个新services实现自动对学码结果做标签,并通过使用标签发送对应红外码,对已知红外码可通过编辑配置文件直接添加标签
2,支持配置发送的红外码的含义,并在发射时自动同步空调伴侣插件状态
插件配置方法:
插件放在custom_components\climate下
配置:
climate:
- platform: xiaomi_miio_s #必填,插件名称
name: bedroom AC #实例名称
host: !secret Xiaomi_ACP_ip #ip
token: !secret Xiaomi_ACP_token #token
target_sensor: sensor.at02 #参考的温度传感器
scan_interval: 10 #状态更新频率,秒
auto_switch: input_boolean.bedroom_auto_ac_switch #二元选择器名称,打开时同步发送的红外码状态到空调伴侣插件,关闭时同步空调伴侣状态到空调伴侣插件。默认为关闭
ir_config_file_path: /config/climate.miio.json #ir码库位置,默认为/config/climate.miio.json,格式为utf-8
新增服务:
xiaomi_miio_learn_and_use_command:用于学习并记住红外码,并标记上key
xiaomi_miio_send_command_by_key:用于用指定的key发送对应的红外码
xiaomi_miio_reload_ir_config_file:重新读取码库
参数:
xiaomi_miio_learn_and_use_command
entity_id:可选,根据syssi大神的说法只有部分特定设备需要。
slot:可选,取值范围1-30,默认29。
timeout:可选,默认10秒。
key:必填,这个是学到的码的标签,之后可以用这个标签来发送对应红外码。如果标签已经存在会更新对应数据。
xiaomi_miio_send_command_by_key
entity_id:可选,根据syssi大神的说法只有部分特定设备需要。
key:必填,要发送红外码的标签,也就是调用learn_and_use时输入的key。
调用方法举例:
- service: climate.xiaomi_miio_learn_and_use_command
data:
entity_id: climate.bedroom_ac
slot: 30
timeout: 60
key: bedroom_ac_command_01
- service: climate.xiaomi_miio_send_command_by_key
data:
entity_id: climate.bedroom_ac
key: bedroom_ac_command_01
- service:climate.xiaomi_miio_reload_ir_config_file
通过xiaomi_miio_learn_and_use_command服务学码后会自动记录到码库中,自动格式后,如:
{
"command": {
"bedroomaccoolhoff24": {
"ir": "FE0000000000000000000000000700DC220300290030008800B3015B042113884301020101010101010101010101020101010101010102020201010201010101010101010101010101010101010101010101010101010101010102020101010101054301020101010101010101010101020101010101010102020201010201010101010101010101010101020101020202010101010101020201000100000000000002020002000202020002000202000000000000000000000000000202000000000000000000000202000000000000000000000000000000000002020002000000020000000002000002000002020200020000020202000002000603",
"mode": "制冷",
"fan": "高速",
"swing": "关",
"t": "24"
},
"bedroomacoff": {
"ir": "FE0000000000000000000000000700DC22030028002E008800AF015E041E138843101210101010101010101010101210101010101010121212101002100000000000000000000000000000000000000101010101010101010101020201010101010543010201010101010101010101010201010101010101020202010102010101010101010101010101010101010202020101010201020202010101010101010101020201010102020101020102020101010101010101010101010102020101010101010101010102020101010101010201010101010101010101020201020101010201010101020101020101020202010201020201010202010106C9",
"mode": "off",
"fan": "0",
"swing": "0",
"t": "0"
},
"bedroom_ac_command_01": {
"ir": "FE0000000000000000000000000700DC2203002A0030008700B0015E041E138843000200000000000000000000000200000000000000020202000002000000000000000000000000000000000000000100000001010100010001020200000000000543000200000000000000000000000200000000000000020202000002000000010000000100000000000100000202020000000201020202000000000000010000020200000002020000020002020000010100000000000000000102020000000100000100000102020000000100010201000000010000010000020200020101010201010001010201020101020202010201020200010101020106C0",
"mode": "",
"fan": "",
"swing": "",
"t": ""
}
}
}
这里前2个为手工添加,最后一个名为bedroom_ac_command_01的为学码后得到的。可以修改mode(模式),fan(风速),swing(摇摆),t(温度)参数,参数具体取值可在ha的entity页面中找到空调插件对应实体后,查看其属性。之后调用service:climate.xiaomi_miio_reload_ir_config_file重新载入码库。在配置打开同步时,使用bedroom_ac_command_01发送命令即会同步这些参数到空调插件,此时,米家中相关参数不会同步到插件。(米家中的参数本身也并不是空调的真实运行状态)
关闭指令:在码库中配置关闭指令时mode填off,其他参数无效。
强烈建议各位编辑后检查码库json格式。
强烈呼吁大家把学码后的码库上传到本帖共享,方便更多人。
最后,插件在:
|