Sistema de Alarma para HASS + Xiaomi Gateway

Hola a todos,

En esta entrada voy a detallar como montar un sistema de alarma completo combinando el Gateway de Xiaomi, sus sensores y HomeAssistant.

Voy a dar por sentado que ya tenemos el Gateway integrado en HASS y los sensores configurados.

Yo particularmente siempre trabajo por SSH directamente contra el servidor, así que para todo el proceso utilizaremos PuttY

Nos conectamos por SSH con nuestro usuario homeassistant e ingresamos en el directorio del entorno:

 

 

 

 

En nuestro configuration.yaml agregamos lo siguiente: (nano configuration.yaml)

[yaml]

alarm_control_panel: !include alarm.yaml
panel_custom: !include panel_custom.yaml

[/yaml]

Guardamos (ctrl+o y ctrl+x)

Ahora deberemos crear los archivos que hemos indicado anteriormente.

nano alarm.yaml

[yaml]

platform: bwalarm
name: House

code: !secret alarm_code #Code, should consist of one or more digits ie 6482
panic_code: !secret panic_code #[OPTIONAL] Panic Code should consist of one or more digits ie 9876, it needs to be different to your standard alarm code. This enables a special panic mode. This can be used under duress to deactivate the alarm which would appear to the unseeing eye as deactivated however a special attribute [panic_mode] listed under the alarm_control_panel.[identifier] will change to ACTIVE. This status could be used in your automations to send a notification to someone else police/spouse/sibling/neighbour that you are under duress. To deactive this mode arm then disarm your alarm in the usual manner.

pending_time: 25 #Grace time in seconds to allow for exit and entry using Away mode
trigger_time: 600

alarm: automation.alarm_triggered
warning: automation.alarm_warning

clock: True #Optional – True enables a clock in the center of the status bar
perimeter_mode: False #Optional – True enables perimeter mode, this could be known as ‘Day Mode’ i.e. only arm the doors whilst there is someone using all floors
weather: True #Optional – Allows a weather summary to be displayed on the status bar. Dark Sky weather component must be enabled with the name sensor.dark_sky_summary

#### COLOURS ########### Use any HTML format
warning_colour: ‘orange’
pending_colour: ‘orange’
disarmed_colour: ‘#03A9F4’
armed_home_colour: ‘black’
armed_away_colour: ‘black’
triggered_colour: ‘red’

############# SENSOR GROUPS ########################
# Sensors in this group tigger the alarm immediately
immediate:
# – binary_sensor.door_window_sensor_158d0001a5e1a3
# – binary_sensor.door_window_sensor_158d0001a99eb0
– binary_sensor.door_window_sensor_xxxxxxxxxxxx

# Sensors in this group start the clock (pending_time) when tripped before the alarm is activated in ‘Away’ mode
delayed:
– binary_sensor.door_window_sensor_xxxxxxxx
– binary_sensor.door_window_sensor_158d0001a5e1a3
– binary_sensor.door_window_sensor_158d0001a99eb0

# Same as notathome but hopefully the title is more self explanatory. Can still use notathome for backwards compatibility
# Note sensors can exist in more than one group notice top_floor appears in two groups
homemodeignore:
– binary_sensor.door_window_sensor_xxxxxxxxx

# Use this group to automatically override the warning message on open sensors when setting ‘away’ mode. (I use this as I have a motion sensor at the front door)
override:
– binary_sensor.door_window_sensor_xxxxxxxxxxxxxxxxxxx

# This group is special and only effects ‘perimeter mode’. If perimeter_mode is enabled then any sensor in this group will trigger the alarm immediately if arm perimeter is set. There is no delayed group for this mode (unless requested as a feature of course!)
perimeter:
– binary_sensor.garage_door_sensor

[/yaml]

Mostrar Código

Y guardamos.

Ahora, nano panel_custom.yaml

[yaml]

– name: alarm
sidebar_title: Alarm
sidebar_icon: mdi:security-home
config:
alarmid: alarm_control_panel.house ## USE THE SAME ID AS USED IN YOUR ALARM.YAML

[/yaml]

Mostrar Código

Y guardamos.

Ahora, creamos el directorio panels.

mkdir panels
cd panels
nano alarm.html

[html]


 

 

  Alarma de Casa

 

[[hours]]
:
[[meridiem]]

[[minutes]]

 

[[temp]] °C
[[weather.state]]

 

 

  Alarma Desactivada
Perimeter Mode
Modo Noche Modo Fuera de Casa

 

 

[[computeLabel(alarm.state)]] Mode Activated   [[code]]
123Desarmar
456Borrar
7890

 

 

[[opencount]]x Open Sensors

 

 

Sensores Inmediatos

 

 

Sensores Retrasados
Sensores Inmediatos

 

Todos los Sensores

 

Sensores Inactivos

 

 

 

Settings
Calvert
Residence
Disarmed

 

[/html]

 

Mostrar Código

Y guardamos.

Al final de la entrada dejo un .zip con las dependencias JS que habrá que dejar en el directorio www/lib/ de nuestra instalación HA. Si quieres puedes cargarlas con wget así:

[bash]

cd /home/homeassistant/.homeassistant/www

mkdir lib

cd lib

wget http://domology.es/wp-content/uploads/2018/01/countdown360.js

wget http://domology.es/wp-content/uploads/2018/01/jquery-3.2.1.min.js

[/bash]

 

Volvemos un directorio atrás

cd ../

y entramos en el directorio custom_components (si no existe lo creas) la ruta completa sería /home/homeassistant/.homeassistant/custom_components

cd custom_components

crear el directorio alarm_control_panel

mkdir alarm_control_panel

y crear el fichero bwalarm.py

nano bwalarm.py

[python]

“””
My take on the manual alarm control panel
“””
import asyncio
import datetime
import logging
import enum
import re
import voluptuous as vol
from operator import attrgetter

from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_HOME, STATE_ALARM_DISARMED,
STATE_ALARM_PENDING, STATE_ALARM_TRIGGERED, CONF_PLATFORM, CONF_NAME,
CONF_CODE, CONF_PENDING_TIME, CONF_TRIGGER_TIME, CONF_DISARM_AFTER_TRIGGER,
EVENT_STATE_CHANGED, EVENT_TIME_CHANGED,
STATE_ON)
from homeassistant.util.dt import utcnow as now
from homeassistant.helpers.event import async_track_point_in_time
import homeassistant.components.alarm_control_panel as alarm
import homeassistant.components.switch as switch
import homeassistant.helpers.config_validation as cv

STATE_TRUE = ‘true’
STATE_UNLOCKED = ‘unlocked’
STATE_OPEN = ‘open’
STATE_DETECTED = ‘detected’

CONF_PANIC_CODE = ‘panic_code’
CONF_IMMEDIATE = ‘immediate’
CONF_DELAYED = ‘delayed’
CONF_IGNORE = ‘homemodeignore’
CONF_NOTATHOME = ‘notathome’
CONF_OVERRIDE = ‘override’
CONF_PERIMETER_MODE = ‘perimeter_mode’
CONF_PERIMETER = ‘perimeter’
CONF_ALARM = ‘alarm’
CONF_WARNING = ‘warning’

CONF_WARNING_COLOUR = ‘warning_colour’
CONF_PENDING_COLOUR = ‘pending_colour’
CONF_DISARMED_COLOUR = ‘disarmed_colour’
CONF_TRIGGERED_COLOUR = ‘triggered_colour’
CONF_ARMED_AWAY_COLOUR = ‘armed_away_colour’
CONF_ARMED_HOME_COLOUR = ‘armed_home_colour’

CONF_CLOCK = ‘clock’
CONF_WEATHER = ‘weather’

# Add a new state for the time after an delayed sensor and an actual alarm
STATE_ALARM_WARNING = ‘warning’
STATE_ALARM_ARMED_PERIMETER = ‘armed_perimeter’
class Events(enum.Enum):
ImmediateTrip = 1
DelayedTrip = 2
ArmHome = 3
ArmAway = 4
Timeout = 5
Disarm = 6
Trigger = 7
ArmPerimeter = 8

PLATFORM_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): ‘bwalarm’,
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_PENDING_TIME): vol.All(vol.Coerce(int), vol.Range(min=0)),
vol.Required(CONF_TRIGGER_TIME): vol.All(vol.Coerce(int), vol.Range(min=1)),
vol.Required(CONF_ALARM): cv.entity_id, # switch/group to turn on when alarming
vol.Required(CONF_WARNING): cv.entity_id, # switch/group to turn on when warning
vol.Optional(CONF_CODE): cv.string,
vol.Optional(CONF_PANIC_CODE): cv.string,
vol.Optional(CONF_IMMEDIATE): cv.entity_ids, # things that cause an immediate alarm
vol.Optional(CONF_DELAYED): cv.entity_ids, # things that allow a delay before alarm
vol.Optional(CONF_IGNORE): cv.entity_ids, # things that we ignore when at home
vol.Optional(CONF_NOTATHOME): cv.entity_ids, # things that we ignore when at home BACKWARDS COMPAT
vol.Optional(CONF_OVERRIDE): cv.entity_ids, # sensors that can be ignored if open when trying to set alarm in away mode
vol.Optional(CONF_PERIMETER_MODE): cv.boolean, # Enable perimeter mode?
vol.Optional(CONF_PERIMETER): cv.entity_ids, # things monitored under perimeter mode
vol.Optional(CONF_WARNING_COLOUR): cv.string, # Custom colour of warning display
vol.Optional(CONF_PENDING_COLOUR): cv.string, # Custom colour of pending display
vol.Optional(CONF_DISARMED_COLOUR): cv.string, # Custom colour of disarmed display
vol.Optional(CONF_TRIGGERED_COLOUR): cv.string, # Custom colour of triggered display
vol.Optional(CONF_ARMED_AWAY_COLOUR): cv.string, # Custom colour of armed away display
vol.Optional(CONF_ARMED_HOME_COLOUR): cv.string, # Custom colour of armed home display
vol.Optional(CONF_CLOCK): cv.boolean, # DIsplay clock on panel
vol.Optional(CONF_WEATHER): cv.boolean # DIsplay weather on panel
})

_LOGGER = logging.getLogger(__name__)

@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
alarm = BWAlarm(hass, config)
hass.bus.async_listen(EVENT_STATE_CHANGED, alarm.state_change_listener)
hass.bus.async_listen(EVENT_TIME_CHANGED, alarm.time_change_listener)
async_add_devices([alarm])

class BWAlarm(alarm.AlarmControlPanel):

def __init__(self, hass, config):
“”” Initalize the alarm system “””
self._hass = hass
self._name = config[CONF_NAME]
self._immediate = set(config.get(CONF_IMMEDIATE, []))
self._delayed = set(config.get(CONF_DELAYED, []))
self._ignore = set(config.get(CONF_IGNORE, []) if config.get(CONF_IGNORE, []) != [] else config.get(CONF_NOTATHOME, []))
self._override = set(config.get(CONF_OVERRIDE, []))
self._perimeter_mode = config.get(CONF_PERIMETER_MODE, False)
self._perimeter = set(config.get(CONF_PERIMETER, []))
self._allsensors = self._immediate | self._delayed | self._ignore
#self._allsensors = self._allinputs
self._alarm = config[CONF_ALARM]
self._warning = config[CONF_WARNING]
self._code = config[CONF_CODE] if config[CONF_CODE] else None
self._panic_code = config.get(CONF_PANIC_CODE, None)

self._countdown_time = config[CONF_PENDING_TIME]
self._pending_time = datetime.timedelta(seconds=config[CONF_PENDING_TIME])
self._trigger_time = datetime.timedelta(seconds=config[CONF_TRIGGER_TIME])

self._lasttrigger = “”
self._state = STATE_ALARM_DISARMED
self._returnto = STATE_ALARM_DISARMED
self._timeoutat = None

self._warning_colour = config.get(CONF_WARNING_COLOUR, ‘orange’)
self._pending_colour = config.get(CONF_PENDING_COLOUR, ‘orange’)
self._disarmed_colour = config.get(CONF_DISARMED_COLOUR, ‘#03A9F4’)
self._triggered_colour = config.get(CONF_TRIGGERED_COLOUR, ‘red’)
self._armed_away_colour = config.get(CONF_ARMED_AWAY_COLOUR, ‘black’)
self._armed_home_colour = config.get(CONF_ARMED_HOME_COLOUR, ‘black’)

self._panic_mode = “deactivated”

self._clock = config.get(CONF_CLOCK, False)
self._weather = config.get(CONF_WEATHER, False)

self.clearsignals()

### Alarm properties
@property
def should_poll(self) -> bool: return False
@property
def name(self) -> str: return self._name
@property
def changed_by(self) -> str: return self._lasttrigger
@property
def state(self) -> str: return self._state
@property
def device_state_attributes(self):
return {
‘immediate’: sorted(list(self.immediate)),
‘delayed’: sorted(list(self.delayed)),
‘override’: sorted(list(self._override)),
‘ignored’: sorted(list(self.ignored)),
‘allsensors’: sorted(list(self._allsensors)),
‘perimeter_mode’: self._perimeter_mode,
‘perimeter’: sorted(list(self._perimeter)),
‘changedby’: self.changed_by,
‘warning_colour’: self._warning_colour,
‘pending_colour’: self._pending_colour,
‘disarmed_colour’: self._disarmed_colour,
‘triggered_colour’: self._triggered_colour,
‘armed_home_colour’: self._armed_home_colour,
‘armed_away_colour’: self._armed_away_colour,
‘panic_mode’: self._panic_mode,
‘countdown_time’: self._countdown_time,
‘clock’: self._clock,
‘weather’: self._weather
}

### Actions from the outside world that affect us, turn into enum events for internal processing
def time_change_listener(self, eventignored):
“”” I just treat the time events as a periodic check, its simpler then (re-/un-)registration “””
if self._timeoutat is not None:
if now() > self._timeoutat:
self._timeoutat = None
self.process_event(Events.Timeout)

def state_change_listener(self, event):
“”” Something changed, we only care about things turning on at this point “””
new = event.data.get(‘new_state’, None)
if new is None:
return
if new.state.lower() == STATE_ON or new.state.lower() == STATE_TRUE or new.state.lower() == STATE_UNLOCKED or new.state.lower() == STATE_OPEN or new.state.lower() == STATE_DETECTED:
eid = event.data[‘entity_id’]
if eid in self.immediate:
self._lasttrigger = eid
self.process_event(Events.ImmediateTrip)
elif eid in self.delayed:
self._lasttrigger = eid
self.process_event(Events.DelayedTrip)

@property
def code_format(self):
“””One or more characters.”””
return None if self._code is None else ‘.+’

def alarm_disarm(self, code=None):

#If the provided code matches the panic alarm then deactivate the alarm but set the state of the panic mode to active.
if self._validate_panic_code(code):
self.process_event(Events.Disarm)
self._panic_mode = “ACTIVE”
# Let HA know that something changed
self.schedule_update_ha_state()
return

if not self._validate_code(code, STATE_ALARM_DISARMED):
return
self.process_event(Events.Disarm)

def alarm_arm_home(self, code):
self.process_event(Events.ArmHome)

def alarm_arm_away(self, code=None):
self.process_event(Events.ArmAway)

def alarm_arm_night(self, code=None):
self.process_event(Events.ArmPerimeter)

def alarm_trigger(self, code=None):
self.process_event(Events.Trigger)

### Internal processing
def setsignals(self, alarmMode):
“”” Figure out what to sense and how “””
if alarmMode == Events.ArmHome or alarmMode == Events.ArmAway:
self.immediate = self._immediate.copy()
self.delayed = self._delayed.copy()
if alarmMode == Events.ArmHome:
self.immediate -= self._ignore
self.delayed -= self._ignore
if alarmMode == Events.ArmPerimeter:
self.immediate = self._perimeter.copy()
self.ignored = self._allsensors – (self.immediate | self.delayed)

def clearsignals(self):
“”” Clear all our signals, we aren’t listening anymore “””
self._panic_mode = “deactivated”
self.immediate = set()
self.delayed = set()
self.ignored = self._allsensors.copy()

def process_event(self, event):
old = self._state

# Update state if applicable
if event == Events.Disarm:
self._state = STATE_ALARM_DISARMED
elif event == Events.Trigger:
self._state = STATE_ALARM_TRIGGERED
elif old == STATE_ALARM_DISARMED:
if event == Events.ArmHome: self._state = STATE_ALARM_ARMED_HOME
elif event == Events.ArmAway: self._state = STATE_ALARM_PENDING
elif event == Events.ArmPerimeter: self._state = STATE_ALARM_ARMED_PERIMETER
elif old == STATE_ALARM_PENDING:
if event == Events.Timeout: self._state = STATE_ALARM_ARMED_AWAY
elif old == STATE_ALARM_ARMED_HOME or \
old == STATE_ALARM_ARMED_AWAY or \
old == STATE_ALARM_ARMED_PERIMETER:
if event == Events.ImmediateTrip: self._state = STATE_ALARM_TRIGGERED
elif event == Events.DelayedTrip: self._state = STATE_ALARM_WARNING
elif old == STATE_ALARM_WARNING:
if event == Events.Timeout: self._state = STATE_ALARM_TRIGGERED
elif old == STATE_ALARM_TRIGGERED:
if event == Events.Timeout: self._state = self._returnto

new = self._state
if old != new:
_LOGGER.debug(“Alarm changing from {} to {}”.format(old, new))
# Things to do on entering state
if new == STATE_ALARM_WARNING:
_LOGGER.debug(“Turning on warning”)
switch.turn_on(self._hass, self._warning)
self._timeoutat = now() + self._pending_time
elif new == STATE_ALARM_TRIGGERED:
_LOGGER.debug(“Turning on alarm”)
switch.turn_on(self._hass, self._alarm)
self._timeoutat = now() + self._trigger_time
elif new == STATE_ALARM_PENDING:
_LOGGER.debug(“Pending user leaving house”)
switch.turn_on(self._hass, self._warning)
self._timeoutat = now() + self._pending_time
self._returnto = STATE_ALARM_ARMED_AWAY
self.setsignals(Events.ArmAway)
elif new == STATE_ALARM_ARMED_HOME:
self._returnto = new
self.setsignals(Events.ArmHome)
elif new == STATE_ALARM_ARMED_AWAY:
self._returnto = new
self.setsignals(Events.ArmAway)
elif new == STATE_ALARM_ARMED_PERIMETER:
self._returnto = new
self.setsignals(Events.ArmPerimeter)
elif new == STATE_ALARM_DISARMED:
self._returnto = new
self.clearsignals()

# Things to do on leaving state
if old == STATE_ALARM_WARNING or old == STATE_ALARM_PENDING:
_LOGGER.debug(“Turning off warning”)
switch.turn_off(self._hass, self._warning)
elif old == STATE_ALARM_TRIGGERED:
_LOGGER.debug(“Turning off alarm”)
switch.turn_off(self._hass, self._alarm)

# Let HA know that something changed
self.schedule_update_ha_state()

def _validate_code(self, code, state):
“””Validate given code.”””
check = self._code is None or code == self._code
if not check:
_LOGGER.debug(“Invalid code given for %s”, state)
return check

def _validate_panic_code(self, code):
“””Validate given code.”””
check = code == self._panic_code
if check:
_LOGGER.warning(“[ALARM] PANIC MODE ACTIVATED!!!”)
return check

[/python]

Mostrar Código

Guardamos y listo, ya tenemos todos los ficheros necesarios, ahora simplemente faltaria crear la automatizacion y subir las voces al Gateway de Xiaomi mediante la APP Mi Home.

Los sonidos personalizados del GW de Xiaomi empiezan por el ID 10004, debereis ir llamandolos en el script de automatizacion segun el orden de vuestro GW.

Aqui os dejo mi Automation de ejemplo.

[yaml]
– id: alarm_armed_away
alias: ‘[Alarm] Away Mode Armed’
trigger:
– platform: state
entity_id: alarm_control_panel.house
to: ‘armed_away’
action:
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 10010 # Alarma Activada.
ringtone_vol: 100
– service: switch.turn_on
entity_id: switch.cerrarentrada
– service: notify.telegram
data:
message: “* Alarma Activada*. Adios :)”
– service: climate.set_temperature
data:
entity_id: climate.aa_fujitsu
temperature: 23
operation_mode: Apagado
– service: input_boolean.turn_on
data:
entity_id: input_boolean.alarma_casa

– id: alarm_armed_home
alias: ‘[Alarm] Home Mode Armed’
trigger:
– platform: state
entity_id: alarm_control_panel.house
to: ‘armed_home’
action:
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 10011 # Modo casa activado. Buenas noches
ringtone_vol: 50
– service: notify.telegram
data:
message: “*Modo noche activado*. Buenas noches.”
– service: input_boolean.turn_on
data:
entity_id: input_boolean.alarma_casa

– id: alarm_arming_away
alias: ‘[Alarm] Away Mode Arming’
trigger:
– platform: state
entity_id: alarm_control_panel.house
to: ‘pending’
action:
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 10012 # Activando alarma, revisa que puertas y ventanas esten cerradas
ringtone_vol: 100
– delay:
seconds: 8
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 10017 # Contador 22 Segundos
ringtone_vol: 100

– id: alarm_disarmed
alias: ‘[Alarm] Disarmed’
trigger:
– platform: state
entity_id: alarm_control_panel.house
to: ‘disarmed’
action:
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 10014 # Alarma desactivada
ringtone_vol: 100
– service: input_boolean.turn_off
data:
entity_id: input_boolean.alarma_casa
– service: notify.telegram
data:
message: “Alarma *desactivada*”
– service: automation.turn_off
entity_id: automation.sirena1
– service: automation.turn_off
entity_id: automation.sirena2
– service: automation.turn_off
entity_id: automation.sirena3

