本帖最后由 chiunownow 于 2019-5-22 05:24 编辑
190522更新
- 修改少量逻辑,似乎还有优化空间,不妨碍使用
- 增加风扇 for homekit,在Homekit中风扇100%为大风,67%为中风,33%为小风,关闭为自动风速
前言
之前发过这么两个帖子:
控客插座红外控制空调(滑块温度+风速选择)
iOS 捷径 + HA API 控制 HA (以控客遥控空调为例子)
但是用 Shortcut 总归有一些不方便,还是想在 iOS 上用 Homekit 优雅地控制空调。
今天忘记哪来的灵感,挖掘了一下 HA 官方文档,发现了这个好东西:通用恒温器
190522补充
以下内容因空调控制方式差异巨大,同时每位用户录码方式可能存在差异,所以不具有广泛适用性。请根据自己的实际情况调整yaml配置文件内容。
实现效果
前方高能预警
这个 yaml 全是不会写真正的代码的我瞎搞的一堆骚操作。
使用前请先熟读 并背诵全文 控客插座红外控制空调(滑块温度+风速选择),确保会用了。
下面的代码大量与上面这个帖子重复,且需要根据自己的需求进行调整
不足
- 直接使用了
state.climate.zhu_wo_kong_diao ,输出值只有 idle 和 off (用于制冷和关机)。如果使用 {{state_attr('climate.zhu_wo_kong_diao','operation_mode')}} 的话,可以输出更多的值,实现更多操作。
通用恒温器没有风速控制功能,可以另外写一个模板风扇(参考文档),用于控制风速。 fix done
空调控制器完整Yaml
input_number:
remote_temp_bedroom: #温度滑块
min: 16
max: 28
initial: 24
step: 1
name: 空调温度
unit_of_measurement: "℃"
icon: mdi:thermometer
input_select:
remote_fanspeed_bedroom: #风速选择下拉菜单
name: 风速
icon: mdi:weather-windy
options:
- "自动"
- "小"
- "中"
- "大"
sensor:
- platform: template #通用恒温器温度数值寄存
sensors:
climate_bedroom_ac:
value_template: "{{state_attr('climate.zhu_wo_kong_diao','temperature') | int }}"
automation:
- alias: "控客黑自动发送空调遥控信号"
initial_state: true
trigger:
- platform: state
entity_id: input_number.remote_temp_bedroom
- platform: state
entity_id: input_select.remote_fanspeed_bedroom
action:
service: script.toggle
entity_id: script.remote_minikpro_turnon_ac
- alias: "climate_temp" #通用恒温器调整温度时同步到温度控制滑块
initial_state: true
trigger:
platform: state
entity_id: sensor.climate_bedroom_ac
action:
service: input_number.set_value
data_template:
entity_id: input_number.remote_temp_bedroom
value: "{{states('sensor.climate_bedroom_ac') | int }}"
- alias: "climate_cooling" #通用恒温器调整模式到制冷时打开空调
initial_state: true
trigger:
platform: state
entity_id: climate.zhu_wo_kong_diao
from: "off"
to: "idle"
action:
service: script.toggle
entity_id: script.remote_minikpro_turnon_ac
- alias: "climate_turnoff" #通用恒温器调整模式到关闭时关闭空调
initial_state: true
trigger:
platform: state
entity_id: climate.zhu_wo_kong_diao
from: "idle"
to: "off"
action:
service: script.toggle
entity_id: script.remote_minikpro_turnoff_ac
script:
remote_minikpro_turnoff_ac: #发送关空调信号
alias: 关空调
sequence:
- service: remote.send_command
data:
entity_id: remote.wo_shi_yao_kong
command: ir_1000
- service: input_boodlean.turn_off
entity_id: input_boodlean.bedroom_ac
remote_minikpro_turnon_ac:
alias: 开空调 #发送开空调信号(对应滑块温度与下拉菜单风速)
sequence:
- service: remote.send_command
data_template:
entity_id: remote.wo_shi_yao_kong
command: >
{% if states.input_select.remote_fanspeed_bedroom.state == "自动" %}ir_{{ states('input_number.remote_temp_bedroom') | int }}00
{% elif states.input_select.remote_fanspeed_bedroom.state == "小" %}ir_{{ states('input_number.remote_temp_bedroom') | int }}01
{% elif states.input_select.remote_fanspeed_bedroom.state == "中" %}ir_{{ states('input_number.remote_temp_bedroom') | int }}02
{% elif states.input_select.remote_fanspeed_bedroom.state == "大" %}ir_{{ states('input_number.remote_temp_bedroom') | int }}03
{% endif %}
- service: input_boodlean.turn_on
entity_id: input_boodlean.bedroom_ac
set_acfan_speed_auto: #设置风速下拉菜单到自动
sequence:
- service: input_select.select_option
data:
entity_id: input_select.remote_fanspeed_bedroom
option: "自动"
set_acfan_speed_min: #设小风
sequence:
- service: input_select.select_option
data:
entity_id: input_select.remote_fanspeed_bedroom
option: "小"
set_acfan_speed_medium: #设中风
sequence:
- service: input_select.select_option
data:
entity_id: input_select.remote_fanspeed_bedroom
option: "中"
set_acfan_speed_large: #设大风
sequence:
- service: input_select.select_option
data:
entity_id: input_select.remote_fanspeed_bedroom
option: "大"
switch:
- platform: template #通用恒温器所需模板开关
switches:
bedroom_ac:
friendly_name: 主卧空调
value_template: "{{ is_state('input_boolean.bedroom_ac', 'on') }}"
turn_on:
- service: script.toggle
data:
entity_id: script.remote_minikpro_turnon_ac
- service: input_boodlean.turn_on
data:
entity_id: input_boodlean.bedroom_ac
turn_off:
- service: script.toggle
data:
entity_id: script.remote_minikpro_turnoff_ac
- service: input_boodlean.turn_off
data:
entity_id: input_boodlean.bedroom_ac
input_boolean:
bedroom_ac: #通用恒温器所需布尔值传感器
name: 卧室空调
initial: on
climate:
- platform: generic_thermostat #通用恒温器 for homekit
name: 主卧空调
heater: switch.bedroom_ac
target_sensor: sensor.climate_bedroom_ac
min_temp: 16
max_temp: 32
ac_mode: true
precision: 1
fan:
- platform: template
fans:
ac_fan: #模板风扇 for homekit
friendly_name: 空调风速
value_template: "{{states('climate.zhu_wo_kong_diao')}}"
speed_template: "{{states('input_select.remote_fanspeed_bedroom')}}"
turn_on:
service: script.remote_minikpro_turnon_ac
turn_off:
service: script.set_acfan_speed_auto
speeds:
- "自动"
- "小"
- "中"
- "大"
set_speed:
service_template: >
{% if speed == '自动' %}
script.set_acfan_speed_auto
{% elif speed == '小' %}
script.set_acfan_speed_min
{% elif speed == '中' %}
script.set_acfan_speed_medium
{% elif speed == '大' %}
script.set_acfan_speed_large
{% endif %}
|