|
楼主 |
发表于 2021-1-6 09:23:19
|
显示全部楼层
昨天重新想了一下再加上国外HA的资料, 竟然被我搞出来, 所以就来自问自答
[思路]
Binary sensor 无法处理 event, 所以先建立一个 input boolean 转换资讯
之后 event 透过 automation 进行辨识
Event -> Automation -> input boolean -> binary sensor -> Homekit
以下是我自己编出来的, 仅截取门开阖状态以及上锁状态 Event 给 Homekit 生成传感器
====
input_boolean:
mi_door:
name: Xiaomi Door
icon: mdi:door
mi_doorlock:
name: Xiaomi Door Lock
icon: mdi:lock
binary_sensor:
- platform: template
sensors:
xiaomi_door:
friendly_name: "Xiaomi Door"
device_class: "door"
value_template: "{{ is_state('input_boolean.mi_door', 'on') }}"
xiaomi_doorlock:
friendly_name: "Xiaomi Door Lock"
device_class: "lock"
value_template: "{{ is_state('input_boolean.mi_doorlock', 'on') }}"
automation:
- alias: door open
trigger:
platform: state
entity_id: sensor.门锁编号_action
to: door
condition:
condition: template
value_template: "{{ trigger.to_state.attributes['action_id'] == 0 }}"
action:
service: input_boolean.turn_on
data:
entity_id: input_boolean.mi_door
- alias: door closed
trigger:
platform: state
entity_id: sensor.门锁编号_action
to: door
condition:
condition: template
value_template: "{{ trigger.to_state.attributes['action_id'] == 1 }}"
action:
service: input_boolean.turn_off
data:
entity_id: input_boolean.mi_door
- alias: door locked
trigger:
platform: state
entity_id: sensor.门锁编号_action
to: lock
condition:
condition: or
conditions:
- condition: template
value_template: "{{ trigger.to_state.attributes['action_id'] == 1 }}"
- condition: template
value_template: "{{ trigger.to_state.attributes['action_id'] == 5 }}"
action:
service: input_boolean.turn_on
data:
entity_id: input_boolean.mi_doorlock
- alias: door unlock
trigger:
platform: state
entity_id: sensor.门锁编号_action
to: lock
condition:
condition: or
conditions:
- condition: template
value_template: "{{ trigger.to_state.attributes['action_id'] == 0 }}"
- condition: template
value_template: "{{ trigger.to_state.attributes['action_id'] == 4 }}"
action:
service: input_boolean.turn_off
data:
entity_id: input_boolean.mi_doorlock
|
|