– id: alarm_triggered
alias: ‘[Alarm] Triggered’
trigger:
– platform: state
entity_id: alarm_control_panel.house
to: ‘triggered’
action:
– service: automation.turn_on
entity_id: automation.sirena1
# – service: switch.turn_on
# entity_id: switch.siren_switch
– service: notify.telegram
data:
message: ‘HA SALTADO LA ALARMA!!! {{ states[states.alarm_control_panel.house.attributes.changed_by.split(“.”)[0]][ states.alarm_control_panel.house.attributes.changed_by.split(“.”)[1]].name }}’

– id: alarm_warning
alias: ‘[Alarm] Warning’
trigger:
– platform: state
entity_id: alarm_control_panel.house
to: ‘warning’
action:
– service: notify.telegram
data:
message: ‘ALARM Warning {{ states[states.alarm_control_panel.house.attributes.changed_by.split(“.”)[0]][ states.alarm_control_panel.house.attributes.changed_by.split(“.”)[1]].name }}’
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 10013 # Se ha disparado la alarma, por favor desactivar.
ringtone_vol: 100

####################################################
################# P U L S A D O R #################
####################################################
– alias: “Alarma Casa on”
trigger:
– platform: state
entity_id: input_boolean.alarma_casa
to: ‘on’
action:
– service: alarm_control_panel.alarm_arm_away
data:
entity_id: alarm_control_panel.house
# code: !secret alarm_code

– alias: “Alarma Casa off”
trigger:
– platform: state
entity_id: input_boolean.alarma_casa
to: ‘off’
action:
– service: alarm_control_panel.alarm_disarm
data:
entity_id: alarm_control_panel.house
code: !secret alarm_code

####################################################
################# S I R E N A ######################
####################################################
– alias: “Sirena1”
initial_state: False
hide_entity: False
trigger:
– platform: state
entity_id: automation.sirena1
from: ‘off’
to: ‘on’
condition:
– condition: state
entity_id: alarm_control_panel.house
state: ‘triggered’
action:
– service: automation.turn_off
entity_id: automation.sirena3
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 2
ringtone_vol: 100
– delay:
seconds: 4
– service: automation.turn_on
entity_id: automation.sirena2

– alias: “Sirena2”
initial_state: False
hide_entity: False
trigger:
– platform: state
entity_id: automation.sirena2
from: ‘off’
to: ‘on’
condition:
– condition: state
entity_id: alarm_control_panel.house
state: ‘triggered’
action:
– service: automation.turn_off
entity_id: automation.sirena1
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 2
ringtone_vol: 100
– delay:
seconds: 4
– service: automation.turn_on
entity_id: automation.sirena3

– alias: “Sirena3”
initial_state: False
hide_entity: False
trigger:
– platform: state
entity_id: automation.sirena3
from: ‘off’
to: ‘on’
condition:
– condition: state
entity_id: alarm_control_panel.house
state: ‘triggered’
action:
– service: automation.turn_off
entity_id: automation.sirena2
– service: xiaomi_aqara.play_ringtone
data:
gw_mac: 34:ce:00:88:xx:xx
ringtone_id: 2
ringtone_vol: 100
– delay:
seconds: 4
– service: automation.turn_on
entity_id: automation.sirena1
[/yaml]

Mostrar Código

Por ultimo os dejo un paquete con todos los ficheros y las Voces que tengo generadas para esa automatización.

 

Alarma HASS+XiaomiGW-ESP-ByRubenzori86

 

Si queréis mas información sobre esta alarma podéis visitar al creador de la misma en GitHub.

https://github.com/gazoscalvertos/Hass-Custom-Alarm

12 comentarios sobre “Sistema de Alarma para HASS + Xiaomi Gateway

Deja un comentario

Síguenos

Siguenos en facebook