Compare commits
5 Commits
main
...
657d01a724
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
657d01a724 | ||
|
|
e21eca4f42 | ||
|
|
61d5d99dee | ||
|
|
29759692b2 | ||
|
|
fbd60ab6ac |
@@ -1,6 +1,5 @@
|
|||||||
appdaemon:
|
appdaemon:
|
||||||
uvloop: True
|
uvloop: True
|
||||||
use_dictionary_unpacking: True
|
|
||||||
import_method: expert
|
import_method: expert
|
||||||
latitude: 30.250968
|
latitude: 30.250968
|
||||||
longitude: -97.748193
|
longitude: -97.748193
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
hello-world:
|
hello-world:
|
||||||
module: hello
|
module: hello
|
||||||
class: HelloWorld
|
class: HelloWorld
|
||||||
|
|
||||||
|
gone:
|
||||||
|
module: gone
|
||||||
|
class: Gone
|
||||||
|
entities:
|
||||||
|
- light.bar
|
||||||
|
- light.h6076
|
||||||
|
- light.h6076_2
|
||||||
|
|||||||
7
apps/drivers/moes.yaml
Normal file
7
apps/drivers/moes.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
moes_driver:
|
||||||
|
module: moes_pad
|
||||||
|
class: MoesBridge
|
||||||
|
|
||||||
|
moes2:
|
||||||
|
module: moes_pad
|
||||||
|
class: MoesPad
|
||||||
73
apps/drivers/moes_pad.py
Normal file
73
apps/drivers/moes_pad.py
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
from enum import Enum
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from appdaemon.adapi import ADAPI
|
||||||
|
from appdaemon.adbase import ADBase
|
||||||
|
|
||||||
|
|
||||||
|
class MoesButtons(int, Enum):
|
||||||
|
TOP_LEFT = 1
|
||||||
|
TOP_RIGHT = 2
|
||||||
|
BOTTOM_LEFT = 3
|
||||||
|
BOTTOM_RIGHT = 4
|
||||||
|
|
||||||
|
|
||||||
|
class MoesActions(str, Enum):
|
||||||
|
SINGLE_PRESS = 'single'
|
||||||
|
DOUBLE_PRESS = 'double'
|
||||||
|
LONG_PRESS = 'hold'
|
||||||
|
|
||||||
|
|
||||||
|
class MoesBridge(ADBase):
|
||||||
|
"""Class for an app that listens for state changes generated by 4 button Moes Pads and makes the events more
|
||||||
|
sensible with enums."""
|
||||||
|
|
||||||
|
adapi: ADAPI
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
self.adapi = self.get_ad_api()
|
||||||
|
self.log = self.adapi.log
|
||||||
|
self.event_handle = self.adapi.listen_state(self.handle_state_change)
|
||||||
|
|
||||||
|
def handle_state_change(self, entity: str, attribute: str, old: Any, new: Any, **kwargs: Any) -> None:
|
||||||
|
if new == '' or not new[0].isdigit():
|
||||||
|
return
|
||||||
|
|
||||||
|
domain, ent = entity.split('.', 1)
|
||||||
|
if domain == 'sensor' and ent.startswith('moes'):
|
||||||
|
button, action = new.split('_')
|
||||||
|
button = MoesButtons(int(button))
|
||||||
|
button_str = button.name.lower().replace('_', ' ')
|
||||||
|
action = MoesActions(action)
|
||||||
|
self.log(f'Moes Pad action detected: {action.value} on button {button_str}')
|
||||||
|
self.adapi.fire_event(
|
||||||
|
'moes_pad',
|
||||||
|
device=entity,
|
||||||
|
button=button,
|
||||||
|
action=action,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MoesPad(ADBase):
|
||||||
|
def initialize(self):
|
||||||
|
self.adapi = self.get_ad_api()
|
||||||
|
self.log = self.adapi.log
|
||||||
|
self.event_handle = self.adapi.listen_event(self.handle_moes_event, 'moes_pad')
|
||||||
|
|
||||||
|
def handle_moes_event(self, event_name: str, data: dict[str, Any], **kwargs: Any) -> None:
|
||||||
|
button = MoesButtons(data.get('button'))
|
||||||
|
action = MoesActions(data.get('action'))
|
||||||
|
self.log(f'Received Moes Pad event: {action} on button {button}')
|
||||||
|
|
||||||
|
match action:
|
||||||
|
case MoesActions.SINGLE_PRESS:
|
||||||
|
self.handle_single_press(button)
|
||||||
|
|
||||||
|
def handle_single_press(self, button: MoesButtons) -> None:
|
||||||
|
match button:
|
||||||
|
case MoesButtons.TOP_LEFT:
|
||||||
|
self.adapi.call_service('light/toggle', entity_id='light.bedroom_sydney')
|
||||||
|
case MoesButtons.TOP_RIGHT:
|
||||||
|
self.adapi.call_service('light/toggle', entity_id='light.bedroom_john')
|
||||||
|
case MoesButtons.BOTTOM_LEFT:
|
||||||
|
self.adapi.call_service('light/toggle', entity_id='light.h6076_2')
|
||||||
27
apps/gone.py
Normal file
27
apps/gone.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from appdaemon.plugins.hass import Hass
|
||||||
|
|
||||||
|
|
||||||
|
class Gone(Hass):
|
||||||
|
def initialize(self):
|
||||||
|
people = self.get_state('person')
|
||||||
|
# self.log(json.dumps(people, indent=2))
|
||||||
|
|
||||||
|
self.log(list(people.keys()))
|
||||||
|
for person in self.get_state('person'):
|
||||||
|
self.listen_state(self.handle_state, entity_id=person, new='not_home')
|
||||||
|
|
||||||
|
self.log(f'No one home: {self.no_one_home()}')
|
||||||
|
|
||||||
|
def no_one_home(self) -> bool:
|
||||||
|
return all(state.get('state') != 'home' for state in self.get_state('person', copy=False).values())
|
||||||
|
|
||||||
|
def handle_state(self, entity: str, attribute: str, old: Any, new: Any, **kwargs: Any) -> None:
|
||||||
|
if self.no_one_home():
|
||||||
|
for ent in self.args['entities']:
|
||||||
|
try:
|
||||||
|
self.turn_off(ent)
|
||||||
|
except Exception:
|
||||||
|
self.log(f'Failed to turn off {ent}', level='ERROR')
|
||||||
|
continue
|
||||||
@@ -39,13 +39,25 @@ bar_lights:
|
|||||||
- start: 'sunset'
|
- start: 'sunset'
|
||||||
scene:
|
scene:
|
||||||
light.bar:
|
light.bar:
|
||||||
state: on
|
state: "on"
|
||||||
color_temp_kelvin: 2202
|
color_temp_kelvin: 2202
|
||||||
brightness: 100
|
brightness: 100
|
||||||
light.server_lamp:
|
light.server_lamp:
|
||||||
state: on
|
state: "on"
|
||||||
rgb_color: [255, 112, 86]
|
rgb_color:
|
||||||
|
- 255
|
||||||
|
- 112
|
||||||
|
- 86
|
||||||
brightness: 175
|
brightness: 175
|
||||||
|
light.h6076:
|
||||||
|
state: "on"
|
||||||
|
brightness: 50
|
||||||
|
effect: sunset
|
||||||
|
- start: 'sunset + 1:00'
|
||||||
|
scene:
|
||||||
|
light.h6076:
|
||||||
|
state: on
|
||||||
|
brightness: 255
|
||||||
- start: '10:00 pm'
|
- start: '10:00 pm'
|
||||||
scene:
|
scene:
|
||||||
light.bar:
|
light.bar:
|
||||||
@@ -56,6 +68,9 @@ bar_lights:
|
|||||||
state: on
|
state: on
|
||||||
rgb_color: [255, 112, 86]
|
rgb_color: [255, 112, 86]
|
||||||
brightness: 75
|
brightness: 75
|
||||||
|
light.h6076:
|
||||||
|
state: "on"
|
||||||
|
brightness: 175
|
||||||
- start: '11:30 pm'
|
- start: '11:30 pm'
|
||||||
scene:
|
scene:
|
||||||
light.bar:
|
light.bar:
|
||||||
|
|||||||
@@ -69,15 +69,15 @@ class StagedLight(Hass):
|
|||||||
|
|
||||||
### Transitions
|
### Transitions
|
||||||
|
|
||||||
def schedule_transition_checks(self, **kwargs: Any):
|
def schedule_transition_checks(self, **_):
|
||||||
now = self.get_now()
|
now = self.get_now()
|
||||||
for stage in self._stages:
|
for stage in self._stages:
|
||||||
dt = self.parse_datetime(stage.start, aware=True, today=True)
|
dt = self.parse_datetime(stage.start, aware=True, today=True)
|
||||||
if dt > now:
|
if dt > now:
|
||||||
self.log(f'Scehduling transition at: {dt.isoformat()}', level='DEBUG')
|
self.log(f'Scehduling transition at: {dt.strftime("%I:%M %p")}', level='DEBUG')
|
||||||
self.run_at(self._check_transition, start=dt)
|
self.run_at(self._check_transition, start=dt)
|
||||||
|
|
||||||
def _check_transition(self, **kwargs: Any):
|
def _check_transition(self, **_):
|
||||||
self.log('Firing transition event', level='DEBUG')
|
self.log('Firing transition event', level='DEBUG')
|
||||||
self.fire_event(
|
self.fire_event(
|
||||||
'stage_control',
|
'stage_control',
|
||||||
|
|||||||
Reference in New Issue
Block a user