updating configuration
This commit is contained in:
@@ -20,17 +20,31 @@ import appdaemon.plugins.hass.hassapi as hass
|
||||
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.listen_state(self.water_leak, self.args['sensor'])
|
||||
|
||||
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()
|
||||
|
||||
def send_alarm(self):
|
||||
self.log('water leak alarm triggered!')
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
|
||||
@@ -44,10 +58,6 @@ class WaterLeak(hass.Hass):
|
||||
self.notify(message, name = self.args['notify'])
|
||||
|
||||
message = "Состояние датчиков протечки:\n"
|
||||
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"]:
|
||||
message += '{} ({}) = {}\n'.format(self.friendly_name(entity_id), entity_id, self.get_state(entity_id))
|
||||
self.notify(message, name = self.args['notify'])
|
||||
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'])
|
||||
|
||||
@@ -5,8 +5,9 @@ water_leak:
|
||||
module: water_leak
|
||||
class: WaterLeak
|
||||
constraint: input_boolean.water_leak_control
|
||||
sensor: group.water_leak
|
||||
sensor: group.water_leak_sensors
|
||||
valve: switch.water_valve
|
||||
sensor_prefix: binary_sensor.water_leak_sensor_
|
||||
notify: telegram
|
||||
gw_mac: !secret aqara1_mac
|
||||
global_dependencies:
|
||||
|
||||
Reference in New Issue
Block a user