added leaving app

This commit is contained in:
John Lancaster
2023-11-24 21:02:25 -06:00
parent 1f30147a71
commit d5e1cb174d
2 changed files with 30 additions and 1 deletions

View File

@@ -19,4 +19,15 @@ scene_detect:
module: scene_detect
class: MotionCanceller
scene: in_bed
app: bedroom
app: bedroom
leaving:
module: leaving
class: Leaving
person: person.john
apps:
- living_room
- bedroom
- kitchen
- bathroom
- closet

18
apps/leaving.py Normal file
View File

@@ -0,0 +1,18 @@
from appdaemon.adapi import ADAPI
class Leaving(ADAPI):
def initialize(self):
self.listen_state(self.handle_state_change, entity_id=self.args['person'])
def handle_state_change(self, entity, attribute, old, new, kwargs):
self.log(f'Changed state {old} -> {new}')
if old == 'home' and new != 'home':
self.turn_everything_off()
def turn_everything_off(self):
for app_name in self.args['apps']:
try:
self.get_app(app_name).deactivate(cause='leaving')
except Exception as e:
self.log(f'{type(e).__name__}: {e}')
continue