Files
ad-nix/apps/patio.py
John Lancaster 6970bab14e fixed patio
2024-08-30 08:35:07 -05:00

28 lines
1.0 KiB
Python

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):
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):
self.log('Door close')
self.run_in(callback=lambda *args, **kwargs: self.light.turn_off(), delay=30.0)