Seite 1 von 1
action mit condition
Verfasst: Fr 4. Aug 2023, 12:30
von mondface
Hallo,
wie sieht der yaml code aus,
wenn ich etwas ausführen möchte, wenn die Bedingung stimmt?
Also in etwa:
trigger: Tür 1 auf
actions:
wenn helligkeit > 100 lux, dann schalter 1 ein
wenn helligkeit < 100 lux, dann schalter 2 ein
wenn helligkeit 0 lux, dann schalter 3 ein
Re: action mit condition
Verfasst: Fr 4. Aug 2023, 13:38
von Osorkon
Eine von vielen Möglichkeiten unter Verwendung von Auswahl:
Code: Alles auswählen
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.tuer
from: "off"
to: "on"
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.helligkeit
below: 1
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.1
- conditions:
- condition: numeric_state
entity_id: sensor.helligkeit
below: 100
- condition: numeric_state
entity_id: sensor.helligkeit
above: 0
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.2
- conditions:
- condition: numeric_state
entity_id: sensor.helligkeit
above: 99
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.3
mode: single
Gruß
Osorkon
Re: action mit condition
Verfasst: Fr 4. Aug 2023, 14:48
von mondface
Re: action mit condition
Verfasst: Fr 4. Aug 2023, 18:19
von Osorkon
Da war noch ein kleiner Fehler drin, die letze Bedingung muss lauten Über 99 anstatt über 100.
Sonst wird beim Helligkeitswert 100 keine Aktion ausgeführt. Habe es bereits oben korrigiert.
Einen Weitere Möglichkeit wäre die Wenn Dann Aktion.
Code: Alles auswählen
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.tuer
from: "off"
to: "on"
condition: []
action:
- if:
- condition: numeric_state
entity_id: sensor.helligkeit
below: 1
then:
- service: light.turn_on
data: {}
target:
entity_id: light.1
- if:
- condition: numeric_state
entity_id: sensor.helligkeit
above: 0
below: 100
then:
- service: light.turn_on
data: {}
target:
entity_id: light.2
- if:
- condition: numeric_state
entity_id: sensor.helligkeit
above: 99
then:
- service: light.turn_on
data: {}
target:
entity_id: light.3
mode: single
Gruß
Osorkon
Re: action mit condition
Verfasst: Sa 5. Aug 2023, 08:41
von mondface
Dankeschön 