Alarm tripping automation preventing false positives

This is my alarm setup at present, I’m a noob at home assistant, having only set it up a month ago and I don’t have an I.T. background, so feel free to suggest some improves.

The idea is as follows:

  • Trigger the alarm only if two different sensors trigger within 15 minutes of each other.
  • Have a toggle for whether the alarm is armed or not armed.
  • Send a notification when the alarm is triggered telling me which two sensors triggered the alarm.
  • Have a toggle for when the alarm is tripped, so you can base other automations on whether the alarm is tripped, and un-trip the alarm after 20 minutes (ie so your alarm isn’t going all day and night)

Configuration.yaml

notify:
  - name: html5
    platform: html5
    gcm_api_key: 'XXXXXXXXXXXXXXXXXXXXXX'
    gcm_sender_id: 'XXXXXXXXXXXXXX'

input_boolean:
  alarm_tripped:
    name: Alarm Tripped
    initial: off
  alarm_armed:
    name: Alarm Armed
    initial: off

input_text:
  alarm_trigger_one:
    initial: none
  alarm_trigger_two:
    initial: none

timer:
  alarm_triggered: # Time between 2x sensor tripping to trigger alarm_armed
    duration: '00:15:00'
  alarm_tripped: # How long the alarm will go on for before reseting
    duration: '00:20:00'

Automation.yaml

- alias: "Alarm: First trigger"
  trigger:
    - platform: state # Door and window
      entity_id: binary_sensor.door_window_sensor_158d0001d63b07, binary_sensor.door_window_sensor_158d0001ef77d8, binary_sensor.door_window_sensor_158d0001fa792d, binary_sensor.door_window_sensor_158d0001a94c35, binary_sensor.door_window_sensor_158d0001f9e2e2, binary_sensor.door_window_sensor_158d0001f38b1f
      from: 'off'
      to: 'on'
    - platform: state # Motion
      entity_id: binary_sensor.motion_sensor_158d0001e57659, binary_sensor.motion_sensor_158d0001e52dee, binary_sensor.motion_sensor_158d0001dc7526
      from: 'off'
      to: 'on'
  condition:
    - condition: state
      entity_id: input_boolean.alarm_armed
      state: 'on'
    - condition: template
      value_template: '{{ is_state("timer.alarm_triggered", "idle") }}'
  action:
    - service: timer.start
      entity_id: timer.alarm_triggered
    - service: input_text.set_value
      data_template:
        entity_id: input_text.alarm_trigger_one
        value: '{{ trigger.to_state.attributes.friendly_name }}'

- alias: "Alarm: Second trigger"
  trigger:
    - platform: state # Door and window
      entity_id: binary_sensor.door_window_sensor_158d0001d63b07, binary_sensor.door_window_sensor_158d0001ef77d8, binary_sensor.door_window_sensor_158d0001fa792d, binary_sensor.door_window_sensor_158d0001a94c35, binary_sensor.door_window_sensor_158d0001f9e2e2, binary_sensor.door_window_sensor_158d0001f38b1f
      from: 'off'
      to: 'on'
    - platform: state # Motion
      entity_id: binary_sensor.motion_sensor_158d0001e57659, binary_sensor.motion_sensor_158d0001e52dee, binary_sensor.motion_sensor_158d0001dc7526
      from: 'off'
      to: 'on'
  condition:
    - condition: state
      entity_id: input_boolean.alarm_armed
      state: 'on'
    - condition: template
      value_template: '{{ is_state("timer.alarm_triggered", "active") }}'
    - condition: template
      value_template: '{{ states("input_text.alarm_trigger_one") != trigger.to_state.attributes.friendly_name }}'
  action:
    - service: timer.cancel
      entity_id: timer.alarm_triggered
    - service: input_boolean.turn_on
      data:
        entity_id: input_boolean.alarm_tripped
    - service: input_text.set_value
      data_template:
        entity_id: input_text.alarm_trigger_two
        value: '{{ trigger.to_state.attributes.friendly_name }}'
        
- alias: "Alarm: Tripped"
  trigger:
    - platform: state
      entity_id: input_boolean.alarm_tripped
      to: 'on'
  action:
    - service: timer.start
      entity_id: timer.alarm_tripped
    - service: timer.cancel
      entity_id: timer.alarm_triggered
    - service: notify.html5
      data_template:
        message: 'Alarm has been tripped by {{ states("input_text.alarm_trigger_one") }} and {{ states("input_text.alarm_trigger_two") }}'
      data:
        data:
          tag: 'home assistant'
          
- alias: "Alarm: Un-tripped"
  trigger:
    - platform: event
      event_type: timer.finished
      event_data: 
        entity_id: timer.alarm_tripped
    - platform: state
      entity_id: input_boolean.alarm_tripped
      to: 'off'
  action:
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.alarm_tripped
    - service: timer.cancel
      entity_id: timer.alarm_triggered
    - service: timer.cancel
      entity_id: timer.alarm_tripped
    - service: input_text.set_value
      data:
        entity_id: input_text.alarm_trigger_one
        value: 'none'
    - service: input_text.set_value
      data:
        entity_id: input_text.alarm_trigger_two
        value: 'none'
1 Like