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)
|
||||
|
||||
@@ -17,7 +17,6 @@ from automation import Automation, Base # type: ignore
|
||||
# Initial Version
|
||||
|
||||
class Balance(Base):
|
||||
|
||||
def initialize(self):
|
||||
super().initialize()
|
||||
self.check_balance({"force": 1})
|
||||
|
||||
@@ -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,6 +28,8 @@ 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']):
|
||||
@@ -35,3 +37,4 @@ class IntercomSwitch(hass.Hass):
|
||||
entity_id = self.args['entity_id']
|
||||
self.log("All persons leave home, turn off {}".format(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"]:
|
||||
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:
|
||||
|
||||
+11
-1
@@ -44,7 +44,7 @@ services:
|
||||
max-size: 50m
|
||||
|
||||
hass:
|
||||
image: homeassistant/home-assistant:0.100.2
|
||||
image: homeassistant/home-assistant:0.100.3
|
||||
container_name: hass
|
||||
volumes:
|
||||
- ./hass/settings:/config
|
||||
@@ -61,6 +61,11 @@ services:
|
||||
- broadlink
|
||||
network_mode: "host"
|
||||
restart: always
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:8123"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 6
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
@@ -181,3 +186,8 @@ services:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 50m
|
||||
|
||||
networks:
|
||||
traefik:
|
||||
external:
|
||||
name: my-pre-existing-network
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
- platform: ping
|
||||
name: uptime_synology
|
||||
host: !secret syno_ip
|
||||
count: 2
|
||||
scan_interval: 30
|
||||
@@ -0,0 +1,2 @@
|
||||
- platform: mpd
|
||||
host: 192.168.1.125
|
||||
@@ -0,0 +1,8 @@
|
||||
- platform: synologydsm
|
||||
host: !secret syno_ip
|
||||
port: 5000
|
||||
ssl: false
|
||||
username: !secret syno_user
|
||||
password: !secret syno_pass
|
||||
monitored_conditions:
|
||||
- cpu_total_load
|
||||
@@ -11,4 +11,4 @@
|
||||
power_cost:
|
||||
friendly_name: "Стоимость квт/ч"
|
||||
unit_of_measurement: 'Р'
|
||||
value_template: "4.37"
|
||||
value_template: "4.65"
|
||||
@@ -47,15 +47,15 @@
|
||||
power_money_t1_monthly:
|
||||
friendly_name: "Т1 в мес."
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_theory_t1') | float * 1.37) | round(2) }}"
|
||||
value_template: "{{ (states('sensor.power_theory_t1') | float * 1.5) | round(2) }}"
|
||||
power_money_t2_monthly:
|
||||
friendly_name: "Т2 в мес."
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_theory_t2') | float * 4.37) | round(2) }}"
|
||||
value_template: "{{ (states('sensor.power_theory_t2') | float * 4.65) | round(2) }}"
|
||||
power_money_t3_monthly:
|
||||
friendly_name: "Т3 в мес."
|
||||
unit_of_measurement: '₽'
|
||||
value_template: "{{ (states('sensor.power_theory_t3') | float * 5.25) | round(2) }}"
|
||||
value_template: "{{ (states('sensor.power_theory_t3') | float * 5.58) | round(2) }}"
|
||||
power_theory_money_monthly:
|
||||
friendly_name: "Итого в мес."
|
||||
unit_of_measurement: '₽'
|
||||
|
||||
@@ -95,6 +95,7 @@ work_coords: xxxxxxxxx
|
||||
# SYNOLOGY SETTINGS #
|
||||
###################################
|
||||
syno_url: xxxxxxxxx
|
||||
syno_ip: xxxxxxxxx
|
||||
syno_user: xxxxxxxxx
|
||||
syno_pass: xxxxxxxxx
|
||||
rtsp_entrance: xxxxxxxxx
|
||||
|
||||
@@ -168,6 +168,11 @@ views:
|
||||
camera_image: camera.entrance
|
||||
show_info: true
|
||||
tap_action: dialog
|
||||
- type: entities
|
||||
title: "Электропитание"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- media_player.mpd
|
||||
- title: "Будильники"
|
||||
icon: mdi:alarm
|
||||
cards:
|
||||
@@ -302,6 +307,7 @@ views:
|
||||
title: "Теория трехтарифника"
|
||||
show_header_toggle: false
|
||||
entities:
|
||||
- utility_meter.power_theory
|
||||
- sensor.power_theory_t1
|
||||
- sensor.power_theory_t2
|
||||
- sensor.power_theory_t3
|
||||
|
||||
@@ -10,6 +10,13 @@ serial: xxxxxxxxx
|
||||
disable_led: xxxxxxxxx
|
||||
advanced: xxxxxxxxx
|
||||
cache_state: xxxxxxxxx
|
||||
# Optional: xxxxxxxxx
|
||||
# unstable when executing many commands
|
||||
queue: xxxxxxxxx
|
||||
# Optional: xxxxxxxxx
|
||||
delay: xxxxxxxxx
|
||||
# Optional: xxxxxxxxx
|
||||
simultaneously: xxxxxxxxx
|
||||
devices: xxxxxxxxx
|
||||
'0x00158d0001e065e8': xxxxxxxxx
|
||||
friendly_name: xxxxxxxxx
|
||||
@@ -23,3 +30,7 @@ devices: xxxxxxxxx
|
||||
'0x00158d00026ea017': xxxxxxxxx
|
||||
friendly_name: xxxxxxxxx
|
||||
retain: xxxxxxxxx
|
||||
'0x000d6ffffe2c61ce': xxxxxxxxx
|
||||
friendly_name: xxxxxxxxx
|
||||
debounce: xxxxxxxxx
|
||||
retrieve_state: xxxxxxxxx
|
||||
|
||||
Reference in New Issue
Block a user