added patio light

This commit is contained in:
John Lancaster
2024-08-13 01:07:00 -05:00
parent 3bd955299c
commit de31b6ca5a
2 changed files with 39 additions and 3 deletions

View File

@@ -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
@@ -32,3 +32,12 @@ leaving:
- kitchen
- bathroom
- closet
patio:
module: patio
class: Patio
door: binary_sensor.back_contact
light: light.patio
state:
brightness: 150
color_temp: 400

27
apps/patio.py Normal file
View File

@@ -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)