『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 4732|回复: 1

开门延时N秒,网关报警,翻动魔方关闭报警

[复制链接]

20

主题

216

帖子

1458

积分

论坛DIY达人

积分
1458
金钱
1217
HASS币
100
发表于 2019-3-4 09:42:53 | 显示全部楼层 |阅读模式
config里面定义两个变量
input_number:
  ringalarm:
    min: 0
    max: 10
    step: 1

input_boolean:
  kaimen:
    initial: off

门开了设置变量kaimen,室内无人加上的话就是从外面开门才报警,里面开门不报警

- alias: open door
  initial_state: true
  trigger: #开门
    - platform: state
      entity_id: binary_sensor.door_window_sensor_158dxx
      from: 'off'
      to: 'on'
#  condition:
#    condition: state  #室内无人
#    entity_id: binary_sensor.motion_sensor_158dxx
#    state: 'off'
  action:
    - service: notify.weixin
      data: {"title":"门开了。","message":"大门被打开了!"}
    - service: input_boolean.turn_on
      data:
        entity_id: input_boolean.kaimen

kaimen变量on 持续2S 报警 同时把ringalarm设为1
- alias: open door after 2S alarm if cube dont flip90
  initial_state: true
  trigger:
   - platform: state
     entity_id: input_boolean.kaimen
     from: 'off'
     to: 'on'
     for:
       seconds: 2 #延时可设置
  action:
    - service: xiaomi_aqara.play_ringtone
      data: {"gw_mac":"7C49xx","ringtone_id": "0","ringtone_vol": "100"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '1'
ringalarm 为1的时候等待8秒(报警声0持续8秒),触发报警声1 并且设定ringalarm 为2
- alias: alarm number alarm
  initial_state: true
  hide_entity: false
  trigger:
   - platform: state
     entity_id: input_number.ringalarm
     to: '1.0'
     for:
       seconds: 8
  action:
    - service: xiaomi_aqara.play_ringtone
      data: {"gw_mac":"7C49xx","ringtone_id": "1","ringtone_vol": "100"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '2'
ringalarm 为2的时候等待15秒(报警声1持续15秒),触发报警声2 并且设定ringalarm 为3
- alias: alarm number alarm
  initial_state: true
  hide_entity: false
  trigger:
   - platform: state
     entity_id: input_number.ringalarm
     to: '2.0'
     for:
       seconds: 15
  action:
    - service: xiaomi_aqara.play_ringtone
      data: {"gw_mac":"7C49xx","ringtone_id": "2","ringtone_vol": "100"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '3'
ringalarm 为3的时候等待10秒(报警声2持续10秒),触发报警声7 并且设定ringalarm 为1
- alias: alarm number alarm
  initial_state: true
  hide_entity: false
  trigger:
   - platform: state
     entity_id: input_number.ringalarm
     to: '3.0'
     for:
       seconds: 10
  action:
    - service: xiaomi_aqara.play_ringtone
      data: {"gw_mac":"7C49xx","ringtone_id": "7","ringtone_vol": "100"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '1'

魔方翻转90度设定 ringalarm为0,停止报警,ringalarm设定多次,是为了确保关闭,另外先翻转再开门可以避免报警
- alias: flip90 disable alarm
  initial_state: true
  trigger:
    - platform: event
      event_type: xiaomi_aqara.cube_action
      event_data:
        entity_id: binary_sensor.cube_158dxx
        action_type: flip90
  action:
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.kaimen
    - service: xiaomi_aqara.stop_ringtone
      data: {"gw_mac":"7C49xx"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '0'
    - delay: '00:00:02'
    - service: xiaomi_aqara.stop_ringtone
      data: {"gw_mac":"7C49xx"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '0'
    - delay: '00:00:02'
    - service: xiaomi_aqara.stop_ringtone
      data: {"gw_mac":"7C49xx"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '0'
    - delay: '00:00:02'
    - service: xiaomi_aqara.stop_ringtone
      data: {"gw_mac":"7C49xx"}
    - service: input_number.set_value
      data_template:
        entity_id: input_number.ringalarm
        value: '0'

评分

参与人数 1金钱 +1 收起 理由
jick + 1 感谢楼主分享!

查看全部评分

回复

使用道具 举报

8

主题

2073

帖子

6053

积分

论坛元老

流水无味

Rank: 8Rank: 8

积分
6053
金钱
3980
HASS币
145

灌水之王

发表于 2019-3-4 20:50:39 | 显示全部楼层
我的小米网关 不会叫了 变哑巴了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-24 17:51 , Processed in 0.448059 second(s), 26 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表