added the blue button app
This commit is contained in:
@@ -9,3 +9,7 @@ gone:
|
||||
- light.bar
|
||||
- light.h6076
|
||||
- light.h6076_2
|
||||
|
||||
blue-button:
|
||||
module: media_button
|
||||
class: Button
|
||||
38
apps/media_button.py
Normal file
38
apps/media_button.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
from appdaemon.plugins.hass import Hass
|
||||
|
||||
|
||||
class ButtonPress(str, Enum):
|
||||
SINGLE = 'single'
|
||||
DOUBLE = 'double'
|
||||
HOLD = 'hold'
|
||||
|
||||
|
||||
class Button(Hass):
|
||||
def initialize(self):
|
||||
self.set_log_level('DEBUG')
|
||||
self.listen_state(
|
||||
self.handle_button,
|
||||
entity_id='sensor.blue_lamp_button_action',
|
||||
new=lambda s: s.strip() != '',
|
||||
)
|
||||
|
||||
def handle_button(self, entity: str, attribute: str, old: Any, new: Any, **kwargs: Any) -> None:
|
||||
match new:
|
||||
case ButtonPress.SINGLE:
|
||||
self.log('Single press')
|
||||
self.call_service('media_player/media_play_pause', entity_id='media_player.living_room_tv')
|
||||
case ButtonPress.DOUBLE:
|
||||
self.log('Double')
|
||||
self.call_service(
|
||||
'scene/apply',
|
||||
entities={
|
||||
'light.bar': {'state': 'on', 'brightness': 10},
|
||||
'light.living_room_stick': {'state': 'on', 'brightness': 100},
|
||||
'light.server_lamp': {'state': 'on', 'brightness': 25},
|
||||
},
|
||||
)
|
||||
case ButtonPress.HOLD:
|
||||
self.log('Hold down')
|
||||
Reference in New Issue
Block a user