Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence #574

Open
AbianTang opened this issue Jan 4, 2025 · 7 comments
Open

Comments

@AbianTang
Copy link

Describe the Bug / 描述问题

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

How to Reproduce / 复现步骤

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence
截屏2025-01-04 21 52 58
需改成presence如下,不然无法进行自动化
截屏2025-01-04 21 53 49

Expected Behavior / 预期结果

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

Reproduce Time / 问题复现的时间点

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

Home Assistant Logs / 系统日志

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

Log Timezone / 日志时区

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

Home Assistant Core Version / Home Assistant Core 版本

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

Home Assistant Operation System Version / Home Assistant Operation System 版本

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

Xiaomi Home Integration Version / 米家集成版本

Xiaomi Motion Sensor 2S Motion Sensor 建议修改为ha的presence

Additional Context / 其他说明

No response

@caibinqing
Copy link

event 是可以用的,也是HA最新建议的写法,(我也觉得不是很好用,尽管它比较正确)
自动化的触发条件可以像这样写:

trigger: state
entity_id:
  - event.xiaomi_cn_blt_3_*************_pir1_motion_detected_e_2_1008
not_from: unavailable
not_to: unavailable

@AbianTang
Copy link
Author

AbianTang commented Jan 8, 2025

``

event 是可以用的,也是HA最新建议的写法,(我也觉得不是很好用,尽管它比较正确) 自动化的触发条件可以像这样写:

trigger: state
entity_id:
  - event.xiaomi_cn_blt_3_*************_pir1_motion_detected_e_2_1008
not_from: unavailable
not_to: unavailable
platform: state
entity_id:
  - event.xiaomi_cn_xxxxxxxxxxxx
from: 检测到移动
to: 检测到移动

应该是这样吧

@dante210402
Copy link

``

event 是可以用的,也是HA最新建议的写法,(我也觉得不是很好用,尽管它比较正确) 自动化的触发条件可以像这样写:

trigger: state
entity_id:
  - event.xiaomi_cn_blt_3_*************_pir1_motion_detected_e_2_1008
not_from: unavailable
not_to: unavailable
platform: state
entity_id:
  - event.xiaomi_cn_xxxxxxxxxxxx
from: 检测到移动
to: 检测到移动

应该是这样吧

这个事件的值不是检测到移动,而且一个触发时间,可以自己模板里创建一个二元传感器,虽然我觉着现在这么做不太优雅

{% set temp = as_timestamp(states('event.xiaomi_cn_blt_3_*************_pir1_motion_detected_e_2_1008')) -%}
{%- if as_timestamp(now()) - temp > 60 -%}
OFF
{%- else -%}
ON
{% endif %}

@caibinqing
Copy link

platform: state
entity_id:
  - event.xiaomi_cn_xxxxxxxxxxxx
from: 检测到移动
to: 检测到移动

应该是这样吧

不是这样的,状态是触发的时间戳,所以才能监听到变化(这个motion事件只有一种类型,就不需要判断了),完整的自动化可以参考这个:

mode: restart
triggers:
  - trigger: state
    entity_id:
      - event.xiaomi_cn_blt_3_*************_pir1_motion_detected_e_2_1008
    not_from: unavailable
    not_to: unavailable
conditions: []
actions:
  - alias: 如果灯关着就打开
    if:
      - condition: state
        entity_id: light.*************
        state: "on"
    then:
      - action: light.turn_on
        target:
          entity_id: light.*************
        data: {}
  - alias: 等一会儿
    delay:
      hours: 0
      minutes: 2
      seconds: 0
  - alias: 关灯
    action: light.turn_off
    target:
      entity_id: light.*************
    data: {}

@AbianTang
Copy link
Author

platform: state
entity_id:
  - event.xiaomi_cn_xxxxxxxxxxxx
from: 检测到移动
to: 检测到移动

应该是这样吧

不是这样的,状态是触发的时间戳,所以才能监听到变化(这个motion事件只有一种类型,就不需要判断了),完整的自动化可以参考这个:

mode: restart
triggers:
  - trigger: state
    entity_id:
      - event.xiaomi_cn_blt_3_*************_pir1_motion_detected_e_2_1008
    not_from: unavailable
    not_to: unavailable
conditions: []
actions:
  - alias: 如果灯关着就打开
    if:
      - condition: state
        entity_id: light.*************
        state: "on"
    then:
      - action: light.turn_on
        target:
          entity_id: light.*************
        data: {}
  - alias: 等一会儿
    delay:
      hours: 0
      minutes: 2
      seconds: 0
  - alias: 关灯
    action: light.turn_off
    target:
      entity_id: light.*************
    data: {}
description: ""
mode: restart
triggers:
  - trigger: state
    entity_id:
      - event.xiaomi_cn_blt_3_xxxxxxxxxxxx_pir1_motion_detected_e_2_1008
    not_from: unavailable
    not_to: unavailable
conditions: []
actions:
  - alias: 如果灯关着就打开
    if:
      - condition: state
        entity_id: light.yeelink_cn_xxxxxxxxxceiling22_s_2
        state: "on"
    then:
      - action: light.turn_on
        target:
          entity_id: light.yeelink_cnxxxxxxxxx_ceiling22_s_2
        data: {}
  - alias: 等一会儿
    delay:
      hours: 0
      minutes: 2
      seconds: 0
  - alias: 关灯
    action: light.turn_off
    target:
      entity_id: light.yeelink_xxxxxxxxxxxxxxxxxxx22_s_2
    data: {}
alias: 新建自动化

错误Message malformed: extra keys not allowed @ data['triggers']

@AbianTang
Copy link
Author

还是感觉presence优雅,2s人体传感器event五颜六色在ha看起来都怪怪的。

@caibinqing
Copy link

错误Message malformed: extra keys not allowed @ data['triggers']

旧版本大概是这样写的:

mode: restart
trigger:
  - platform: state
    entity_id:
      - event.xiaomi_cn_blt_3_*************_pir1_motion_detected_e_2_1008
    not_from: unavailable
    not_to: unavailable
condition: []
action:
  - alias: 如果灯关着就打开
    if:
      - condition: state
        entity_id: light.*************
        state: "on"
    then:
      - service: light.turn_on
        target:
          entity_id: light.*************
        data: {}
  - alias: 等一会儿
    delay:
      hours: 0
      minutes: 2
      seconds: 0
  - alias: 关灯
    service: light.turn_off
    target:
      entity_id: light.*************
    data: {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants