Config update

This commit is contained in:
2025-12-07 12:22:33 +01:00
parent 9718d9428a
commit 52d11bfff0
9 changed files with 318 additions and 222 deletions

View File

@@ -1,40 +1,6 @@
from datetime import datetime, timedelta
from datetime import datetime
from ir_helpers import *
TIMEOUT_REPEAT_PRESS = 5 # time to switch states when pressed shortly in sequence, in seconds
# --------------------------------- Helper functions ----------------------------------------------------
light_scene_helper_dict = {}
def scene_helper(scene_function):
"""Function to manage the repeated press of the same action
When pressed shortly in sequence, states are cycled
Otherwise light is toggled"""
unique_name_for_globals = id(scene_function)
is_on_func, scenes = scene_function()
last_called, call_idx = light_scene_helper_dict.get(unique_name_for_globals, (datetime.now(), -1))
now = datetime.now()
time_since_last_call = now - last_called
recently_called = (time_since_last_call < timedelta(seconds=TIMEOUT_REPEAT_PRESS))
light_already_on = is_on_func()
log.warning(f"{light_already_on=}")
if recently_called:
call_idx = (call_idx + 1)
else:
call_idx = -1
if light_already_on and call_idx == -1:
scenes[-1]()
call_idx = -1
elif not light_already_on:
scenes[0]()
call_idx = 0
else:
idx = call_idx % len(scenes)
scenes[idx]()
light_scene_helper_dict[unique_name_for_globals] = (now, call_idx)
# --------------------------------- "Scenes" for actions ----------------------------------------------------

View File

@@ -5,32 +5,36 @@ async def regal_licht_f(**kwargs):
await hass.services.async_call('light', 'turn_on', {'entity_id': "light.music_mouse_regal_licht", 'effect': 'static', **kwargs})
return f
@event_trigger("ir_command_received", "host == 'musicmouse.fritz.box' and repeat_counter == 0 and remote == 'ir_led3'")
@event_trigger("ir_command_received", "host == 'musicmouse.fritz.box' and repeat_counter == 0 and remote == 'small_led_remote'")
def ir_remote_kinderzimmer(button_name=None, **kwargs):
def dim_offset_f(offset):
async def f():
await hass.services.async_call('dimmer', 'dim', {'entity_id': 'group.kids_room', 'offset': offset})
return f
mapping = {
'key_on': scene_f('kinderzimmer_hell'),
'key_off': light_f("turn_off", entity_id="group.kids_room"),
'key_brightnessup': cover_f('open_cover', 'cover.kinderzimmer_rollo'),
'key_brightnessdown': cover_f('close_cover', 'cover.kinderzimmer_rollo'),
'key_white': scene_f('kinderzimmer_hell'),
'key_red': scene_f('kinderzimmer_wickeln_nachts'),
'key_pound': regal_licht_f(rgbw_color=[255, 30, 60, 0]),
'key_1': regal_licht_f(rgbw_color=[255, 30, 60, 0]),
'key_2': regal_licht_f(rgbw_color=[28, 255, 35, 0]),
'key_3': regal_licht_f(rgbw_color=[0, 0, 255, 0]),
'key_4': regal_licht_f(rgbw_color=[255, 156, 17, 0]),
'key_5': regal_licht_f(rgbw_color=[12, 166, 255, 0]),
'key_6': regal_licht_f(rgbw_color=[185, 10, 255, 0]),
'key_7': regal_licht_f(rgbw_color=[255, 156, 17, 0], brightness=50, effect="side_0.2_inc8"),
'key_8': regal_licht_f(rgbw_color=[0, 0, 255, 0], brightness=50, effect="side_0.2_inc8"),
'key_9': regal_licht_f(rgbw_color=[255, 30, 60, 0], brightness=50, effect="side_0.2_inc8"),
'on': scene_f('kinderzimmer_hell'),
'off': light_f("turn_off", entity_id="group.kids_room"),
'brightness_up': cover_f('open_cover', 'cover.kinderzimmer_rollo'),
'brightness_down': cover_f('close_cover', 'cover.kinderzimmer_rollo'),
'white': scene_f('kinderzimmer_hell'),
'red': scene_f('kinderzimmer_wickeln_nachts'),
'hash_pink': regal_licht_f(rgbw_color=[255, 30, 60, 0]),
'1_orange': regal_licht_f(rgbw_color=[255, 30, 60, 0]),
'2_green': regal_licht_f(rgbw_color=[28, 255, 35, 0]),
'3_light_blue': regal_licht_f(rgbw_color=[0, 0, 255, 0]),
'4_orange': regal_licht_f(rgbw_color=[255, 156, 17, 0]),
'5_blue': regal_licht_f(rgbw_color=[12, 166, 255, 0]),
'6_purple': regal_licht_f(rgbw_color=[185, 10, 255, 0]),
'7_yellow': regal_licht_f(rgbw_color=[255, 156, 17, 0], brightness=50, effect="side_0.2_inc8"),
'8_light_blue': regal_licht_f(rgbw_color=[0, 0, 255, 0], brightness=50, effect="side_0.2_inc8"),
'9_pink': regal_licht_f(rgbw_color=[255, 30, 60, 0], brightness=50, effect="side_0.2_inc8"),
'star_yellow': scene_f('kinderzimmer_regal_dunkel'),
'fade': dim_offset_f(+30),
'smooth': dim_offset_f(-30),
}
if button_name in mapping:
mapping[button_name]()
elif button_name == 'key_smooth':
dimmer.dim(entity_id="light.music_mouse_regal_licht", offset=-30)
elif button_name == 'key_fade':
dimmer.dim(entity_id="light.music_mouse_regal_licht", offset=+30)
@event_trigger("ir_command_received", "host == 'musicmouse.fritz.box' and repeat_counter == 0 and remote == 'Hauppauge'")
def ir_remote_hauppauge_kinderzimmer(button_name=None, **kwargs):
@@ -39,6 +43,16 @@ def ir_remote_hauppauge_kinderzimmer(button_name=None, **kwargs):
**default_ir_light_control('group.kids_room'),
**default_ir_cover_control('group.kids_room'),
**default_ir_music_control(**p),
'key_red': scene_f('kinderzimmer_regal_dunkel'),
'key_green': scene_f('kinderzimmer_orange'),
'key_yellow': scene_f('kinderzimmer_hell'),
'key_blue': scene_f('kinderzimmer_normal'),
'btn_1': playlist_f('Good Morning', **p),
'btn_2': playlist_f('Good Night Long', **p),
'btn_3': playlist_f('Good Night', **p),
'key_video': playlist_f('Good Night', **p),
}
if button_name in mapping:
mapping[button_name]()

