Publicado en Home-Assistant

Control de Alarma con notificaciones de alerta para Home Assistant


Implementar sistema de control de alarma inteligente para Home Assistant, detección de apertura de puertas, ventanas y presencia, cuando la alarma este armada en modo armed_home o armed_away al detectar un cambio de sensor, notifique cual sensor se ha activado, de esa forma se consigue tener un mejor seguimiento de la incidencia.

Declaración de los elementos para la automatización

Escoger los sensores que pueden iniciar la alerta de alarma

#Puertas
binary_sensor.entrance_door, binary_sensor.back_door

#Ventanas
binary_sensor.bathroom_window, binary_sensor.dinning_room_window, binary_sensor.kitchen_window, binary_sensor.main_bedroom_window

En las automatizaciones en la propiedad entitity_id se puede añadir múltiples sensores separados por coma

- alias: 'Trigger alarm while armed home'
  trigger:
    - platform: state
      entity_id: binary_sensor.entrance_door, binary_sensor.back_door
      to: 'on'
    - platform: state
      entity_id: binary_sensor.bathroom_window, binary_sensor.dinning_room_window, binary_sensor.kitchen_window, binary_sensor.main_bedroom_window
      to: 'on'

Establecer la condición de la alarma cuando su estado sea modo casa(armed_home)

  condition:
    - condition: state
      entity_id: alarm_control_panel.home_alarm
      state: armed_home

En la acción añadir que avise mediante un servicio de notificación, en este caso por Telegram, y para obtener el nombre del sensor que a iniciado la automatización se puede con:

 {{ trigger.to_state.attributes.friendly_name }}  
  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.home_alarm
    - service: notify.telegram_notify
      data_template:
        message: '{{ trigger.to_state.attributes.friendly_name }} opened'
      data:
        title: 'ALERTA!!!'

Automatización: Notificar alerta de alarma en mode home

- alias: 'Trigger alarm while armed home'
  trigger:
    - platform: state
      entity_id: binary_sensor.entrance_door, binary_sensor.back_door
      to: 'on'
    - platform: state
      entity_id: binary_sensor.bathroom_window, binary_sensor.dinning_room_window, binary_sensor.kitchen_window, binary_sensor.main_bedroom_window
      to: 'on'
  condition:
    - condition: state
      entity_id: alarm_control_panel.home_alarm
      state: armed_home
  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.home_alarm
    - service: notify.telegram_notify
      data_template:
        message: '{{ trigger.to_state.attributes.friendly_name }} opened'
      data:
        title: 'ALERTA!!!'


Automatización: Notificar alerta de alarma en mode away

- alias: 'Trigger alarm while armed away'
  trigger:
    - platform: state
      entity_id: binary_sensor.entrance_door, binary_sensor.back_door
      to: 'on'
    - platform: state
      entity_id: binary_sensor.dinning_room_motion, binary_sensor.garage_motion, binary_sensor.garden_motion, binary_sensor.kitchen_motion
      to: 'on'
    - platform: state
      entity_id: binary_sensor.bathroom_window, binary_sensor.dinning_room_window, binary_sensor.kitchen_window, binary_sensor.main_bedroom_window
      to: 'on'
  condition:
    - condition: state
      entity_id: alarm_control_panel.home_alarm
      state: armed_away
  action:
    - service: alarm_control_panel.alarm_trigger
      entity_id: alarm_control_panel.home_alarm
    - service: notify.telegram_notify
      data_template:
        message: '{{ trigger.to_state.attributes.friendly_name }} opened'
      data:
        title: 'ALERTA!!!'