场景:通过红外遥控控制的老电器,远程控制不知道是否开启.
实例:家里是个老空调,使用博联的红外控制和小米空调伴侣2都存在远程控制开启,但实际上并没有运行的情况.
思路:调用服务,开启空调 ,检测插座功率是否上升到50,延长30秒,重复此过程知道插座功率上升到50,推送到手机,提示空调开启成功.
前置条件:1.电器使用的是带功率检测的插座,并且在HA中可以查看 2.可以控制电器的设备,比如博联红外遥控器、小米空调伴侣2
turn_the_air_conditioner_on:
sequence:
- repeat:
while:
- condition: numeric_state
entity_id: climate.xiaomi_air_conditioning_companion_2
attribute: load_power
below: '50'
sequence:
- service: switch.turn_on
target:
entity_id: switch.kong_diao
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- choose:
- conditions:
- condition: state
entity_id: sensor.season
state: winter
sequence:
- repeat:
until:
- condition: state
entity_id: climate.xiaomi_air_conditioning_companion_2
state: heat
attribute: hvac_mode
sequence:
- service: climate.set_hvac_mode
target:
entity_id: climate.xiaomi_air_conditioning_companion_2
data:
hvac_mode: heat
- service: climate.set_temperature
target:
entity_id: climate.xiaomi_air_conditioning_companion_2
data:
temperature: 30
- conditions:
- condition: state
entity_id: sensor.season
state: summer
sequence:
- repeat:
until:
- condition: state
entity_id: climate.xiaomi_air_conditioning_companion_2
state: cool
attribute: hvac_mode
sequence:
- service: climate.set_hvac_mode
target:
entity_id: climate.xiaomi_air_conditioning_companion_2
data:
hvac_mode: cool
- service: climate.set_temperature
target:
entity_id: climate.xiaomi_air_conditioning_companion_2
data:
temperature: 20
default: []
- service: notify.mobile_app_iphone
data:
message: 空调已开启
mode: single
alias: 开空调
turn_the_air_conditioner_off:
sequence:
- repeat:
while:
- condition: numeric_state
entity_id: climate.xiaomi_air_conditioning_companion_2
attribute: load_power
above: '50'
sequence:
- service: switch.turn_off
target:
entity_id: switch.kong_diao
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- service: notify.mobile_app_iphone
data:
message: 空调已关闭
mode: single
alias: 关空调
这个问题困扰了我好几年,其实并不难,但对于小白来说,就是漫漫的摸索过程,写出来,希望能帮到有同样需求的小白.
|