From 89576840a5af2f511af42052bf249ae6fdb15193 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 09:55:38 -0600 Subject: [PATCH 01/26] started async stuff --- apps/room_control | 2 +- apps/scene_detect.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/room_control b/apps/room_control index c9cc841..4513437 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit c9cc841d58ca45dac8557576913249ed807fef2c +Subproject commit 4513437bf4e982b603c61b3e5c0136fb872d17c4 diff --git a/apps/scene_detect.py b/apps/scene_detect.py index a5e13b0..a247b52 100644 --- a/apps/scene_detect.py +++ b/apps/scene_detect.py @@ -1,5 +1,6 @@ from appdaemon.plugins.hass.hassapi import Hass + class SceneDetector(Hass): def initialize(self): self.scene_entity = self.args['scene'] if self.args['scene'].startswith('scene.') else f'scene.{self.args["scene"]}' @@ -8,17 +9,17 @@ class SceneDetector(Hass): self.listen_event(self.event_callback, event='call_service', domain='scene', service='turn_on') self.log(f'Waiting for {self.scene_entity.friendly_name} to activate') - def event_callback(self, event_name, data, cb_args): + async def event_callback(self, event_name, data, cb_args): entity_id = data['service_data']['entity_id'] if entity_id == self.scene_entity.entity_id: - self.scene_detected() + await self.scene_detected() - def scene_detected(self): + async def scene_detected(self): self.log(f'Detected scene activation: {self.scene_entity.friendly_name}') class MotionCanceller(SceneDetector): - def scene_detected(self): - super().scene_detected() - app = self.get_app(self.args['app']) + async def scene_detected(self): + await super().scene_detected() + app = await self.get_app(self.args['app']) app.cancel_motion_callback(new='off') \ No newline at end of file From daf97fcb06a7ba5d146fdfcffc50c405baf74e36 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:23:19 -0600 Subject: [PATCH 02/26] simplified a bit --- apps/sleep.py | 56 ++++++++++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/apps/sleep.py b/apps/sleep.py index 1f4089d..49d5651 100755 --- a/apps/sleep.py +++ b/apps/sleep.py @@ -8,9 +8,8 @@ from appdaemon.plugins.mqtt.mqttapi import Mqtt class SleepSetter(Hass, Mqtt): def initialize(self): assert self.entity_exists(entity_id=self.variable), f'{self.variable} does not exist' - self.variable_entity.listen_state(callback=self.handle_state) + self.listen_state(callback=self.handle_state, entity_id=self.variable) self.setup_buttons() - self.log(f'{self.variable} can be set using {self.button}, currently {self.state}') def setup_buttons(self): if isinstance(self.button, list): @@ -23,7 +22,7 @@ class SleepSetter(Hass, Mqtt): topic = f'zigbee2mqtt/{name}' self.mqtt_subscribe(topic, namespace='mqtt') self.listen_event(self.handle_button, "MQTT_MESSAGE", topic=topic, namespace='mqtt', button=name) - self.log(f'Listening for sleep setting on {name}') + self.log(f'Subscribed: {topic}') @property def button(self) -> str: @@ -56,15 +55,13 @@ class SleepSetter(Hass, Mqtt): @property def sun_elevation(self) -> float: - try: - return float(self.get_state('sun.sun', 'elevation')) - except: - self.log(f'Failed to return sun elevation') - return + state = self.get_state('sun.sun', 'elevation') + assert isinstance(state, float) + return state def handle_state(self, entity, attribute, old, new, kwargs): - self.log(f'{entity}: {old} -> {new}') - if self.state and self.sun_elevation < float(self.args['elevation_limit']): + self.log(f'new state: {self.state}') + if self.state: self.all_off() try: self.call_service('scene/turn_on', entity_id=self.scene) @@ -77,19 +74,15 @@ class SleepSetter(Hass, Mqtt): def handle_button(self, event_name, data, kwargs): topic = data['topic'] # self.log(f'Button event for: {topic}') - if (elev := self.sun_elevation) < 0: - try: - payload = json.loads(data['payload']) - action = payload['action'] - except json.JSONDecodeError: - self.log(f'Error decoding JSON from {data["payload"]}', level='ERROR') - except KeyError as e: - return - else: - self.handle_action(action) - + try: + payload = json.loads(data['payload']) + action = payload['action'] + except json.JSONDecodeError: + self.log(f'Error decoding JSON from {data["payload"]}', level='ERROR') + except KeyError as e: + return else: - self.log(f'Ignoring event because sun elevation {elev} > 0') + self.handle_action(action) def handle_action(self, action: str): if action == '': @@ -98,14 +91,7 @@ class SleepSetter(Hass, Mqtt): self.state = True elif action == 'double': self.state = not self.state - if (on_apps := self.args.get('on_apps', None)) is not None: - for app_name in on_apps: - try: - self.get_app(app_name).activate(cause='sleep setter') - except: - return - else: - self.log(f'Activated {app_name}') + self.on_apps() def all_off(self): self.log(f'Deactivating apps') @@ -123,3 +109,13 @@ class SleepSetter(Hass, Mqtt): except: self.log(f'Failed to turn off {entity}') continue + + def on_apps(self): + if (on_apps := self.args.get('on_apps', None)) is not None: + for app_name in on_apps: + try: + self.get_app(app_name).activate(cause='sleep setter') + except: + return + else: + self.log(f'Activated {app_name}') \ No newline at end of file From 021dc61c6b3d9ce7124ca27a02131a7b4b535c05 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:23:31 -0600 Subject: [PATCH 03/26] renames --- apps/room_control | 2 +- apps/rooms/bathroom.yaml | 2 +- apps/rooms/bedroom.yaml | 2 +- apps/rooms/kitchen.yaml | 2 +- apps/rooms/living_room.yaml | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/room_control b/apps/room_control index 4513437..8a5431a 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit 4513437bf4e982b603c61b3e5c0136fb872d17c4 +Subproject commit 8a5431a72bc8f0ef5ae2f1c98d97db55bd670523 diff --git a/apps/rooms/bathroom.yaml b/apps/rooms/bathroom.yaml index e4b71db..df8c701 100644 --- a/apps/rooms/bathroom.yaml +++ b/apps/rooms/bathroom.yaml @@ -33,7 +33,7 @@ bathroom: bathroom_button: module: button - class: ButtonController + class: Button app: bathroom ref_entity: light.bathroom button: Bathroom Button diff --git a/apps/rooms/bedroom.yaml b/apps/rooms/bedroom.yaml index efff443..19ea792 100644 --- a/apps/rooms/bedroom.yaml +++ b/apps/rooms/bedroom.yaml @@ -75,7 +75,7 @@ bedroom: bedroom_buttons: module: button - class: ButtonController + class: Button app: bedroom ref_entity: light.bedroom button: diff --git a/apps/rooms/kitchen.yaml b/apps/rooms/kitchen.yaml index ffd5479..91063d9 100755 --- a/apps/rooms/kitchen.yaml +++ b/apps/rooms/kitchen.yaml @@ -38,7 +38,7 @@ kitchen: kitchen_button: module: button - class: ButtonController + class: Button app: kitchen ref_entity: light.kitchen button: Kitchen Button diff --git a/apps/rooms/living_room.yaml b/apps/rooms/living_room.yaml index df9a4a2..867eddd 100644 --- a/apps/rooms/living_room.yaml +++ b/apps/rooms/living_room.yaml @@ -67,13 +67,13 @@ living_room: front_door: module: door - class: DoorControl + class: Door app: living_room door: binary_sensor.front_contact living_room_button: module: button - class: ButtonController + class: Button app: living_room button: Living Room Button ref_entity: light.living_room From e644eefa6d7fd9b3e8ab0778ed0ecb910267203d Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:50:47 -0600 Subject: [PATCH 04/26] added await to MotionCanceller --- apps/scene_detect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/scene_detect.py b/apps/scene_detect.py index a247b52..2311e44 100644 --- a/apps/scene_detect.py +++ b/apps/scene_detect.py @@ -22,4 +22,4 @@ class MotionCanceller(SceneDetector): async def scene_detected(self): await super().scene_detected() app = await self.get_app(self.args['app']) - app.cancel_motion_callback(new='off') \ No newline at end of file + await app.cancel_motion_callback(new='off') \ No newline at end of file From f877cab66de7724a380739d6525b1286414c6dcd Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:50:57 -0600 Subject: [PATCH 05/26] better logging --- apps/sleep.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/sleep.py b/apps/sleep.py index 49d5651..dc6a7aa 100755 --- a/apps/sleep.py +++ b/apps/sleep.py @@ -87,9 +87,12 @@ class SleepSetter(Hass, Mqtt): def handle_action(self, action: str): if action == '': return - elif action == 'hold': + + if action == 'hold': + self.log(f' {action.upper()} '.center(50, '=')) self.state = True elif action == 'double': + self.log(f' {action.upper()} '.center(50, '=')) self.state = not self.state self.on_apps() From 3b0b4e07bb82ab4e11878248d974a75d03f9d12b Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:51:27 -0600 Subject: [PATCH 06/26] sleep update --- apps/sleep.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sleep.yaml b/apps/sleep.yaml index 57148c6..b616f4f 100755 --- a/apps/sleep.yaml +++ b/apps/sleep.yaml @@ -9,7 +9,7 @@ sleep: - Bedroom Button 2 - Living Room Button off_apps: - - bedroom + # - bedroom - living_room - kitchen - bathroom From 9d0b5e4331e431e617b15352b23b6274f16908f1 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 18:51:33 -0600 Subject: [PATCH 07/26] room control update --- apps/room_control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/room_control b/apps/room_control index 8a5431a..afc5e45 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit 8a5431a72bc8f0ef5ae2f1c98d97db55bd670523 +Subproject commit afc5e456425ae7c1ba1e64d05bcf8405edc67296 From 00a7fd5048d4b5ed4a76f9f31b2607a06db89d9e Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 22:06:43 -0600 Subject: [PATCH 08/26] toggle stuff --- apps/cubes/cube.py | 18 ++++++++---------- apps/room_control | 2 +- apps/rooms/bathroom.yaml | 2 +- apps/rooms/bedroom.yaml | 1 + apps/rooms/kitchen.yaml | 2 +- apps/rooms/living_room.yaml | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/cubes/cube.py b/apps/cubes/cube.py index 13b8e06..536b8e2 100644 --- a/apps/cubes/cube.py +++ b/apps/cubes/cube.py @@ -1,15 +1,16 @@ import json from copy import deepcopy +from appdaemon.plugins.hass.hassapi import Hass from appdaemon.plugins.mqtt.mqttapi import Mqtt +# from ..room_control.room_control import RoomController -class AqaraCube(Mqtt): +class AqaraCube(Hass, Mqtt): def initialize(self): - self.set_namespace('mqtt') topic = f'zigbee2mqtt/{self.args["cube"]}' - self.mqtt_subscribe(topic) - self.listen_event(self.handle_event, "MQTT_MESSAGE", topic=topic) + self.mqtt_subscribe(topic, namespace='mqtt') + self.listen_event(self.handle_event, "MQTT_MESSAGE", topic=topic, namespace='mqtt') self.log(f'Listening for cube events on: {topic}') self.app = self.get_app(self.args['app']) @@ -39,12 +40,9 @@ class AqaraCube(Mqtt): self.call_service('scene/turn_on', entity_id=description, namespace='default') self.log(f'Turned on {description}') - elif description == 'toggle': - cause = f'{action} from {self.args["cube"]}' - if self.app.entity_state: - self.app.deactivate(cause=cause) - else: - self.app.activate(cause=cause) + elif description.startswith('toggle'): + cause = f'{self.args["cube"]} {action}' + self.app.toggle(kwargs={'cause': cause}) # def handle_rotate_right(self, payload): # self.log(f'{self.args["cube"]}: Rotate right') diff --git a/apps/room_control b/apps/room_control index afc5e45..1486450 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit afc5e456425ae7c1ba1e64d05bcf8405edc67296 +Subproject commit 148645094abd9ad253699aaf1d1b05d7c85ed4f3 diff --git a/apps/rooms/bathroom.yaml b/apps/rooms/bathroom.yaml index df8c701..d46566a 100644 --- a/apps/rooms/bathroom.yaml +++ b/apps/rooms/bathroom.yaml @@ -1,6 +1,7 @@ bathroom: module: room_control class: RoomController + ref_entity: light.bathroom off_duration: '00:05:00' states: - time: '05:00:00' @@ -35,7 +36,6 @@ bathroom_button: module: button class: Button app: bathroom - ref_entity: light.bathroom button: Bathroom Button bathroom_motion: diff --git a/apps/rooms/bedroom.yaml b/apps/rooms/bedroom.yaml index 19ea792..41b2b33 100644 --- a/apps/rooms/bedroom.yaml +++ b/apps/rooms/bedroom.yaml @@ -1,6 +1,7 @@ bedroom: module: room_control class: RoomController + ref_entity: light.bedroom off_duration: '00:05:00' states: - time: 'sunrise - 03:00:00' diff --git a/apps/rooms/kitchen.yaml b/apps/rooms/kitchen.yaml index 91063d9..74ec1f4 100755 --- a/apps/rooms/kitchen.yaml +++ b/apps/rooms/kitchen.yaml @@ -1,6 +1,7 @@ kitchen: module: room_control class: RoomController + ref_entity: light.kitchen off_duration: '00:10:00' ha_button: input_button.activate_kitchen states: @@ -40,7 +41,6 @@ kitchen_button: module: button class: Button app: kitchen - ref_entity: light.kitchen button: Kitchen Button kitchen_motion: diff --git a/apps/rooms/living_room.yaml b/apps/rooms/living_room.yaml index 867eddd..911ee33 100644 --- a/apps/rooms/living_room.yaml +++ b/apps/rooms/living_room.yaml @@ -1,6 +1,7 @@ living_room: module: room_control class: RoomController + ref_entity: light.living_room off_duration: 00:30:00 states: - time: sunrise @@ -76,7 +77,6 @@ living_room_button: class: Button app: living_room button: Living Room Button - ref_entity: light.living_room living_room_motion: module: motion From 07330e442d0a51dcac9eb7702dd5c83864d5413b Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 22:09:10 -0600 Subject: [PATCH 09/26] leaving update --- apps/leaving.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/leaving.py b/apps/leaving.py index 1c65ff1..68801bd 100644 --- a/apps/leaving.py +++ b/apps/leaving.py @@ -2,17 +2,13 @@ from appdaemon.adapi import ADAPI class Leaving(ADAPI): def initialize(self): - self.listen_state(self.handle_state_change, entity_id=self.args['person']) - - def handle_state_change(self, entity, attribute, old, new, kwargs): - self.log(f'Changed state {old} -> {new}') - if old == 'home' and new != 'home': - self.turn_everything_off() + self.listen_state(self.turn_everything_off, entity_id=self.args['person'], old='home') - def turn_everything_off(self): + def turn_everything_off(self, *args, **kwargs): + self.log(f'turning everything off') for app_name in self.args['apps']: try: - self.get_app(app_name).deactivate(cause='leaving') + self.get_app(app_name).deactivate(kwargs={'cause': 'leaving'}) except Exception as e: self.log(f'{type(e).__name__}: {e}') continue From f7d8fba8fb6535d29f38cf2bca88fdc240245ed0 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 22:36:18 -0600 Subject: [PATCH 10/26] gixed on apps --- apps/room_control | 2 +- apps/sleep.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/room_control b/apps/room_control index 1486450..8b00fac 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit 148645094abd9ad253699aaf1d1b05d7c85ed4f3 +Subproject commit 8b00faceb61e1717634c4d6f6a930f3351bbdf1a diff --git a/apps/sleep.py b/apps/sleep.py index dc6a7aa..135dd2e 100755 --- a/apps/sleep.py +++ b/apps/sleep.py @@ -117,7 +117,7 @@ class SleepSetter(Hass, Mqtt): if (on_apps := self.args.get('on_apps', None)) is not None: for app_name in on_apps: try: - self.get_app(app_name).activate(cause='sleep setter') + self.get_app(app_name).activate(kwargs={'cause': 'sleep setter'}) except: return else: From 0102321b87e192fa833907dff9ed1484c1126db6 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 22:36:41 -0600 Subject: [PATCH 11/26] fixed scene watchers --- apps/apps.yaml | 4 ++-- apps/scene_detect.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/apps.yaml b/apps/apps.yaml index a0a58d7..57c45a9 100644 --- a/apps/apps.yaml +++ b/apps/apps.yaml @@ -13,9 +13,9 @@ scene_detect: module: scene_detect class: MotionCanceller scene: bedsport - app: bedroom + app: bedroom_motion -scene_detect: +scene_detect2: module: scene_detect class: MotionCanceller scene: in_bed diff --git a/apps/scene_detect.py b/apps/scene_detect.py index 2311e44..6621deb 100644 --- a/apps/scene_detect.py +++ b/apps/scene_detect.py @@ -1,5 +1,5 @@ from appdaemon.plugins.hass.hassapi import Hass - +import asyncio class SceneDetector(Hass): def initialize(self): @@ -21,5 +21,6 @@ class SceneDetector(Hass): class MotionCanceller(SceneDetector): async def scene_detected(self): await super().scene_detected() + await asyncio.sleep(0.5) # needed for when the scene gets turned on from everything being off because of competing callbacks app = await self.get_app(self.args['app']) - await app.cancel_motion_callback(new='off') \ No newline at end of file + await app.cancel_motion_callback(new='off') From 4b0b7c5e6100c13bca09ad107bd5a3123333757f Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 3 Dec 2023 18:04:16 -0600 Subject: [PATCH 12/26] yaml tweaks --- appdaemon.yaml | 2 -- apps/rooms/kitchen.yaml | 2 +- apps/rooms/living_room.yaml | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/appdaemon.yaml b/appdaemon.yaml index 4d4d345..e4212af 100755 --- a/appdaemon.yaml +++ b/appdaemon.yaml @@ -1,6 +1,4 @@ appdaemon: - invalid_yaml_warnings: 0 - missing_app_warnings: 0 latitude: 30.250968 longitude: -97.748193 elevation: 150 diff --git a/apps/rooms/kitchen.yaml b/apps/rooms/kitchen.yaml index 74ec1f4..39c80bc 100755 --- a/apps/rooms/kitchen.yaml +++ b/apps/rooms/kitchen.yaml @@ -35,7 +35,7 @@ kitchen: scene: light.kitchen: state: on - brightness_pct: 1 + brightness: 1 kitchen_button: module: button diff --git a/apps/rooms/living_room.yaml b/apps/rooms/living_room.yaml index 911ee33..38aed73 100644 --- a/apps/rooms/living_room.yaml +++ b/apps/rooms/living_room.yaml @@ -59,7 +59,7 @@ living_room: brightness_pct: 5 sleep: input_boolean.sleeping sleep_state: - off_duration: '00:02:00' + # off_duration: '00:02:00' scene: light.living_room: state: 'on' From 8d303438ce20696658b03c3cd3feb3316468e54d Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 3 Dec 2023 18:04:30 -0600 Subject: [PATCH 13/26] read only on config folder --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index d6d370f..036ce3d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: volumes: - /etc/localtime:/etc/localtime:ro - /etc/timezone:/etc/timezone:ro - - config:/conf + - config:/conf:ro ports: - 5050:5050 restart: unless-stopped From 80392fbf9541646d4cc0684866ee1a1e451d2d50 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:03:37 -0600 Subject: [PATCH 14/26] rearrange --- apps/rooms/kitchen.yaml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/rooms/kitchen.yaml b/apps/rooms/kitchen.yaml index 39c80bc..638669d 100755 --- a/apps/rooms/kitchen.yaml +++ b/apps/rooms/kitchen.yaml @@ -3,7 +3,13 @@ kitchen: class: RoomController ref_entity: light.kitchen off_duration: '00:10:00' - ha_button: input_button.activate_kitchen + # ha_button: input_button.activate_kitchen + sleep: input_boolean.sleeping + sleep_state: + scene: + light.kitchen: + state: on + brightness: 1 states: - time: sunrise scene: @@ -30,13 +36,7 @@ kitchen: state: on color_temp: 650 brightness_pct: 10 - sleep: input_boolean.sleeping - sleep_state: - scene: - light.kitchen: - state: on - brightness: 1 - + kitchen_button: module: button class: Button From 7456174ef615a1a2b35292c38908c145d0804a13 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Thu, 7 Dec 2023 00:28:45 -0600 Subject: [PATCH 15/26] room control update --- apps/room_control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/room_control b/apps/room_control index 8b00fac..e0caaed 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit 8b00faceb61e1717634c4d6f6a930f3351bbdf1a +Subproject commit e0caaedc152c6edd7eb81d8ae1a7425fb08fcc17 From 56e4d893f5065792c3044c6902e10afbb8a15c2a Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Thu, 7 Dec 2023 00:33:20 -0600 Subject: [PATCH 16/26] changed to async branch for room_control submodule --- .gitmodules | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitmodules b/.gitmodules index 7125fa9..9b3b555 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,4 @@ [submodule "apps/room_control"] path = apps/room_control url = https://github.com/jsl12/room_control + branch = async From e3735e381b182c2d94a175b0b18956c432a54597 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Fri, 8 Dec 2023 08:18:56 -0600 Subject: [PATCH 17/26] fixed brightness_pct after update --- apps/rooms/bathroom.yaml | 10 +++++----- apps/rooms/bedroom.yaml | 29 ++++++++++++++--------------- apps/rooms/closet.yaml | 8 ++++---- apps/rooms/kitchen.yaml | 10 +++++----- apps/rooms/living_room.yaml | 24 ++++++++++++------------ 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/apps/rooms/bathroom.yaml b/apps/rooms/bathroom.yaml index d46566a..00137ff 100644 --- a/apps/rooms/bathroom.yaml +++ b/apps/rooms/bathroom.yaml @@ -1,28 +1,27 @@ bathroom: module: room_control class: RoomController - ref_entity: light.bathroom off_duration: '00:05:00' states: - time: '05:00:00' scene: light.bathroom: - brightness_pct: 40 + brightness: 100 color_temp: 250 - time: '12:00:00' scene: light.bathroom: - brightness_pct: 70 + brightness: 175 color_temp: 300 - time: sunset scene: light.bathroom: - brightness_pct: 50 + brightness: 125 color_temp: 350 - time: '23:00:00' scene: light.bathroom: - brightness_pct: 20 + brightness: 50 color_temp: 350 sleep: input_boolean.sleeping sleep_state: @@ -37,6 +36,7 @@ bathroom_button: class: Button app: bathroom button: Bathroom Button + ref_entity: light.bathroom bathroom_motion: module: motion diff --git a/apps/rooms/bedroom.yaml b/apps/rooms/bedroom.yaml index 41b2b33..1f85954 100644 --- a/apps/rooms/bedroom.yaml +++ b/apps/rooms/bedroom.yaml @@ -1,7 +1,6 @@ bedroom: module: room_control class: RoomController - ref_entity: light.bedroom off_duration: '00:05:00' states: - time: 'sunrise - 03:00:00' @@ -9,11 +8,11 @@ bedroom: light.bedroom: state: on color_temp: 200 - brightness_pct: 20 + brightness: 50 light.globe: state: on color_temp: 200 - brightness_pct: 20 + brightness: 50 light.overhead: state: off - time: '06:00:00' @@ -21,57 +20,57 @@ bedroom: light.bedroom: state: on color_temp: 250 - brightness_pct: 20 + brightness: 50 light.globe: state: on color_temp: 250 - brightness_pct: 20 + brightness: 50 light.overhead: state: on color_temp: 250 - brightness_pct: 15 + brightness: 40 - time: '12:00:00' scene: light.bedroom: state: on color_temp: 325 - brightness_pct: 30 + brightness: 75 light.globe: state: on color_temp: 325 - brightness_pct: 30 + brightness: 75 light.overhead: state: on color_temp: 325 - brightness_pct: 50 + brightness: 50 - time: 'sunset' scene: light.bedroom: state: on color_temp: 325 - brightness_pct: 50 + brightness: 50 light.globe: state: on color_temp: 325 - brightness_pct: 50 + brightness: 50 light.overhead: state: on color_temp: 350 - brightness_pct: 10 + brightness: 65 - time: '01:00:00' scene: light.bedroom: state: on color_name: green - brightness_pct: 50 + brightness: 50 light.globe: state: on color_name: blue - brightness_pct: 50 + brightness: 50 light.overhead: state: on color_name: blueviolet - brightness_pct: 100 + brightness: 255 sleep: input_boolean.sleeping bedroom_buttons: diff --git a/apps/rooms/closet.yaml b/apps/rooms/closet.yaml index 5011890..b9ac54a 100644 --- a/apps/rooms/closet.yaml +++ b/apps/rooms/closet.yaml @@ -6,22 +6,22 @@ closet: - time: 'sunrise - 03:00:00' scene: light.closet: - brightness_pct: 10 + brightness: 25 color_temp: 200 - time: 'sunrise' scene: light.closet: - brightness_pct: 30 + brightness: 75 color_temp: 200 - time: '12:00:00' scene: light.closet: - brightness_pct: 70 + brightness: 175 color_temp: 300 - time: sunset scene: light.closet: - brightness_pct: 40 + brightness: 100 color_temp: 400 closet_motion: diff --git a/apps/rooms/kitchen.yaml b/apps/rooms/kitchen.yaml index 638669d..e7bc239 100755 --- a/apps/rooms/kitchen.yaml +++ b/apps/rooms/kitchen.yaml @@ -1,7 +1,6 @@ kitchen: module: room_control class: RoomController - ref_entity: light.kitchen off_duration: '00:10:00' # ha_button: input_button.activate_kitchen sleep: input_boolean.sleeping @@ -16,32 +15,33 @@ kitchen: light.kitchen: state: on color_temp: 200 - brightness_pct: 10 + brightness: 25 - time: '12:00:00' scene: light.kitchen: state: on color_temp: 300 - brightness_pct: 30 + brightness: 75 - time: sunset scene: light.kitchen: state: on color_temp: 450 - brightness_pct: 40 + brightness: 100 - time: '22:00:00' off_duration: '00:02:00' scene: light.kitchen: state: on color_temp: 650 - brightness_pct: 10 + brightness: 25 kitchen_button: module: button class: Button app: kitchen button: Kitchen Button + ref_entity: light.kitchen kitchen_motion: module: motion diff --git a/apps/rooms/living_room.yaml b/apps/rooms/living_room.yaml index 38aed73..0a81a83 100644 --- a/apps/rooms/living_room.yaml +++ b/apps/rooms/living_room.yaml @@ -1,7 +1,6 @@ living_room: module: room_control class: RoomController - ref_entity: light.living_room off_duration: 00:30:00 states: - time: sunrise @@ -9,42 +8,42 @@ living_room: light.living_room: state: on color_temp: 200 - brightness_pct: 30 + brightness: 75 light.couch_corner: state: on color_temp: 200 - brightness_pct: 7 + brightness: 20 - time: '09:00:00' scene: light.living_room: state: on color_temp: 250 - brightness_pct: 50 + brightness: 130 light.couch_corner: state: on color_temp: 250 - brightness_pct: 25 + brightness: 65 - time: '12:00:00' scene: light.living_room: state: on color_temp: 300 - brightness_pct: 100 + brightness: 255 light.couch_corner: state: on color_temp: 450 - brightness_pct: 50 + brightness: 125 - time: sunset off_duration: 01:00:00 scene: light.living_room: state: on color_temp: 350 - brightness_pct: 70 + brightness: 175 light.couch_corner: state: on color_temp: 650 - brightness_pct: 10 + brightness: 25 - elevation: -20 direction: setting off_duration: 00:30:00 @@ -52,11 +51,11 @@ living_room: light.living_room: state: on color_temp: 350 - brightness_pct: 50 + brightness: 125 light.couch_corner: state: on color_temp: 650 - brightness_pct: 5 + brightness: 5 sleep: input_boolean.sleeping sleep_state: # off_duration: '00:02:00' @@ -64,7 +63,7 @@ living_room: light.living_room: state: 'on' color_name: 'red' - brightness_pct: 10 + brightness: 25 front_door: module: door @@ -77,6 +76,7 @@ living_room_button: class: Button app: living_room button: Living Room Button + ref_entity: light.living_room living_room_motion: module: motion From b93b3081319ed95d76d505eead4c32dd7763e0c9 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Fri, 8 Dec 2023 08:23:09 -0600 Subject: [PATCH 18/26] room_control update --- apps/room_control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/room_control b/apps/room_control index e0caaed..cf9f0f3 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit e0caaedc152c6edd7eb81d8ae1a7425fb08fcc17 +Subproject commit cf9f0f3244f7b4bb9dcc96e3f119ce4fca5773e6 From 496664e106cedd4f4ddccc6fea4a9d770f4baa17 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Fri, 8 Dec 2023 08:23:20 -0600 Subject: [PATCH 19/26] added bathroom button to sleep setter --- apps/sleep.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/sleep.yaml b/apps/sleep.yaml index b616f4f..2b25bb8 100755 --- a/apps/sleep.yaml +++ b/apps/sleep.yaml @@ -8,6 +8,7 @@ sleep: - Bedroom Button 1 - Bedroom Button 2 - Living Room Button + - Bathroom Button off_apps: # - bedroom - living_room From 2cd374a9275a8420c17a90bdd1688229d710b0cb Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Mon, 8 Jan 2024 20:24:27 -0600 Subject: [PATCH 20/26] fixed leaving? --- apps/leaving.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/leaving.py b/apps/leaving.py index 68801bd..005811b 100644 --- a/apps/leaving.py +++ b/apps/leaving.py @@ -1,6 +1,7 @@ -from appdaemon.adapi import ADAPI +from appdaemon.plugins.hass.hassapi import Hass -class Leaving(ADAPI): + +class Leaving(Hass): def initialize(self): self.listen_state(self.turn_everything_off, entity_id=self.args['person'], old='home') From e71b0030994b1af426d5ea3d409f8d1c33bbd8eb Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Mon, 15 Jan 2024 23:04:34 -0600 Subject: [PATCH 21/26] room_control update --- apps/room_control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/room_control b/apps/room_control index cf9f0f3..dda9d2b 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit cf9f0f3244f7b4bb9dcc96e3f119ce4fca5773e6 +Subproject commit dda9d2b5016fb7275feaa9d9f1f7e508f68c4302 From 4ab88d11ca62d8f0120f70a3c71b7eccce93fd31 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 21 Jan 2024 10:57:51 -0600 Subject: [PATCH 22/26] had to change from color name to RGB for some reason --- apps/rooms/living_room.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/rooms/living_room.yaml b/apps/rooms/living_room.yaml index 0a81a83..da15c4b 100644 --- a/apps/rooms/living_room.yaml +++ b/apps/rooms/living_room.yaml @@ -62,7 +62,7 @@ living_room: scene: light.living_room: state: 'on' - color_name: 'red' + rgb_color: [255, 0, 0] brightness: 25 front_door: From 27c89cf542edb1d2d3d03df7681052fbead35de9 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:47:45 -0600 Subject: [PATCH 23/26] submodule update --- apps/room_control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/room_control b/apps/room_control index dda9d2b..d8a9d3d 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit dda9d2b5016fb7275feaa9d9f1f7e508f68c4302 +Subproject commit d8a9d3d83af6510429b55d4f525e5de1c42483d4 From 986996c595b72c03d1846b6cfe4d187be40eed0d Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:48:00 -0600 Subject: [PATCH 24/26] fixed toggle --- apps/cubes/cube.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/cubes/cube.py b/apps/cubes/cube.py index 536b8e2..01634c0 100644 --- a/apps/cubes/cube.py +++ b/apps/cubes/cube.py @@ -4,7 +4,6 @@ from copy import deepcopy from appdaemon.plugins.hass.hassapi import Hass from appdaemon.plugins.mqtt.mqttapi import Mqtt -# from ..room_control.room_control import RoomController class AqaraCube(Hass, Mqtt): def initialize(self): @@ -42,7 +41,7 @@ class AqaraCube(Hass, Mqtt): elif description.startswith('toggle'): cause = f'{self.args["cube"]} {action}' - self.app.toggle(kwargs={'cause': cause}) + self.app.toggle_activate(kwargs={'cause': cause}) # def handle_rotate_right(self, payload): # self.log(f'{self.args["cube"]}: Rotate right') From 28d054128435fb5871dbd29dee7c0eac394d0478 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:53:05 -0600 Subject: [PATCH 25/26] removed async --- apps/scene_detect.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/apps/scene_detect.py b/apps/scene_detect.py index 6621deb..6df4891 100644 --- a/apps/scene_detect.py +++ b/apps/scene_detect.py @@ -1,5 +1,5 @@ from appdaemon.plugins.hass.hassapi import Hass -import asyncio + class SceneDetector(Hass): def initialize(self): @@ -9,18 +9,25 @@ class SceneDetector(Hass): self.listen_event(self.event_callback, event='call_service', domain='scene', service='turn_on') self.log(f'Waiting for {self.scene_entity.friendly_name} to activate') - async def event_callback(self, event_name, data, cb_args): + def event_callback(self, event_name, data, cb_args): entity_id = data['service_data']['entity_id'] if entity_id == self.scene_entity.entity_id: - await self.scene_detected() + self.scene_detected() - async def scene_detected(self): + def scene_detected(self): self.log(f'Detected scene activation: {self.scene_entity.friendly_name}') class MotionCanceller(SceneDetector): - async def scene_detected(self): - await super().scene_detected() - await asyncio.sleep(0.5) # needed for when the scene gets turned on from everything being off because of competing callbacks - app = await self.get_app(self.args['app']) - await app.cancel_motion_callback(new='off') + def scene_detected(self): + super().scene_detected() + app = self.get_app(self.args['app']) + try: + self.run_in( + callback=lambda *args, **kwargs: app.cancel_motion_callback(), + delay=0.5 + ) + except: + self.log(f'Error cancelling motion callback for {self.args["app"]}', level='ERROR') + else: + self.log('Cancelled motion callback') From 0eb484f187b6dd2dbe08cfcbbdf0e8f5858fdec1 Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sun, 28 Jan 2024 08:53:51 -0600 Subject: [PATCH 26/26] expanded callback arguments --- apps/leaving.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/leaving.py b/apps/leaving.py index 005811b..edcd285 100644 --- a/apps/leaving.py +++ b/apps/leaving.py @@ -5,8 +5,9 @@ class Leaving(Hass): def initialize(self): self.listen_state(self.turn_everything_off, entity_id=self.args['person'], old='home') - def turn_everything_off(self, *args, **kwargs): + def turn_everything_off(self, entity, attribute, old, new, kwargs): self.log(f'turning everything off') + self.log(kwargs) for app_name in self.args['apps']: try: self.get_app(app_name).deactivate(kwargs={'cause': 'leaving'})