This commit is contained in:
monster
2018-12-30 14:13:57 +03:00
parent e311c31b88
commit 2033fe79e4
225 changed files with 6370 additions and 0 deletions
@@ -0,0 +1,55 @@
import appdaemon.plugins.hass.hassapi as hass
import globals
#
# 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.
# Args:
#
# sensor = sensor, which will stop alarm (bath motion sensor for me)
# ringtone = (default = 20) xiaomi ringtone id.
#
# None
#
# Release Notes
#
# Version 1.0:
# Initial Version
class AlarmclockAction(hass.Hass):
timer = None
ringtone = 20
volume = 10
gw_mac = ''
def initialize(self):
if not globals.check_args(self, ["sensor","gw_mac"]):
return
self.gw_mac = self.args['gw_mac']
if 'ringtone' in self.args:
self.ringtone = self.args['ringtone']
self.listen_event(self.alarmclock_alarm, "alarmclock_alarm")
self.listen_event(self.alarmclock_stop, "alarmclock_stop")
self.listen_state(self.sensor_trigger, self.args['sensor'])
def alarmclock_stop(self, event_id, event_args, kwargs):
self.sensor_trigger(None, None, None, 'on', None)
def sensor_trigger(self, entity, attribute, old, new, kwargs):
if new == "on" and self.timer != None:
self.call_service("xiaomi_aqara/stop_ringtone", gw_mac=self.gw_mac)
self.cancel_current_timer()
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)
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)
if self.volume < 100:
self.volume = self.volume + 10
def cancel_current_timer(self):
if self.timer != None:
self.log('canceling timer')
self.cancel_timer(self.timer)
self.timer = None