sleep setter update

This commit is contained in:
John Lancaster
2023-11-24 16:06:50 -06:00
parent 0deb3eb8f6
commit d57032bfb5
2 changed files with 17 additions and 8 deletions

View File

@@ -18,7 +18,7 @@ class SleepSetter(hass.Hass):
def handle_state(self, entity, attribute, old, new, kwargs): def handle_state(self, entity, attribute, old, new, kwargs):
self.log(f'{entity}: {old} -> {new}') self.log(f'{entity}: {old} -> {new}')
if self.state and self.sun_elevation < -10: if self.state and self.sun_elevation < float(self.args['elevation_limit']):
self.all_off() self.all_off()
self.turn_on(self.scene) self.turn_on(self.scene)
@@ -68,7 +68,15 @@ class SleepSetter(hass.Hass):
self.log(f'Ignoring event because sun elevation {elev} > 0') self.log(f'Ignoring event because sun elevation {elev} > 0')
def all_off(self): def all_off(self):
self.log(f'Turning off') self.log(f'Deactivating apps')
for app_name in self.args['off_apps']:
try:
self.get_app(app_name).deactivate()
except:
self.log(f'Failed to deactivate {app_name}')
continue
self.log(f'Turning off entities')
for entity in self.args['off_entities']: for entity in self.args['off_entities']:
try: try:
self.turn_off(entity) self.turn_off(entity)

View File

@@ -1,17 +1,18 @@
sleep: sleep:
module: sleep module: sleep
class: SleepSetter class: SleepSetter
elevation_limit: -10
scene: in_bed scene: in_bed
variable: input_boolean.sleeping variable: input_boolean.sleeping
button: button:
- Bedroom Button 1
- Bedroom Button 2
- Living Room Button
off_apps:
- bedroom - bedroom
- bedroom2
- living_room - living_room
- kitchen
- bathroom
off_entities: off_entities:
- light.living_room
- light.bathroom
- light.patio - light.patio
- light.closet - light.closet
- light.kitchen
- light.couch_corner
- light.globe