updating configuration
This commit is contained in:
@@ -72,3 +72,18 @@ def turn_off(self, entity_id, state):
|
||||
def notification(self, to, message):
|
||||
self.notify(message, name = "telegram")
|
||||
|
||||
|
||||
def get_arg(args, key):
|
||||
key = args[key]
|
||||
return key
|
||||
|
||||
|
||||
def get_arg_list(args, key):
|
||||
arg_list = []
|
||||
if isinstance(args[key], list):
|
||||
arg = args[key]
|
||||
else:
|
||||
arg = (args[key]).split(",")
|
||||
for key in arg:
|
||||
arg_list.append(key)
|
||||
return arg_list
|
||||
@@ -55,7 +55,7 @@ class Groups(hass.Hass):
|
||||
entitylist.sort(key=self.sortByFriendlyName)
|
||||
|
||||
self.log("Creating group {} with entities: {}".format(name, entitylist))
|
||||
self.set_state(name,state="on",attributes={"view": view,"hidden": hidden,"assumed_state": assumed_state,"friendly_name": friendly_name,"entity_id": entitylist})
|
||||
self.set_state(name,state="on",attributes={"view": view,"hidden": hidden,"assumed_state": assumed_state,"friendly_name": friendly_name,"entity_id": entitylist, 'description': 'Created and updated from appdaemon ({})'.format(__name__)})
|
||||
|
||||
def sortByFriendlyName(self, entity):
|
||||
return self.get_state(entity, 'friendly_name')
|
||||
|
||||
@@ -53,7 +53,9 @@ class LightButton(hass.Hass):
|
||||
self.set_on(entity_id)
|
||||
|
||||
def set_on(self, entity_id):
|
||||
if entity_id.startswith("light"):
|
||||
if entity_id.startswith("light") and 'color' in entity_id:
|
||||
self.call_service("light/turn_on", entity_id = entity_id, transition = 1, brightness = 255, color_temp=204)
|
||||
elif entity_id.startswith("light"):
|
||||
self.call_service("light/turn_on", entity_id = entity_id, transition = 1, brightness = 255)
|
||||
else:
|
||||
self.turn_on(entity_id)
|
||||
|
||||
@@ -1,56 +1,55 @@
|
||||
import datetime
|
||||
from automation import Automation, Base # type: ignore
|
||||
|
||||
#
|
||||
# App to send email report for low balance
|
||||
#
|
||||
# Args:
|
||||
#
|
||||
# threshold = value below which battery levels are reported and email is sent
|
||||
# always_send = set to 1 to override threshold and force send
|
||||
#
|
||||
# None
|
||||
#
|
||||
# Release Notes
|
||||
#
|
||||
# Version 1.0:
|
||||
# Initial Version
|
||||
|
||||
class Balance(Base):
|
||||
|
||||
def initialize(self):
|
||||
super().initialize()
|
||||
self.check_balance({"force": 1})
|
||||
self.run_daily(self.check_balance, datetime.time(10, 0, 0))
|
||||
|
||||
def check_balance(self, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
|
||||
values = {}
|
||||
low = []
|
||||
for key in self.entity_ids:
|
||||
device = self.entity_ids[key]
|
||||
balance = self.get_state(device)
|
||||
if balance != None and self.is_number(balance):
|
||||
if float(balance) < self.args["threshold"]:
|
||||
low.append(device)
|
||||
values[device] = balance
|
||||
|
||||
message=""
|
||||
if low:
|
||||
message += "Пожалуйста пополните баланс: (< {}) \n".format(self.args["threshold"])
|
||||
for device in low:
|
||||
message += " - {}: {}\n".format(self.friendly_name(device), values[device])
|
||||
message += "\n\n"
|
||||
|
||||
if low or ("always_send" in self.args and self.args["always_send"] == 1) or ("force" in kwargs and kwargs["force"] == 1):
|
||||
if message != "":
|
||||
self.notify(message, name = "telegram") #name = "telegram_monster"
|
||||
|
||||
def is_number(self, s):
|
||||
try:
|
||||
float(s)
|
||||
return True
|
||||
except ValueError:
|
||||
import datetime
|
||||
from automation import Automation, Base # type: ignore
|
||||
|
||||
#
|
||||
# App to send email report for low balance
|
||||
#
|
||||
# Args:
|
||||
#
|
||||
# threshold = value below which battery levels are reported and email is sent
|
||||
# always_send = set to 1 to override threshold and force send
|
||||
#
|
||||
# None
|
||||
#
|
||||
# Release Notes
|
||||
#
|
||||
# Version 1.0:
|
||||
# Initial Version
|
||||
|
||||
class Balance(Base):
|
||||
def initialize(self):
|
||||
super().initialize()
|
||||
self.check_balance({"force": 1})
|
||||
self.run_daily(self.check_balance, datetime.time(10, 0, 0))
|
||||
|
||||
def check_balance(self, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
|
||||
values = {}
|
||||
low = []
|
||||
for key in self.entity_ids:
|
||||
device = self.entity_ids[key]
|
||||
balance = self.get_state(device)
|
||||
if balance != None and self.is_number(balance):
|
||||
if float(balance) < self.args["threshold"]:
|
||||
low.append(device)
|
||||
values[device] = balance
|
||||
|
||||
message=""
|
||||
if low:
|
||||
message += "Пожалуйста пополните баланс: (< {}) \n".format(self.args["threshold"])
|
||||
for device in low:
|
||||
message += " - {}: {}\n".format(self.friendly_name(device), values[device])
|
||||
message += "\n\n"
|
||||
|
||||
if low or ("always_send" in self.args and self.args["always_send"] == 1) or ("force" in kwargs and kwargs["force"] == 1):
|
||||
if message != "":
|
||||
self.notify(message, name = "telegram") #name = "telegram_monster"
|
||||
|
||||
def is_number(self, s):
|
||||
try:
|
||||
float(s)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
@@ -26,22 +26,22 @@ class WaterCountersAlarm(hass.Hass):
|
||||
self.send_threasold = self.args['send_threasold']
|
||||
|
||||
self.check_send_dates({"force": 1})
|
||||
time = datetime.time(10, 0, 0)
|
||||
self.run_daily(self.check_checkup_dates, time)
|
||||
self.run_daily(self.check_send_dates, time)
|
||||
# self.check_send_dates([])
|
||||
self.run_daily(self.check_checkup_dates, datetime.time(10, 0, 0))
|
||||
self.run_daily(self.check_send_dates, datetime.time(10, 1, 0))
|
||||
#self.check_checkup_dates([])
|
||||
|
||||
def check_send_dates(self, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
devices = self.get_state()
|
||||
if devices == None:
|
||||
return
|
||||
values = {}
|
||||
send_devices = []
|
||||
for deviceName in devices:
|
||||
device = devices[deviceName]
|
||||
if (device == None):
|
||||
continue
|
||||
|
||||
send_date = None
|
||||
if "attributes" in device:
|
||||
if "date" in device["attributes"]:
|
||||
@@ -75,20 +75,27 @@ class WaterCountersAlarm(hass.Hass):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
|
||||
devices = self.get_state()
|
||||
entities = self.get_state()
|
||||
if entities == None:
|
||||
return
|
||||
|
||||
values = {}
|
||||
checkup_devices = []
|
||||
for device in devices:
|
||||
for entity_id in entities:
|
||||
entity = entities[entity_id]
|
||||
if entity == None:
|
||||
# self.log('not found {} in entities list.'.format(entity_id))
|
||||
continue
|
||||
checkup = None
|
||||
if "attributes" in devices[device]:
|
||||
if "checkup" in devices[device]["attributes"]:
|
||||
checkup = devices[device]["attributes"]["checkup"]
|
||||
if "attributes" in entity:
|
||||
if "checkup" in entity["attributes"]:
|
||||
checkup = entity["attributes"]["checkup"]
|
||||
if checkup != None:
|
||||
self.log('found device {} with checkup date {}'.format(device, checkup))
|
||||
self.log('found device {} with checkup date {}'.format(entity_id, checkup))
|
||||
checkup_date = datetime.datetime.strptime(checkup, '%Y-%m-%d')
|
||||
if (checkup_date - datetime.timedelta(days=self.checkup_threasold)) < datetime.datetime.now():
|
||||
checkup_devices.append(device)
|
||||
values[device] = checkup
|
||||
checkup_devices.append(entity_id)
|
||||
values[entity_id] = checkup
|
||||
|
||||
message=""
|
||||
if checkup_devices:
|
||||
|
||||
@@ -34,6 +34,10 @@ class Purifier(hass.Hass):
|
||||
self.listen_event_handle_list.append(self.listen_state(self.state_change, self.args['entity'], attribute='illuminance'))
|
||||
|
||||
def state_change(self, entity, attribute, old, new, kwargs):
|
||||
presence_state = self.get_state(self.args['ha_panel'])
|
||||
if presence_state != "disarmed":
|
||||
# self.log('Nobody home, ignoring illuminance changes.')
|
||||
return
|
||||
self.log("{} changed from {} to {}".format(attribute, old, new))
|
||||
if old > 0 and new == 0 and self.time_is_between(self.datetime(), self.args["on_time"], self.args["off_time"]):
|
||||
self.night_mode()
|
||||
@@ -61,7 +65,7 @@ class Purifier(hass.Hass):
|
||||
self.call_service("fan/set_speed", entity_id = self.args['entity'], speed='favorite')
|
||||
self.call_service("fan/xiaomi_miio_set_favorite_level", entity_id = self.args['entity'], level=self.away_fan_speed)
|
||||
self.call_service("fan/xiaomi_miio_set_led_on", entity_id = self.args['entity'])
|
||||
self.call_service("fan/xiaomi_miio_set_buzzer_on", entity_id = self.args['entity'])
|
||||
# self.call_service("fan/xiaomi_miio_set_buzzer_on", entity_id = self.args['entity'])
|
||||
|
||||
def auto_mode(self):
|
||||
self.mode='auto'
|
||||
@@ -69,7 +73,7 @@ class Purifier(hass.Hass):
|
||||
if 'entity' in self.args:
|
||||
self.call_service("fan/set_speed", entity_id = self.args['entity'], speed='auto')
|
||||
self.call_service("fan/xiaomi_miio_set_led_on", entity_id = self.args['entity'])
|
||||
self.call_service("fan/xiaomi_miio_set_buzzer_on", entity_id = self.args['entity'])
|
||||
# self.call_service("fan/xiaomi_miio_set_buzzer_on", entity_id = self.args['entity'])
|
||||
|
||||
def night_mode(self):
|
||||
self.mode='night'
|
||||
|
||||
@@ -4,5 +4,6 @@ purifier_timer:
|
||||
on_time: "06:45:00"
|
||||
off_time: "23:00:00"
|
||||
entity: fan.xiaomi_miio_device
|
||||
ha_panel: alarm_control_panel.ha_alarm
|
||||
global_dependencies:
|
||||
- globals
|
||||
@@ -28,10 +28,13 @@ class IntercomSwitch(hass.Hass):
|
||||
entity_id = self.args['entity_id']
|
||||
self.log("Somebody come home, turn on {}".format(entity_id))
|
||||
self.turn_on(entity_id)
|
||||
self.notify("Кто-то вернулся домой, включаю домофон.", name = self.args['notify'])
|
||||
|
||||
|
||||
def leave_event(self, event_id, event_args, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
entity_id = self.args['entity_id']
|
||||
self.log("All persons leave home, turn off {}".format(entity_id))
|
||||
self.turn_off(entity_id)
|
||||
self.turn_off(entity_id)
|
||||
self.notify("Все ушли из дома, выключаю домофон", name = self.args['notify'])
|
||||
@@ -4,6 +4,7 @@
|
||||
intercom_auto_open:
|
||||
module: intercom_switch
|
||||
class: IntercomSwitch
|
||||
notify: telegram_monster
|
||||
entity_id: switch.domofon_mode
|
||||
arrive_event: homekit_home_arrive
|
||||
leave_event: homekit_home_leave
|
||||
|
||||
@@ -35,8 +35,6 @@ class WorkTime(hass.Hass):
|
||||
self.run_timer()
|
||||
|
||||
def arrive_event(self, event_id, event_args, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
if self.arrive_time != None:
|
||||
self.log('You have already arrived to the work today at {}'.format(self.arrive_time))
|
||||
self.run_timer()
|
||||
@@ -49,6 +47,9 @@ class WorkTime(hass.Hass):
|
||||
self.run_timer()
|
||||
self.log("Monster has arrived to work at {}, work till {}, will notify at {}.".format(self.arrive_time, self.leave_time, self.notify_time))
|
||||
self.timers.append(self.run_every(self.timer_tick, self.notify_time, self.notify_every_seconds))
|
||||
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
self.notify("Добро пожаловать в офис. Сегодня работаешь до {}.".format(self.format_time(self.leave_time)), name = self.args['notify'])
|
||||
|
||||
def run_timer(self):
|
||||
@@ -60,8 +61,6 @@ class WorkTime(hass.Hass):
|
||||
self.timers.append(self.run_every(self.timer_tick, timer_start, self.notify_every_seconds))
|
||||
|
||||
def leave_event(self, event_id, event_args, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
if self.arrive_time == None:
|
||||
return
|
||||
self.cancel_timers()
|
||||
@@ -78,14 +77,17 @@ class WorkTime(hass.Hass):
|
||||
else:
|
||||
self.log("Monster leave work at {} - {}".format(self.arrive_time, self.datetime))
|
||||
message = "Рабочий день окончен ({}-{}). Приятной дороги домой.{}".format(self.format_time(self.arrive_time), self.format_time(self.datetime()), travelTime)
|
||||
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
self.notify(message, name = self.args['notify'])
|
||||
# self.reset_timer_tick(None)
|
||||
|
||||
def timer_tick(self, args) -> None:
|
||||
self.log('timer tick')
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
if self.notify_time == None or self.datetime()<self.notify_time:
|
||||
return
|
||||
if self.datetime()<self.notify_time:
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
return
|
||||
message = "Ты пришел на работу в {}, работаешь до {}. Пора домой!".format(self.format_time(self.arrive_time), self.format_time(self.leave_time))
|
||||
self.notify(message, name = self.args['notify'])
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
#
|
||||
# Helper for presence detection
|
||||
#
|
||||
# Args:
|
||||
# ha_panel - alarm control panel entity (to arm and disarm).
|
||||
#
|
||||
# Release Notes
|
||||
#
|
||||
# Version 1.0:
|
||||
# Initial Version
|
||||
|
||||
class Presence(hass.Hass):
|
||||
def initialize(self):
|
||||
self.log('started')
|
||||
|
||||
def function():
|
||||
pass
|
||||
@@ -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