action mit condition

Bereich rings rum zum Thema Yaml und seine Tücken.


Antworten
mondface
Beiträge: 167
Registriert: Di 10. Mai 2022, 23:06
1
Has thanked: 112 times
Been thanked: 12 times

action mit condition

Beitrag 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

Benutzeravatar
Osorkon
Administrator
Beiträge: 1953
Registriert: Sa 17. Jul 2021, 16:53
2
Wohnort: Langenargen
Has thanked: 61 times
Been thanked: 530 times
Kontaktdaten:

Re: action mit condition

Beitrag 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

Einer muss ja für Ordnung sorgen. :D
mondface
Beiträge: 167
Registriert: Di 10. Mai 2022, 23:06
1
Has thanked: 112 times
Been thanked: 12 times

Re: action mit condition

Beitrag von mondface »

Danke!

Benutzeravatar
Osorkon
Administrator
Beiträge: 1953
Registriert: Sa 17. Jul 2021, 16:53
2
Wohnort: Langenargen
Has thanked: 61 times
Been thanked: 530 times
Kontaktdaten:

Re: action mit condition

Beitrag 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

Einer muss ja für Ordnung sorgen. :D
mondface
Beiträge: 167
Registriert: Di 10. Mai 2022, 23:06
1
Has thanked: 112 times
Been thanked: 12 times

Re: action mit condition

Beitrag von mondface »

Dankeschön ☺️

Antworten