本帖最后由 chiunownow 于 2019-7-4 22:44 编辑
天猫精灵不知道啥时候出了一款BLE按钮,价格不错,加上优惠后三个按钮六十块钱出头,需要搭配天猫精灵作为网关,比小米的便宜多了。果断撸几个回来折腾。具体购买链接和使用需求请某宝搜索按呗 咨询客服。
套路
- 将HA接入猫精(有条件的用 aihome,没条件的用论坛新版猫精
- 写几个
input_boolean 专门给猫精控制
- 把上面的
input_boolean 在猫精APP里分配到奇怪的房间
- 写几个
automation 来实现想要的功能
保姆房车库宠物房都是不存在的,专门给猫精按钮分配的
Package.yaml
此处用我自己使用的三个功能作为案例供参考:
- 单击:将小米飞利浦台灯设为夜灯或关灯
- 双击:睡眠灯光,关掉大部分照明灯
- 长按:打开空调并设置为24度大风或关空调
# 先生成几个假按钮给猫精
input_boolean:
tmall_b1_1:
tmall_b1_2:
tmall_b1_3:
# 让猫精接入上面的假按钮。此处使用aihome方案,论坛新版猫精请自行修改
homeassistant:
customize:
input_boolean.tmall_b1_1:
friendly_name: "宠物房的挂灯"
aihome_device: True
aligenie_deviceName: 挂灯
aligenie_zone: 宠物房
aligenie_deviceType: light
aligenie_actions: ["TurnOn", "TurnOff"]
input_boolean.tmall_b1_2:
friendly_name: "宠物房的射灯"
aihome_device: True
aligenie_deviceName: 射灯
aligenie_zone: 宠物房
aligenie_deviceType: light
aligenie_actions: ["TurnOn", "TurnOff"]
input_boolean.tmall_b1_3:
friendly_name: "宠物房的筒灯"
aihome_device: True
aligenie_deviceName: 筒灯
aligenie_zone: 宠物房
aligenie_deviceType: light
aligenie_actions: ["TurnOn", "TurnOff"]
# 将 climate 组件的空调情况转为 sensor 方便 automation 调用
sensor:
- platform: template
sensors:
climate_operation_mode:
value_template: "{{state_attr('climate.zhu_wo_kong_diao', 'operation_mode')}}"
# 让按钮实现功能
automation:
- alias: 单击-关小米飞利浦台灯
initial_state: true
trigger:
platform: state
entity_id: input_boolean.tmall_b3_1
from: "off"
to: "on"
condition:
condition: or
conditions:
- condition: state
entity_id: light.fei_li_pu_tai_deng
state: "on"
- condition: state
entity_id: light.fei_li_pu_tai_deng_ambient_light
state: "on"
action:
- service: homeassistant.turn_off
entity_id: light.fei_li_pu_tai_deng
- service: homeassistant.turn_off
entity_id: light.fei_li_pu_tai_deng_ambient_light
- service: homeassistant.turn_off
entity_id: input_boolean.tmall_b3_1
- alias: 单击-小米飞利浦台灯设为夜灯
initial_state: true
trigger:
platform: state
entity_id: input_boolean.tmall_b3_1
from: "off"
to: "on"
condition:
condition: and
conditions:
- condition: state
entity_id: light.fei_li_pu_tai_deng
state: "off"
- condition: state
entity_id: light.fei_li_pu_tai_deng_ambient_light
state: "off"
action:
- service: light.turn_on
data:
entity_id: light.fei_li_pu_tai_deng
brightness: 1
- service: light.turn_on
entity_id: light.fei_li_pu_tai_deng_ambient_light
- service: homeassistant.turn_off
entity_id: input_boolean.tmall_b3_1
- alias: 双击-关家里所有灯
initial_state: true
trigger:
platform: state
entity_id: input_boolean.tmall_b3_2
from: "off"
to: "on"
action:
- service: homeassistant.turn_off
entity_id: group.sleep_mode
- service: homeassistant.turn_off
entity_id: input_boolean.tmall_b3_2
- alias: 长按-关空调
initial_state: true
trigger:
platform: state
entity_id: input_boolean.tmall_b3_3
from: "off"
to: "on"
condition:
condition: state
entity_id: sensor.climate_operation_mode
state: "cool"
action:
- service: climate.turn_off
entity_id: climate.zhu_wo_kong_diao
- service: homeassistant.turn_off
entity_id: input_boolean.tmall_b3_3
- alias: 长按-开空调
initial_state: true
trigger:
platform: state
entity_id: input_boolean.tmall_b3_3
from: "off"
to: "on"
condition:
condition: state
entity_id: sensor.climate_operation_mode
state: "off"
action:
- service: climate.set_operation_mode
entity_id: climate.zhu_wo_kong_diao
data:
operation_mode: cool
- service: climate.set_temperature
entity_id: climate.zhu_wo_kong_diao
data:
temperature: 24
- service: script.toggle
entity_id: script.set_acfan_speed_large
- service: homeassistant.turn_off
entity_id: input_boolean.tmall_b3_3
|