View File

@@ -4,11 +4,11 @@
# unten: kurz: off, but 1 min bedlight
# lang: rollos zu: nur tagsueber wenn komplett offen
@event_trigger("homematic.keypress", "name == 'schlafzimmer_deckenlampe'")
def schlafzimmer_licht(channel=None, param=None, **kwargs):
up = (channel == 2)
down = (channel == 1)
long = (param == "PRESS_LONG")
short = not long
def schlafzimmer_licht(subtype=None, type=None, **kwargs):
up = (subtype == 2)
down = (subtype == 1)
long = (type == "press_long")
short= (type == "press_short")
log.info(f"Schlafzimmer knopf up {up}, long {long}")
if up and short:

View File

@@ -1,3 +1,4 @@
from datetime import datetime, timedelta
# ---------------------------------- Music ---------------------------------------------
URLS = {
@@ -129,3 +130,39 @@ class CyclicCounter:
def prev(self):
self.idx = (self.idx - 1) % len(self.values)
self.func(self.values[self.idx])
TIMEOUT_REPEAT_PRESS = 5 # time to switch states when pressed shortly in sequence, in seconds
# --------------------------------- Helper functions ----------------------------------------------------
light_scene_helper_dict = {}
def scene_helper(scene_function):
"""Function to manage the repeated press of the same action
When pressed shortly in sequence, states are cycled
Otherwise light is toggled"""
unique_name_for_globals = id(scene_function)
is_on_func, scenes = scene_function()
last_called, call_idx = light_scene_helper_dict.get(unique_name_for_globals, (datetime.now(), -1))
now = datetime.now()
time_since_last_call = now - last_called
recently_called = (time_since_last_call < timedelta(seconds=TIMEOUT_REPEAT_PRESS))
light_already_on = is_on_func()
log.warning(f"{light_already_on=}")
if recently_called:
call_idx = (call_idx + 1)
else:
call_idx = -1
if light_already_on and call_idx == -1:
scenes[-1]()
call_idx = -1
elif not light_already_on:
scenes[0]()
call_idx = 0
else:
idx = call_idx % len(scenes)
scenes[idx]()
light_scene_helper_dict[unique_name_for_globals] = (now, call_idx)