This commit is contained in:
monster
2018-12-30 14:13:57 +03:00
parent e311c31b88
commit 2033fe79e4
225 changed files with 6370 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import appdaemon.plugins.hass.hassapi as hass
import globals
#
# Управление замком Xiaomi
#
# Args:
#
# None
#
# Release Notes
#
# Version 1.0:
# Initial Version
class Lock(hass.Hass):
def initialize(self):
self.listen_event_handle_list = []
if not globals.check_args(self, ['notify']):
return
locks = globals.get_group_entities(self, "group.all_locks")
for lock in locks:
self.listen_event_handle_list.append(self.listen_state(self.lock_state_changed, lock))
def lock_state_changed(self, entity, attribute, old, new, kwargs):
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
return
state = new
changed_by = self.get_state(entity, attribute = 'changed_by')
verified_wrong_times = self.get_state(entity, attribute = 'verified_wrong_times')
if verified_wrong_times > 0:
message = "Попытка №{} отрыть замок с неправильным пальцем или паролем!".format(verified_wrong_times)
self.notify(message, name = self.args['notify'])
if state == "unlocked":
user = changed_by
user_var = "user_{}".format(changed_by)
if user_var in self.args:
user = self.args[user_var]
message = "Открыта дверь пользователем: {}.".format(user)
self.notify(message, name = self.args['notify'])
@@ -0,0 +1,11 @@
lock:
module: lock
class: Lock
constraint: input_boolean.lock_report
user_65536: Данил (указ)
user_65537: Данил (сред)
user_65538: Света (указ)
user_65539: Мама (указ)
notify: telegram
global_dependencies:
- globals
@@ -0,0 +1,48 @@
import appdaemon.plugins.hass.hassapi as hass
#
# Security sensors alarm notification
# Send notification if some movement is detecter or door any is open
# while nobody is home
#
# Args:
# sensor - gorup of sensors to listen
# ha_panel - alarm panel entity
# notify - notify entity to send message
#
# Release Notes
#
# Version 1.0:
# Initial Version
class SecuritySensorsReport(hass.Hass):
def initialize(self):
if 'sensor' not in self.args or 'ha_panel' not in self.args or 'notify' not in self.args:
self.error("Please provide sensor, ha_panel and notify in config!")
return
attributes = self.get_state(self.args['sensor'], attribute = "all")
if 'attributes' in attributes:
attributes = attributes['attributes']
if 'entity_id' in attributes:
for entity_id in attributes['entity_id']:
self.listen_state(self.sensor_trigger, entity_id)
def sensor_trigger(self, entity, attribute, old, new, kwargs):
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
return
if old != new and new == "on":
alarm_panel_state = self.get_state(self.args['ha_panel'])
if alarm_panel_state != "armed_away":
return
self.alarm_triggered(entity, old, new)
def alarm_triggered(self, entity, old, new):
self.log('alarm triggered')
self.call_service("alarm_control_panel/alarm_trigger", entity_id = self.args['ha_panel'])
friendly_name = self.friendly_name(entity)
entity = entity.replace('_', '-')
message = "В ваше отсутствие сработал датчик безопастности {} ({}) = {}->{}!".format(friendly_name, entity, old, new)
self.notify(message, name = self.args['notify'])
@@ -0,0 +1,9 @@
security_sensors:
module: security_sensors
class: SecuritySensorsReport
sensor: group.security_sensors
constraint: input_boolean.security_sensors_report
ha_panel: alarm_control_panel.ha_alarm
notify: telegram
global_dependencies:
- globals