162 lines
5.5 KiB
Python
162 lines
5.5 KiB
Python
import json
|
|
|
|
@pyscript_compile
|
|
def in_room(room):
|
|
return f"entity_id.startswith('switch.{room}_szene_')"
|
|
|
|
def vacuum(*rooms):
|
|
room_map = {
|
|
"Eingang" : "16",
|
|
"Wohnzimmer" : "17",
|
|
"Küche" : "18",
|
|
"Gang hinten" : "19",
|
|
"Esszimmer" : "20",
|
|
"Gang vorne" : "21",
|
|
"WC" : "22",
|
|
"Arbeitszimmer" : "24",
|
|
"Waschraum" : "25",
|
|
"Vorratsraum" : "26",
|
|
"Bad" : "27",
|
|
"Schlafzimmer" : "28",
|
|
"Kinderzimmer" : "29",
|
|
}
|
|
rooms = [room_map[name] for name in rooms]
|
|
topic = "valetudo/NewJuniorKingfisher/MapSegmentationCapability/clean/set"
|
|
payload = json.dumps({"segment_ids": rooms, "customOrder": True, "iterations" : 1})
|
|
mqtt.publish(topic=topic, payload=payload)
|
|
|
|
|
|
@event_trigger("short_click", in_room("eingang"))
|
|
@event_trigger("long_click", in_room("eingang"))
|
|
def eingang(entity_id=None, event_type=None):
|
|
long_click = (event_type == "long_click")
|
|
key = {'switch.eingang_szene_2': 'bulb_orange',
|
|
'switch.eingang_szene_3': 'bulb_black',
|
|
'switch.eingang_szene_4': 'key',
|
|
'switch.eingang_szene_5': 'dog'}[entity_id]
|
|
|
|
long_click = (event_type == "long_click")
|
|
|
|
if key == "bulb_orange":
|
|
light.gang_licht.turn_on()
|
|
light.gang_einganglicht.turn_on()
|
|
if long_click:
|
|
scene.wohnbereich_hell.turn_on()
|
|
elif key == "bulb_black":
|
|
if long_click:
|
|
light.turn_off(entity_id="group.all_downstairs")
|
|
else:
|
|
light.turn_off(entity_id="group.all_downstairs_but_outside")
|
|
elif key == "dog":
|
|
if long_click:
|
|
vacuum("Gang hinten", "Gang vorne", "Eingang", "Küche", "Esszimmer", "Wohnzimmer")
|
|
else:
|
|
vacuum("Eingang")
|
|
|
|
|
|
@event_trigger("short_click", in_room("esszimmer"))
|
|
@event_trigger("long_click", in_room("esszimmer"))
|
|
def esszimmer_gangtuer(entity_id=None, event_type=None):
|
|
key = {'switch.esszimmer_szene_0': 'arrow_down',
|
|
'switch.esszimmer_szene_1': 'arrow_up',
|
|
'switch.esszimmer_szene_2': 'bulb_orange',
|
|
'switch.esszimmer_szene_3': 'bulb_yellow',
|
|
'switch.esszimmer_szene_4': 'cooking_pot', # Herd an/aus in separater Datei
|
|
'switch.esszimmer_szene_5': 'bulb_black'}[entity_id]
|
|
long_click = (event_type == "long_click")
|
|
|
|
if long_click:
|
|
covers = ['cover.kuche_fenster_rollo', 'cover.esszimmer_fenster_rollo']
|
|
else:
|
|
covers = ['group.living_area']
|
|
|
|
if key == "arrow_down":
|
|
if long_click:
|
|
vacuum("Esszimmer")
|
|
else:
|
|
cover_half.set_half(entity_id=covers)
|
|
elif key == "arrow_up":
|
|
if long_click:
|
|
vacuum("Küche")
|
|
else:
|
|
cover.open_cover(entity_id=covers)
|
|
elif key == "bulb_orange":
|
|
if long_click:
|
|
scene.kuche_essbereich_orange.turn_on()
|
|
else:
|
|
scene.wohnbereich_orange.turn_on()
|
|
elif key == "bulb_yellow":
|
|
if long_click:
|
|
scene.kuche_essbereich_hell.turn_on()
|
|
else:
|
|
scene.wohnbereich_hell.turn_on()
|
|
elif key == "bulb_black":
|
|
if long_click:
|
|
light.essbereich_lichter.turn_off()
|
|
else:
|
|
light.turn_off(entity_id="group.living_area")
|
|
|
|
|
|
@event_trigger("short_click", in_room("wohnzimmer"))
|
|
@event_trigger("long_click", in_room("wohnzimmer"))
|
|
def wohnzimmer_gangtur(entity_id=None, event_type=None):
|
|
long_click = (event_type == "long_click")
|
|
key = {'switch.wohnzimmer_szene_0': 'arrow_down',
|
|
'switch.wohnzimmer_szene_1': 'arrow_up',
|
|
'switch.wohnzimmer_szene_2': 'bulb_orange',
|
|
'switch.wohnzimmer_szene_3': 'bulb_yellow',
|
|
'switch.wohnzimmer_szene_4': 'bulb_blue',
|
|
'switch.wohnzimmer_szene_5': 'bulb_black'}[entity_id]
|
|
|
|
if long_click:
|
|
covers = ['cover.wohnzimmer_fenster_rollo', 'cover.wohnzimmer_terrassentur_rollo']
|
|
else:
|
|
covers = ['group.living_area']
|
|
|
|
if key == "arrow_down":
|
|
if long_click:
|
|
vacuum("Wohnzimmer")
|
|
else:
|
|
cover_half.set_half(entity_id=covers)
|
|
elif key == "arrow_up":
|
|
if long_click:
|
|
vacuum("Wohnzimmer")
|
|
else:
|
|
cover.open_cover(entity_id=covers)
|
|
elif key == "bulb_orange":
|
|
if long_click:
|
|
scene.wohnzimmer_orange.turn_on()
|
|
else:
|
|
scene.wohnbereich_orange.turn_on()
|
|
elif key == "bulb_yellow":
|
|
if long_click:
|
|
scene.wohnzimmer_hell.turn_on()
|
|
else:
|
|
scene.wohnbereich_hell.turn_on()
|
|
elif key == "bulb_blue":
|
|
if long_click:
|
|
scene.wohnzimmer_dunkel.turn_on()
|
|
else:
|
|
scene.wohnbereich_blau_grun.turn_on()
|
|
elif key == "bulb_black":
|
|
if long_click:
|
|
light.wohnzimmer_lichter.turn_off()
|
|
else:
|
|
light.turn_off(entity_id="group.living_area")
|
|
|
|
|
|
@event_trigger("short_click", in_room("wohnzimmer_terrassentur"))
|
|
@event_trigger("long_click", in_room("wohnzimmer_terrassentur"))
|
|
def wohnzimmer_terassentuer(entity_id=None, event_type=None):
|
|
long_click = (event_type == "long_click")
|
|
key = {'switch.wohnzimmer_terrassentur_szene_2': 'teddy',
|
|
'switch.wohnzimmer_terrassentur_szene_3': 'flowers'}[entity_id]
|
|
if key == "teddy":
|
|
if long_click:
|
|
scene.wohnbereich_kuscheln.turn_on()
|
|
elif key == "flowers":
|
|
if long_click:
|
|
light.turn_off(entity_id="light.garten_lichter")
|
|
else:
|
|
scene.garten_savanna.turn_on()
|