Compare commits

...

3 Commits

Author SHA1 Message Date
John Lancaster
61d5d99dee changed time format in logs 2025-12-02 22:07:20 -06:00
John Lancaster
29759692b2 added the govee stick to the bar lights stages 2025-12-02 22:07:07 -06:00
John Lancaster
fbd60ab6ac started moes pad driver and app 2025-12-02 10:50:30 -06:00
4 changed files with 101 additions and 6 deletions

7
apps/drivers/moes.yaml Normal file
View 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
View 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')

View File

@@ -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:

View File

@@ -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',