updating configuration
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
import fnmatch
|
||||
|
||||
#
|
||||
# Fire 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 FireSensorsReport(hass.Hass):
|
||||
def initialize(self):
|
||||
if 'sensor_parts' not in self.args or 'notify' not in self.args:
|
||||
self.error("Please provide sensor_parts, ha_panel and notify in config!")
|
||||
return
|
||||
|
||||
sensor_parts = self.args['sensor_parts']
|
||||
|
||||
all_sensors = self.get_state()
|
||||
for entity_id in all_sensors:
|
||||
for part in sensor_parts:
|
||||
if fnmatch.fnmatch(entity_id, part):
|
||||
self.log(' [+] listening for security sensor {}'.format(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":
|
||||
self.log('Fire sensor is triggered!!!')
|
||||
self.alarm_triggered(entity, old, new)
|
||||
|
||||
def alarm_triggered(self, entity, old, new):
|
||||
self.log('alarm triggered')
|
||||
|
||||
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 @@
|
||||
fire_sensors:
|
||||
module: fire_sensors
|
||||
class: FireSensorsReport
|
||||
sensor_parts:
|
||||
- binary_sensor.smoke_detector_*_smoke
|
||||
constraint: input_boolean.fire_sensors_report
|
||||
notify: telegram
|
||||
global_dependencies:
|
||||
- globals
|
||||
@@ -0,0 +1,59 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
import fnmatch
|
||||
|
||||
#
|
||||
# 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_parts' not in self.args or 'ha_panel' not in self.args or 'notify' not in self.args:
|
||||
self.error("Please provide sensor_parts, ha_panel and notify in config!")
|
||||
return
|
||||
|
||||
sensor_parts = self.args['sensor_parts']
|
||||
|
||||
all_sensors = self.get_state()
|
||||
for entity_id in all_sensors:
|
||||
for part in sensor_parts:
|
||||
if fnmatch.fnmatch(entity_id, part):
|
||||
self.log(' [+] listening for security sensor {}'.format(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
|
||||
|
||||
vacuum_state = "docked"
|
||||
if "vacuum" in self.args:
|
||||
vacuum_state = self.get_state(self.args["vacuum"])
|
||||
#Если работает пылесос и сработал датчик движения
|
||||
if vacuum_state == 'cleaning' and 'binary_sensor.motion' in entity:
|
||||
self.log('Motion sensor is triggered, but vacuum is cleaning.')
|
||||
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,14 @@
|
||||
security_sensors:
|
||||
module: security_sensors
|
||||
class: SecuritySensorsReport
|
||||
sensor_parts:
|
||||
- binary_sensor.motion_*_occupancy
|
||||
- binary_sensor.door_*_contact
|
||||
- binary_sensor.smoke_detector_*_smoke
|
||||
- binary_sensor.water_leak_*_leak
|
||||
constraint: input_boolean.security_sensors_report
|
||||
ha_panel: alarm_control_panel.ha_alarm
|
||||
vacuum: vacuum.dreame_p2027_6b1e_robot_cleaner
|
||||
notify: telegram
|
||||
global_dependencies:
|
||||
- globals
|
||||
@@ -0,0 +1,62 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
#
|
||||
# Water leak detector
|
||||
# close water valve and send a report
|
||||
#
|
||||
# Args:
|
||||
#
|
||||
# sensor = water leak sensor group
|
||||
# valve = water valve - app will close it, when leak is detected
|
||||
# notify = notify name to send notification
|
||||
#
|
||||
# None
|
||||
#
|
||||
# Release Notes
|
||||
#
|
||||
# Version 1.0:
|
||||
# Initial Version
|
||||
|
||||
class WaterLeak(hass.Hass):
|
||||
ringtone = 2
|
||||
gw_mac = ''
|
||||
sensors = []
|
||||
def initialize(self):
|
||||
if 'sensor' not in self.args or 'valve' not in self.args or 'notify' not in self.args:
|
||||
self.error("Please provide sensor, valve and notify in config!")
|
||||
return
|
||||
self.sensors = self.get_water_leak_sensors()
|
||||
self.log("leak sensors: {}".format(self.sensors))
|
||||
for sensor in self.sensors:
|
||||
self.listen_state(self.water_leak, sensor)
|
||||
|
||||
def get_water_leak_sensors(self):
|
||||
sensors = []
|
||||
devices = self.get_state()
|
||||
for sensor in devices:
|
||||
if not sensor.startswith(self.args['sensor_prefix']):
|
||||
continue
|
||||
sensors.append(sensor)
|
||||
return sensors
|
||||
|
||||
def water_leak(self, entity, attribute, old, new, kwargs):
|
||||
if new == "on":
|
||||
self.send_alarm(entity)
|
||||
|
||||
def send_alarm(self, entity_id):
|
||||
self.log('water leak alarm triggered!')
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
|
||||
#close water valve
|
||||
self.turn_off(self.args['valve'])
|
||||
## to ensure that water is closed. It is important!!!
|
||||
self.call_service("mqtt/publish", topic = 'home/watercontrol/bath/valve/set', payload = 'close')
|
||||
|
||||
message = "ВНИМАНИЕ! В ваше отстутствие сработал датчик протечки воды ({})!!! Выключаю подачу воды.".format(self.friendly_name(entity_id))
|
||||
self.notify(message, name = self.args['notify'])
|
||||
|
||||
message = "Состояние датчиков протечки:\n"
|
||||
for entity_id in self.sensors:
|
||||
message += '{} ({}) = {}\n'.format(self.friendly_name(entity_id), entity_id, self.get_state(entity_id))
|
||||
self.notify(message, name = self.args['notify'])
|
||||
@@ -0,0 +1,14 @@
|
||||
#################################
|
||||
# WATER LEAK #
|
||||
#################################
|
||||
water_leak:
|
||||
module: water_leak
|
||||
class: WaterLeak
|
||||
constraint: input_boolean.water_leak_control
|
||||
sensor: group.water_leak_sensors
|
||||
valve: switch.water_valve
|
||||
sensor_prefix: binary_sensor.water_leak_
|
||||
notify: telegram
|
||||
gw_mac: !secret aqara1_mac
|
||||
global_dependencies:
|
||||
- globals
|
||||
Reference in New Issue
Block a user