本帖最后由 gdlw2000 于 2021-3-12 12:51 编辑
老大按照你那个安装说明装了
在config\packages 下建了 lock.yaml
binary_sensor:
- platform: template
sensors:
smartlock_door:
friendly_name: 门状态
value_template: >-
{% if (is_state_attr('sensor.e50b9a2dxxxx_action','action_id',0) and is_state_attr('sensor.e50b9a2dxxxx_action','action',"door")) or (is_state_attr('sensor.e50b9a2dxxxx2_action','action_id',2) and is_state_attr('sensor.e50b9a2dxxxx_action','action',"door"))%}
sensor:
- platform: template
sensors:
smartlock_state:
friendly_name: 门锁状态
value_template: 未知
smartlock_method:
friendly_name: 开门方式
<blockquote>
这样建立没问题吧
可以在ui直接添加 传感器,但是传感器都显示未知。只有门状态是可以显示,我估计是我理解错意思了,在homekit里直接添加传感器提示出错。
日志也捕捉不到状态变化
折腾几天了没搞出来 网关刷了好几个版本都不成
把网关测试打开 可以捕捉到锁的状态
日志显示 设备蓝牙锁以及门
另外在config里\custom_components\xiaomi_gateway3\core找到了 mqttl_xiaomilock.yaml这个文件不知道有没用,你看下你那里有没有,不知道从哪儿跑出来的貌似是自己生成的么
里面是传感器直接从mqtt读取文件如果这样直接建立传感器所有问题不就直接解决了么?
我直接添加到packages里面了但是没作用
binary_sensor:
- platform: mqtt
name: mijia_lock
state_topic: 'mqttl/101136901/7' #mqttl/设备did/eid, 替换成正确的did和eid
value_template: >-
{% if value[8:10] == '00' or value[8:10] == '02' or value[8:10] == '05'%}
unlock
{% elif value[8:10] == '01' or value[8:10] == '03' or value[8:10] == '04' %}
lock
{% endif %}
payload_on: 'unlock'
payload_off: 'lock'
device_class: lock
qos: 1
sensor:
- platform: mqtt #智能锁状态
name: lock_state
icon: 'mdi:lock-smart'
state_topic: 'mqttl/101136901/7' #mqttl/设备did/eid, 替换成正确的did和eid
value_template: >-
{% if value[8:10] == '00' %}
开门
{% elif value[8:10] == '01' %}
关门
{% elif value[8:10] == '02' %}
超时未关
{% elif value[8:10] == '03' %}
敲门
{% elif value[8:10] == '04' %}
撬门
{% elif value[8:10] == '05' %}
门卡住
{% endif %}
- platform: mqtt
name: lock_state_update_time
icon: 'mdi:lock-clock'
state_topic: 'mqttl/101136901/7'
value_template: "{{ value[0:8]|int(0,16)|timestamp_local }}"
#开锁方式
- platform: mqtt
name: lock_method
icon: 'mdi:lock-question'
state_topic: 'mqttl/101136901/11'
value_template: >-
{% if value[16:17] == '0' %}
蓝牙
{% elif value[16:17] == '1' %}
密码
{% elif value[16:17] == '2' %}
指纹
{% elif value[16:17] == '3' %}
钥匙
{% elif value[16:17] == '4' %}
转盘
{% elif value[16:17] == '5' %}
NFC
{% elif value[16:17] == '6' %}
一次性密码
{% elif value[16:17] == '7' %}
双重验证
{% elif value[16:17] == 'a' %}
人工
{% elif value[16:17] == 'b' %}
自动
{% elif value[16:17] == 'f' %}
异常
{% else %}
{{ value[16:17] }}
{% endif %}
#门锁事件
- platform: mqtt
name: lock_event
icon: 'mdi:lock-question'
state_topic: 'mqttl/101136901/11'
value_template: >-
{% if value[17:18] == '0' %}
门外开锁
{% elif value[17:18] == '1' %}
上提把手锁门
{% elif value[17:18] == '2' %}
反锁
{% elif value[17:18] == '3' %}
解除反锁
{% elif value[17:18] == '4' %}
门内开锁
{% elif value[17:18] == '5' %}
门内上锁
{% elif value[17:18] == '6' %}
开启童锁
{% elif value[17:18] == '7' %}
关闭童锁
{% elif value[17:18] == 'f' %}
异常
{% else %}
{{ value[17:18] }}
{% endif %}
#可以按照下边的格式匹配操作者
- platform: mqtt
name: lock_user
icon: 'mdi:human-handsdown'
state_topic: 'mqttl/101136901/11'
value_template: >-
{% if value[8:16] == '00000000' %}
管理员
{% elif value[8:16] == 'ffffffff' %}
未知操作者
{% elif value[8:16] == 'DEADBEEF' %}
无效操作者
{% else %}
{{ value[8:16] }}
{% endif %}
#0x00000000 - 0x7FFFFFFF:蓝牙(最多 2147483647 个)
#0x80010000 - 0x8001FFFF:指纹(最多 65536 个)
#0x80020000 - 0x8002FFFF:密码(最多 65536 个)
#0x80030000 - 0x8003FFFF:钥匙(最多 65536 个)
#0x80040000 - 0x8004FFFF:NFC(最多 65536 个)
#0x80050000 - 0x8005FFFF:双重验证(最多 65536 个)
- platform: mqtt
name: lock_event_update_time
icon: 'mdi:lock-clock'
state_topic: 'mqttl/101136901/11'
value_template: >-
{% if value[8:12] != 'c0de' %}
{{ value[0:8]|int(0,16)|timestamp_local }}
{% endif %}
- platform: mqtt
name: lock_alert
icon: 'mdi:lock-alert'
state_topic: 'mqttl/101136901/11'
value_template: >-
{% if value[8:12] == 'c0de' %}
{% if value[12:16] == '0000' %}
密码多次验证失败
{% elif value[12:16] == '0001' %}
指纹多次验证失败
{% elif value[12:16] == '0002' %}
操作超时(密码输入超时)
{% elif value[12:16] == '0003' %}
撬锁
{% elif value[12:16] == '0004' %}
重置按键按下
{% elif value[12:16] == '0005' %}
错误钥匙频繁开锁
{% elif value[12:16] == '0006' %}
钥匙孔异物
{% elif value[12:16] == '0007' %}
钥匙未取出
{% elif value[12:16] == '0008' %}
错误NFC频繁开锁
{% elif value[12:16] == '0009' %}
超时未按要求上锁
{% elif value[12:16] == '1000' %}
电量低于10%
{% elif value[12:16] == '1001' %}
电量低于5%
{% elif value[12:16] == '1002' %}
指纹传感器异常
{% else %}
正常
{% endif %}
{% endif %}
- platform: mqtt
name: lock_alert_update_time
icon: 'mdi:lock-clock'
state_topic: 'mqttl/101136901/11'
value_template: >-
{% if value[8:12] == 'c0de' %}
{{ value[0:8]|int(0,16)|timestamp_local }}
{% endif %}
- platform: mqtt
name: lock_battery
state_topic: 'mqttl/101136901/4106'
value_template: "{{ value[8:10]|int(0,16) }}"
unit_of_measurement: '%'
device_class: battery
- platform: mqtt
name: lock_battdate
icon: 'mdi:update'
state_topic: 'mqttl/101136901/4106'
value_template: "{{ value[0:8]|int(0,16)|timestamp_custom('%Y-%m-%d') }}"
homeassistant:
customize:
sensor.lock_state:
friendly_name: 门状态
sensor.lock_state_update_time:
friendly_name: 状态变更时间
sensor.lock_event:
friendly_name: 锁事件
sensor.lock_method:
friendly_name: 开锁方式
sensor.lock_user:
friendly_name: 操作者
sensor.lock_event_update_time:
friendly_name: 事件发生时间
sensor.lock_alert:
friendly_name: 警告信息
sensor.lock_alert_update_time:
friendly_name: 警告发生时间
sensor.lock_battery:
friendly_name: 电池电量
sensor.lock_battdate:
friendly_name: 电量报告日期
上面重启后系统提示无法安装- Unable to prepare setup for platform mqtt.sensor: Unable to set up component.
- Unable to prepare setup for platform mqtt.binary_sensor: Unable to set up component.
|