From de31b6ca5af5b506f81fa013296573449e1df27f Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Tue, 13 Aug 2024 01:07:00 -0500 Subject: [PATCH] added patio light --- apps/apps.yaml | 15 ++++++++++++--- apps/patio.py | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 apps/patio.py diff --git a/apps/apps.yaml b/apps/apps.yaml index eee1644..25cefb7 100644 --- a/apps/apps.yaml +++ b/apps/apps.yaml @@ -14,13 +14,13 @@ scene_detect: module: scene_detect class: MotionCanceller scene: bedsport - app: bedroom_motion + room: bedroom scene_detect2: module: scene_detect class: MotionCanceller scene: in_bed - app: bedroom_motion + room: bedroom leaving: module: leaving @@ -31,4 +31,13 @@ leaving: - bedroom - kitchen - bathroom - - closet \ No newline at end of file + - closet + +patio: + module: patio + class: Patio + door: binary_sensor.back_contact + light: light.patio + state: + brightness: 150 + color_temp: 400 diff --git a/apps/patio.py b/apps/patio.py new file mode 100644 index 0000000..c728114 --- /dev/null +++ b/apps/patio.py @@ -0,0 +1,27 @@ +from appdaemon.entity import Entity +from appdaemon.plugins.hass.hassapi import Hass + + +class Patio(Hass): + def initialize(self): + self.door.listen_state(callback=self.handle_door_open, new='on') + self.door.listen_state(callback=self.handle_door_close, new='off') + self.log(f'Patio light initialized for {self.door.friendly_name}') + self.log(f'Sun angle: {self.AD.sched.location.solar_elevation():.1f}') + + @property + def door(self) -> Entity: + return self.get_entity(self.args['door']) + + @property + def light(self) -> Entity: + return self.get_entity(self.args['light']) + + def handle_door_open(self, entity: str, attribute: str, old: str, new: str, kwargs: dict): + self.log('Door open') + if self.AD.sched.location.solar_elevation() <= 0: + self.light.turn_on(**self.args['state']) + + def handle_door_close(self, entity: str, attribute: str, old: str, new: str, kwargs: dict): + self.log('Door close') + self.run_in(callback=lambda *args: self.light.turn_off(), delay=30.0)