water action fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
ARG VERSION
|
||||
FROM acockburn/appdaemon:${VERSION}
|
||||
ARG BASE_IMAGE
|
||||
#FROM acockburn/appdaemon:${BASE_IMAGE}
|
||||
FROM ${BASE_IMAGE}
|
||||
|
||||
RUN pip3 install \
|
||||
attrs==19.1.0 \
|
||||
@@ -7,4 +8,6 @@ RUN pip3 install \
|
||||
packaging==16.8 \
|
||||
python-Levenshtein==0.12.0 \
|
||||
voluptuous==0.11.5 \
|
||||
noolite==1.4.0 && apt-get update -y && apt-get install -y libusb-1.0-0-dev && apt-get clean
|
||||
noolite==1.4.0 && \
|
||||
apk add --no-cache libusb-dev
|
||||
#apt-get update && apt-get install -y libusb-1.0.0-dev && apt-get clean
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
log:
|
||||
logfile: STDOUT
|
||||
errorfile: STDERR
|
||||
logs:
|
||||
main_log:
|
||||
filename: STDOUT
|
||||
|
||||
appdaemon:
|
||||
threads: 10
|
||||
latitude: !secret home_latitude
|
||||
longitude: !secret home_longitude
|
||||
elevation: 0
|
||||
timezone: !secret timezone
|
||||
api_port: 5000
|
||||
api_key: !secret ha_password
|
||||
time_zone: !secret timezone
|
||||
narodmon_key: !secret narodmon_key
|
||||
|
||||
|
||||
api:
|
||||
|
||||
plugins:
|
||||
HASS:
|
||||
type: hass
|
||||
ha_url: !secret ha_url
|
||||
#ha_key: !secret ha_password
|
||||
token: !secret ha_token
|
||||
token: !secret ha_token
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
import globals
|
||||
import datetime
|
||||
#
|
||||
# Very special case, this will run sound 'alarm' on xiaomi gateway based on alarm clock event (alarmclock_trigger)
|
||||
# and stop it when sensor became active.
|
||||
@@ -41,7 +42,7 @@ class AlarmclockAction(hass.Hass):
|
||||
def alarmclock_alarm(self, event_id, event_args, kwargs):
|
||||
self.log('Alarm triggered!')
|
||||
self.volume = 10
|
||||
self.timer = self.run_every(self.timer_tick, self.datetime(), 17)
|
||||
self.timer = self.run_every(self.timer_tick, self.datetime()+datetime.timedelta(seconds=15), 17)
|
||||
|
||||
def timer_tick(self, kwargs):
|
||||
self.call_service("xiaomi_aqara/play_ringtone", gw_mac=self.gw_mac, ringtone_id=self.ringtone, ringtone_vol=self.volume)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
import datetime
|
||||
|
||||
#
|
||||
# Pre alarm event.
|
||||
@@ -51,7 +52,7 @@ class AlarmclockPrealarm(hass.Hass):
|
||||
self.log('Prealarm triggered!')
|
||||
self.brightness = 1
|
||||
self.color_temp = 588
|
||||
self.timer = self.run_every(self.timer_tick, self.datetime(), 10)
|
||||
self.timer = self.run_every(self.timer_tick, self.datetime()+datetime.timedelta(seconds=15), 10)
|
||||
|
||||
def timer_tick(self, kwargs):
|
||||
attributes = self.get_state(self.args['entity'], attribute = "all")
|
||||
|
||||
@@ -39,11 +39,11 @@ class Doorbell(hass.Hass):
|
||||
self.notify("Звонок в дверь!!!", name = self.args['notify'])
|
||||
result = self.send_video()
|
||||
|
||||
def send_video(self):
|
||||
def send_video(self):
|
||||
file = '/config/www/doorbell_video.mp4'
|
||||
if os.path.exists(file):
|
||||
os.remove(file)
|
||||
|
||||
|
||||
self.call_service("stream/record", stream_source=self.args['rtsp'], filename=file, duration=10)
|
||||
self.timer = self.run_in(self.run_in_send_video, 20, file=file)
|
||||
|
||||
|
||||
@@ -34,6 +34,17 @@ class LightControl(hass.Hass):
|
||||
# self.log('Sun is up, and we will turn it only after sundown.')
|
||||
return
|
||||
|
||||
vacuum_state = "docked"
|
||||
ha_panel_state = ""
|
||||
if "vacuum" in self.args:
|
||||
vacuum_state = self.get_state(self.args["vacuum"])
|
||||
if "ha_panel" in self.args:
|
||||
ha_panel_state = self.get_state(self.args["ha_panel"])
|
||||
#Если работает пылесос и сработал датчик движения
|
||||
if ha_panel_state == "armed_away" and vacuum_state == 'cleaning':
|
||||
self.log('Motion sensor is triggered, but vacuum is cleaning.')
|
||||
return
|
||||
|
||||
#sensor is off
|
||||
if new == 'off' and old == 'on':
|
||||
self.log('Sensor is off - running timer for {}s.'.format(self.args['timeout']))
|
||||
|
||||
@@ -8,6 +8,8 @@ light_control_mainroom:
|
||||
control_entity: group.mainroom_light
|
||||
timeout: 60
|
||||
constraint: input_boolean.mainroom_light_control
|
||||
ha_panel: alarm_control_panel.ha_alarm
|
||||
vacuum: vacuum.xiaomi_vacuum_cleaner
|
||||
global_dependencies:
|
||||
- globals
|
||||
|
||||
@@ -18,6 +20,8 @@ light_control_kitchen:
|
||||
control_entity: group.kitchen_light
|
||||
timeout: 300
|
||||
constraint: input_boolean.kitchen_light_control
|
||||
ha_panel: alarm_control_panel.ha_alarm
|
||||
vacuum: vacuum.xiaomi_vacuum_cleaner
|
||||
global_dependencies:
|
||||
- globals
|
||||
|
||||
@@ -28,6 +32,8 @@ light_control_hall:
|
||||
control_entity: group.hall_light
|
||||
timeout: 120
|
||||
constraint: input_boolean.hall_light_control
|
||||
ha_panel: alarm_control_panel.ha_alarm
|
||||
vacuum: vacuum.xiaomi_vacuum_cleaner
|
||||
global_dependencies:
|
||||
- globals
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class Watchdog(hass.Hass):
|
||||
def initialize(self):
|
||||
if not globals.check_args(self, ['entity','update_interval', 'timeout']):
|
||||
return
|
||||
self.timer = self.run_every(self.watchdog_check, self.datetime(), self.args['update_interval'])
|
||||
self.timer = self.run_every(self.watchdog_check, self.datetime()+timedelta(seconds=10), self.args['update_interval'])
|
||||
|
||||
def watchdog_check(self, kwargs):
|
||||
if 'constraint' in self.args and not self.constrain_input_boolean(self.args['constraint']):
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
import datetime
|
||||
|
||||
#
|
||||
# Water control application.
|
||||
@@ -16,6 +17,8 @@ import appdaemon.plugins.hass.hassapi as hass
|
||||
|
||||
class WaterValveControl(hass.Hass):
|
||||
standby_power_limit = 15
|
||||
current_wait_cycle = 0
|
||||
wait_cycles = 3
|
||||
timer = None
|
||||
listen_event_handle_list = []
|
||||
timers = []
|
||||
@@ -51,7 +54,7 @@ class WaterValveControl(hass.Hass):
|
||||
device_names += self.friendly_name(device)
|
||||
self.notify('В доме остались требующие воды устройства ({}), подача воды не будет отключена.'.format(device_names), name = self.args['notify'])
|
||||
self.cancel_current_timer()
|
||||
self.timers.append(self.run_every(self.wait_when_device_is_done, self.datetime(), 5*60))
|
||||
self.timers.append(self.run_every(self.wait_when_device_is_done, self.datetime()+datetime.timedelta(seconds=5), 5*60))
|
||||
else:
|
||||
self.turn_off(self.args['water_valve'])
|
||||
for device in self.args['water_devices']:
|
||||
@@ -62,13 +65,23 @@ class WaterValveControl(hass.Hass):
|
||||
return
|
||||
powered_on = self.get_turned_on_devices()
|
||||
self.log('still powered on: {}'.format(powered_on))
|
||||
if (len(powered_on) == 0):
|
||||
# self.turn_off(self.args['water_valve'])
|
||||
# for device in self.args['water_devices']:
|
||||
# self.turn_off(device)
|
||||
self.notify('Устройства требующие воды закончили свою работу.', name = self.args['notify'])
|
||||
if len(powered_on) == 1:
|
||||
self.current_wait_cycle = 0
|
||||
elif len(powered_on) == 0 and self.current_wait_cycle<self.wait_cycles:
|
||||
self.log("Current wait cycle: {}".format(self.current_wait_cycle))
|
||||
self.current_wait_cycle = self.current_wait_cycle+1
|
||||
elif len(powered_on) == 0 and self.current_wait_cycle>=self.wait_cycles:
|
||||
self.current_wait_cycle = 0
|
||||
self.notify('Устройства требующие воды закончили свою работу, отключаю подачу воды.', name = self.args['notify'])
|
||||
self.turn_off_water_devices()
|
||||
self.cancel_current_timer()
|
||||
|
||||
def turn_off_water_devices():
|
||||
self.log("Turning off water devices.")
|
||||
self.turn_off(self.args['water_valve'])
|
||||
for device in self.args['water_devices']:
|
||||
self.turn_off(device)
|
||||
|
||||
def get_turned_on_devices(self):
|
||||
powered_on_devices = []
|
||||
devices = self.args['water_devices']
|
||||
@@ -80,8 +93,8 @@ class WaterValveControl(hass.Hass):
|
||||
if 'load_power' not in attributes:
|
||||
continue
|
||||
load_power = attributes['load_power']
|
||||
self.log('{} load power is: {}'.format(device, load_power))
|
||||
if state == 'on' and load_power < self.standby_power_limit:
|
||||
self.log('{} state: {}, load power is: {}'.format(device, state, load_power))
|
||||
if state == 'off' or load_power < self.standby_power_limit:
|
||||
continue
|
||||
powered_on_devices.append(device)
|
||||
return powered_on_devices
|
||||
|
||||
@@ -24,7 +24,7 @@ class MosEnergoSbytSender(Automation):
|
||||
class MosEnergoSbytUpdater(Automation):
|
||||
def initialize(self):
|
||||
super().initialize()
|
||||
self.timer = self.run_every(self.update_sensors, self.datetime(), 1*60*60)
|
||||
self.timer = self.run_every(self.update_sensors, self.datetime()+timedelta(seconds=10), 1*60*60)
|
||||
# self.send_mosenergosbyt_counters({})
|
||||
|
||||
def update_sensors(self, args) -> None:
|
||||
|
||||
@@ -161,7 +161,7 @@ class PowerCounterSensor(Automation):
|
||||
class EpdBalanceSensor(Automation):
|
||||
def initialize(self):
|
||||
super().initialize()
|
||||
self.timer = self.run_every(self.update_sensors, self.datetime(), 1*60*60)
|
||||
self.timer = self.run_every(self.update_sensors, self.datetime()+timedelta(seconds=40), 1*60*60)
|
||||
|
||||
def update_sensors(self, args) -> None:
|
||||
if 'epd_balance' in self.entity_ids:
|
||||
|
||||
@@ -32,7 +32,7 @@ class ToiletPresence(hass.Hass):
|
||||
def distance_changed(self, entity, attribute, old, new, kwargs):
|
||||
distance = int(new)
|
||||
state = ""
|
||||
if (distance > 1000 or distance < 850):
|
||||
if (distance > 1100 or distance < 750):
|
||||
self.timers_off()
|
||||
self.timers.append(self.run_in(self.run_in_presense_off, self.presence_timeout))
|
||||
self.log('re-setting timer for {}s.'.format(self.presence_timeout))
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
from notification import send_notification
|
||||
import datetime
|
||||
import sys, locale
|
||||
import logging, codecs
|
||||
#import unicode
|
||||
# from automation import Automation # type: ignore
|
||||
|
||||
"""
|
||||
@@ -10,7 +14,8 @@ Arguments:
|
||||
"""
|
||||
class Test(hass.Hass):
|
||||
def initialize(self) -> None:
|
||||
self.log('test')
|
||||
self.log(u"Привет")
|
||||
self.log(str(u'ô'))
|
||||
# id = send_notification(
|
||||
# self, targets="telegram_monster", message="Repeated message", title="title", when=datetime.datetime.now(), interval=10, iterations=2
|
||||
# )
|
||||
@@ -23,4 +28,4 @@ class Test(hass.Hass):
|
||||
self.log('terminate')
|
||||
# for listen_event_handle in self.listen_event_handle_list:
|
||||
# self.cancel_listen_event(listen_event_handle)
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import appdaemon.plugins.hass.hassapi as hass
|
||||
from notification import send_notification
|
||||
import datetime
|
||||
import sys, locale
|
||||
import logging
|
||||
#import unicode
|
||||
# from automation import Automation # type: ignore
|
||||
|
||||
"""
|
||||
Monitor events and output changes to the verbose_log. Nice for debugging purposes.
|
||||
Arguments:
|
||||
- events: List of events to monitor
|
||||
"""
|
||||
class Test(hass.Hass):
|
||||
def initialize(self) -> None:
|
||||
root_logger= logging.getLogger()
|
||||
root_logger.setLevel(logging.DEBUG) # or whatever
|
||||
handler = logging.FileHandler('test.log', 'w', 'utf-8') # or whatever
|
||||
formatter = logging.Formatter('%(name)s %(message)s') # or whatever
|
||||
handler.setFormatter(formatter) # Pass handler as a parameter, not assign
|
||||
root_logger.addHandler(handler)
|
||||
UTF8Writer = codecs.getwriter('utf8')
|
||||
sys.stdout = UTF8Writer(sys.stdout.buffer)
|
||||
self.log(u"Привет")
|
||||
self.log(str(u'ô'))
|
||||
# id = send_notification(
|
||||
# self, targets="telegram_monster", message="Repeated message", title="title", when=datetime.datetime.now(), interval=10, iterations=2
|
||||
# )
|
||||
# self.log("id:{}".format(id))
|
||||
# id = send_notification(
|
||||
# self, targets="telegram_monster", message="Dummy", title="title"
|
||||
# )
|
||||
|
||||
def terminate(self):
|
||||
self.log('terminate')
|
||||
# for listen_event_handle in self.listen_event_handle_list:
|
||||
# self.cancel_listen_event(listen_event_handle)
|
||||
|
||||
Reference in New Issue
Block a user