Seite 1 von 1

Automatisierungen konsolidieren

Verfasst: Mi 7. Sep 2022, 14:55
von Snowrisk

Hallo,

ich habe 2 Scripte, um eine Gruppe von Lampen ein- bzw. auszuschalten.

2 Scripte, da ich zum einen 2 Taster nutze (frühere Wechselschaltung) und zum anderen zum
Einschalten eine andere Taste nutze, als zum Ausschalten. "Umschalten" als Aktion geht da nicht.
Hier mal die Scripte:

Einschalten:

Code: Alles auswählen

alias: Licht Schlafzimmer ein
description: ""
trigger:
  - platform: device
    domain: homematicip_local
    device_id: bec34fed0219fc4e6f9ddb57ec6a140d
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: ******
    type: press_short
    subtype: 1
  - platform: device
    domain: homematicip_local
    device_id: fec9d489860ac1e285679c80585ca9e6
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: *******
    type: press_short
    subtype: 1
condition: []
action:
  - service: homeassistant.turn_on
    data: {}
    target:
      entity_id: light.licht_schlafzimmer
mode: single

Ausschalten:

Code: Alles auswählen

alias: Licht Schlafzimmer aus
description: ""
trigger:
  - platform: device
    domain: homematicip_local
    device_id: bec34fed0219fc4e6f9ddb57ec6a140d
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: ******
    type: press_short
    subtype: 2
  - platform: device
    domain: homematicip_local
    device_id: fec9d489860ac1e285679c80585ca9e6
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: *******
    type: press_short
    subtype: 2
condition: []
action:
  - service: homeassistant.turn_off
    data: {}
    target:
      entity_id: light.licht_schlafzimmer
mode: single

Kann man das in ein Script packen? Ich bekomme das nicht hin bzw. denke wohl wieder zu kompliziert :mrgreen:

VG
Jens


Re: Automatisierungen konsolidieren

Verfasst: Sa 10. Sep 2022, 12:04
von Osorkon

@Snowrisk Du meinst bestimmt Automatisierungen und nicht Skripte. 😉

Um Deine 2 einzelnen Automatisierungen zu einer zusammenzuführen, musst Du jedem Trigger eine trigger-id vergeben.
Auslöser zum Einschalten -> trigger_id : "on"
Auslöser zum Ausschalten -> trigger_id : "off"

Aktion Auswahl und die einzelnen Optionen in Abhängigkeit der Trigger-Id, können wir uns sparen und verwenden die Trigger-Id als variable.

Code: Alles auswählen

- service: light.turn_{{ trigger.id }}

Das heisst, die Trigger Id bestimmt ob light.turn_on oder light.turn_off ausgeführt wird

Code: Alles auswählen

alias: Licht Schlafzimmer ein_aus
description: ""
trigger:
  - platform: device
    domain: homematicip_local
    device_id: bec34fed0219fc4e6f9ddb57ec6a140d
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: ******
    type: press_short
    subtype: 1
    id: "on"
  - platform: device
    domain: homematicip_local
    device_id: fec9d489860ac1e285679c80585ca9e6
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: *******
    type: press_short
    subtype: 1
    id: "on"
  - platform: device
    domain: homematicip_local
    device_id: bec34fed0219fc4e6f9ddb57ec6a140d
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: ******
    type: press_short
    subtype: 2
    id: "off"
  - platform: device
    domain: homematicip_local
    device_id: fec9d489860ac1e285679c80585ca9e6
    event_type: homematic.keypress
    interface_id: raspberrymatic-HmIP-RF
    address: *******
    type: press_short
    subtype: 2
    id: "off"
condition: []
action:
  - service: light.turn_{{ trigger.id }}
    data: {}
    target:
      entity_id: light.licht_schlafzimmer
mode: single

Gruß
Osorkon


Re: Automatisierungen konsolidieren

Verfasst: Mo 12. Sep 2022, 13:41
von Snowrisk

@Osorkon

Klar, Automatisierungen ;)

Danke. Ich habe es verstanden und umgesetzt. Klappt natürlich einwandfrei :D

VG
Jens