added patio light
This commit is contained in:
27
apps/patio.py
Normal file
27
apps/patio.py
Normal 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)
|
||||
Reference in New Issue
Block a user