259 lines
9.7 KiB
Python
259 lines
9.7 KiB
Python
from datetime import datetime
|
|
from ir_helpers import *
|
|
|
|
|
|
# --------------------------------- "Scenes" for actions ----------------------------------------------------
|
|
|
|
def az_oben_licht_scenes():
|
|
entity = "light.arbeitszimmer_oben_fluter"
|
|
now = datetime.now()
|
|
if now.hour >=8 and now.hour < 19: # day
|
|
scenes = [
|
|
light_f("turn_on", entity, color_temp=180, brightness=230),
|
|
light_f("turn_on", entity, color_temp= 468, brightness=230),
|
|
light_f("turn_on", entity, color_temp= 468, brightness=100),
|
|
light_f("turn_off", entity)
|
|
]
|
|
elif now.hour < 8: # morning
|
|
scenes = [
|
|
light_f("turn_on", entity, color_temp=420, brightness=200, transition=60),
|
|
light_f("turn_on", entity, color_temp=420, brightness=250, transition=60),
|
|
light_f("turn_off", entity)
|
|
]
|
|
else: # evening
|
|
scenes = [
|
|
light_f("turn_on", entity, color_temp=470, brightness=100),
|
|
light_f("turn_on", entity, color_temp=470, brightness=20),
|
|
light_f("turn_off", entity)
|
|
]
|
|
|
|
is_on = lambda entity=entity: hass.states.get(entity).state == "on"
|
|
return is_on, scenes
|
|
|
|
def kz_regal_scenes():
|
|
now = datetime.now()
|
|
entity = "light.music_mouse_regal_licht"
|
|
|
|
def fade_out_f(rgb_color, seconds):
|
|
return multiple_f(cover_f("close_cover", "cover.kinderzimmer_rollo"),
|
|
light_f("turn_on", entity, brightness=250, rgb_color=rgb_color, effect="side_0.5"),
|
|
light_f("turn_on", entity, brightness= 10, rgb_color=rgb_color, effect="side_0.5_inc4", transition=int(0.8 * seconds)),
|
|
light_f("turn_on", entity, brightness= 10, rgb_color=rgb_color, effect="side_0.2_inc8", transition=int(0.2 * seconds))),
|
|
|
|
if now.hour >= 18: # abends
|
|
scenes = [
|
|
fade_out_f([255, 182, 41], 10 * 60),
|
|
fade_out_f([255, 98, 231], 10 * 60),
|
|
light_f("turn_off", entity)
|
|
]
|
|
else:
|
|
scenes = [
|
|
light_f("turn_on", entity, brightness=250, rgb_color=[255, 182, 41], effect="static"),
|
|
light_f("turn_on", entity, brightness=250, rgb_color=[255, 98, 231], effect="static"),
|
|
light_f("turn_on", entity, brightness=250, rgb_color=[30, 30, 255], effect="static"),
|
|
light_f("turn_on", entity, brightness=200, effect="twocolorrandom"),
|
|
light_f("turn_off", entity)
|
|
]
|
|
is_on = lambda entity=entity: hass.states.get(entity).state == "on"
|
|
return is_on, scenes
|
|
|
|
|
|
def az_unten_licht_scenes():
|
|
scenes = [
|
|
scene_f("arbeitszimmer_orange"),
|
|
scene_f("arbeitszimmer_hell"),
|
|
scene_f("arbeitszimmer_blau_grun"),
|
|
light_f("turn_off", "light.arbeitszimmer_lichter"),
|
|
]
|
|
is_on = lambda: hass.states.get("light.arbeitszimmer_lichter").state == "on"
|
|
return is_on, scenes
|
|
|
|
def wz_deckenlampe():
|
|
scenes = [
|
|
light_f("turn_off", "light.wohnzimmer_deckenlampe"),
|
|
light_f("turn_off", "light.wohnbereich_deckenlampen"),
|
|
multiple_f(light_f("turn_on", "light.kuche_deckenlampe", brightness=10),
|
|
light_f("turn_on", "light.esszimmer_deckenlampe_west", brightness=10),
|
|
light_f("turn_on", "light.wohnzimmer_deckenlampe", brightness=10),
|
|
)
|
|
]
|
|
|
|
def is_off():
|
|
entities = ["light.kuche_deckenlampe",
|
|
"light.esszimmer_deckenlampe_west",
|
|
"light.wohnzimmer_deckenlampe"]
|
|
return all(hass.states.get(e) == 'off' for e in entities)
|
|
|
|
return is_off, scenes
|
|
|
|
def wohnbereich_scenes():
|
|
scenes = [
|
|
scene_f("wohnbereich_orange"),
|
|
scene_f("wohnbereich_hell"),
|
|
scene_f("wohnbereich_blau_grun"),
|
|
scene_f("wohnbereich_grun"),
|
|
light_f("turn_off", "light.wohnbereich_lichter"),
|
|
]
|
|
is_on = lambda: hass.states.get("light.wohnbereich_lichter").state == "on"
|
|
return is_on, scenes
|
|
|
|
def essbereich_scenes():
|
|
scenes = [
|
|
scene_f("kuche_essbereich_orange"),
|
|
scene_f("kuche_essbereich_hell"),
|
|
scene_f("kuche_essbereich_blau_grun"),
|
|
scene_f("kuche_essbereich_grun"),
|
|
light_f("turn_off", "light.essbereich_lichter"),
|
|
]
|
|
is_on = lambda: hass.states.get("light.essbereich_lichter").state == "on"
|
|
return is_on, scenes
|
|
|
|
def wohnzimmer_scenes():
|
|
scenes = [
|
|
scene_f("wohnzimmer_orange"),
|
|
scene_f("wohnzimmer_hell"),
|
|
scene_f("wohnzimmer_dunkel"),
|
|
scene_f("wohnzimmer_blau_grun"),
|
|
scene_f("wohnzimmer_grun"),
|
|
light_f("turn_off", "light.wohnzimmer_lichter"),
|
|
]
|
|
is_on = lambda: hass.states.get("light.wohnzimmer_lichter").state == "on"
|
|
return is_on, scenes
|
|
|
|
def garten_vorne():
|
|
scenes = [
|
|
scene_f("garten_eingang_normal"),
|
|
scene_f("garten_eingang_hell"),
|
|
scene_f("garten_eingang_farbig"),
|
|
]
|
|
is_on = lambda: hass.states.get("light.lichter_garten_eingang").state == "on"
|
|
return is_on, scenes
|
|
|
|
def garten_sued():
|
|
scenes = [
|
|
scene_f("garten_sued_normal"),
|
|
scene_f("garten_sued_hell"),
|
|
scene_f("garten_sued_farbig"),
|
|
]
|
|
is_on = lambda: hass.states.get("light.garten_sud").state == "on"
|
|
return is_on, scenes
|
|
|
|
def garten_alles():
|
|
scenes = [
|
|
scene_f("garten_alles_normal"),
|
|
scene_f("garten_alles_hell"),
|
|
scene_f("garten_alles_farbig"),
|
|
]
|
|
is_on = lambda: hass.states.get("light.garten_sud").state == "on"
|
|
return is_on, scenes
|
|
|
|
# --------------------------------- HA App actions ---------------------------------------------------------------------
|
|
|
|
@event_trigger("ios.action_fired")
|
|
def on_ios_action_fired(actionName, **kwargs):
|
|
if actionName == "az_oben_licht":
|
|
scene_helper(az_oben_licht_scenes)
|
|
elif actionName == "kz_regal":
|
|
log.info("KZ Regal action fired")
|
|
scene_helper(kz_regal_scenes)
|
|
elif actionName == "az_unten_licht":
|
|
log.info("AZ unten Licht action fired")
|
|
scene_helper(az_unten_licht_scenes)
|
|
elif actionName == "wz_deckenlampe":
|
|
scene_helper(wz_deckenlampe)
|
|
elif actionName == "wohnbereich":
|
|
scene_helper(wohnbereich_scenes)
|
|
elif actionName == "wohnzimmer":
|
|
scene_helper(wohnzimmer_scenes)
|
|
elif actionName == "essbereich":
|
|
scene_helper(essbereich_scenes)
|
|
elif actionName == "schlafzimmer_bett_bringen":
|
|
cover.close_cover(entity_id="cover.schlafzimmer_rollo_gross")
|
|
cover.close_cover(entity_id="cover.schlafzimmer_rollo_klein")
|
|
script.timed_sleep(media_content_id="Good Night", light_off_mins=15, music_off_mins=45, shuffle=False)
|
|
elif actionName == "garten_vorne":
|
|
scene_helper(garten_vorne)
|
|
elif actionName == "garten_sued":
|
|
scene_helper(garten_sued)
|
|
elif actionName == "garten_alles":
|
|
scene_helper(garten_alles)
|
|
|
|
|
|
# --------------------------- Shortcut (room dependent) ---------------------------------------------------------------
|
|
|
|
@event_trigger("ios.shortcut_event")
|
|
def on_ios_shortcut_event(room, action, device, **kwargs):
|
|
if room == "unknown":
|
|
room = state.get("sensor.martins_apple_watch")
|
|
if room == "arbeitszimmer":
|
|
if action == "hass_ceiling_light":
|
|
light.toggle(entity_id="light.arbeitszimmer_deckenlampe")
|
|
elif action == "hass_light_off":
|
|
light.turn_off(entity_id="group.office")
|
|
elif action == "hass_light_darken":
|
|
dimmer.dim(entity_id="group.office", offset=-30)
|
|
elif action == "hass_light_brighten":
|
|
dimmer.dim(entity_id="group.office", offset=30)
|
|
elif action == "hass_light_orange":
|
|
scene.turn_on(entity_id="scene.arbeitszimmer_orange")
|
|
elif action == "hass_light_blue":
|
|
scene.turn_on(entity_id="scene.arbeitszimmer_blau_grun")
|
|
elif action == "hass_light_bright":
|
|
scene.turn_on(entity_id="scene.arbeitszimmer_hell")
|
|
elif action == "hass_cover_open":
|
|
cover.open_cover(entity_id="cover.arbeitszimmer_rollo")
|
|
elif action == "hass_cover_close":
|
|
cover.close_cover(entity_id="cover.arbeitszimmer_rollo")
|
|
elif action == "hass_cover_half":
|
|
cover_half.set_half(entity_id="cover.arbeitszimmer_rollo")
|
|
|
|
if room in ("küche", "esszimmer", "sofa", "wohnzimmer"):
|
|
if action == "hass_light_off":
|
|
light_f('turn_off', "group.living_area")()
|
|
elif action == "hass_light_orange":
|
|
scene_f("wohnbereich_orange")()
|
|
elif action == "hass_light_blue":
|
|
scene_f("wohnbereich_blau_grun")()
|
|
elif action == "hass_light_bright":
|
|
scene_f("wohnbereich_hell")()
|
|
elif action == "hass_light_darken":
|
|
dimmer.dim(entity_id="group.living_area", offset=-80)
|
|
elif action == "hass_light_brighten":
|
|
dimmer.dim(entity_id="group.living_area", offset=80)
|
|
elif action == "hass_light_off":
|
|
light.turn_off(entity_id="group.living_area")
|
|
elif action == "hass_cover_open":
|
|
cover.open_cover(entity_id="group.living_area")
|
|
elif action == "hass_cover_close":
|
|
cover.close_cover(entity_id="group.living_area")
|
|
elif action == "hass_cover_half":
|
|
cover_half.set_half(entity_id="group.living_area")
|
|
elif action == "hass_sun_blinds":
|
|
cover_half.set_half(entitiy_id="cover.wohnzimmer_fenster_rollo")
|
|
|
|
if room == "kinderzimmer":
|
|
if action == "hass_cover_open":
|
|
cover.open_cover(area_id="kinderzimmer")
|
|
elif action == "hass_cover_close":
|
|
cover.close_cover(area_id="kinderzimmer")
|
|
|
|
if room == "buero_oben":
|
|
if action == "hass_light":
|
|
scene_helper(az_oben_licht_scenes)
|
|
elif action == "hass_light_off":
|
|
light.turn_off(entity_id="light.arbeitszimmer_oben_fluter")
|
|
elif action == "hass_light_orange":
|
|
scene_f("arbeitszimmer_oben_orange")()
|
|
elif action == "hass_light_blue":
|
|
scene_f("arbeitszimmer_oben_blau")()
|
|
elif action == "hass_light_darken":
|
|
dimmer.dim(entity_id="light.arbeitszimmer_oben_fluter", offset=-80)
|
|
elif action == "hass_light_brighten":
|
|
dimmer.dim(entity_id="light.arbeitszimmer_oben_fluter", offset=80)
|
|
elif action == "hass_light_off":
|
|
light.turn_off(entity_id="light.arbeitszimmer_oben_fluter")
|
|
elif action == "hass_cover_open":
|
|
cover.open_cover(area_id="arbeitszimmeroben")
|
|
elif action == "hass_cover_close":
|
|
cover.close_cover(area_id="arbeitszimmeroben")
|