Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. [ESPHome] Syntaxfrage: mehrere if conditions

    NEWS

    • Monatsrückblick - April 2025

    • Minor js-controller 7.0.7 Update in latest repo

    • Save The Date: ioBroker@Smart Living Forum Solingen, 14.06.

    [ESPHome] Syntaxfrage: mehrere if conditions

    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      WolfgangFB last edited by

      Ich möchte nach einem Ereignis (z.B. ein Sensort löst aus) mehrer Aktionen ion Abhängigkeit von anderen Größen ausführen. Also in der Art:

      switch:
        - platform: gpio
          pin:
            number: D5
            mode: OUTPUT
            inverted: true
          name: "D5"
          id: GPIOD5
          on_turn_off:
            if: 
              condition:
                lambda: return id(GlobaleVariable ==3);
              then:
              - switch.turn_on: LED1
            if:
              condition:
                lambda: return id(GlobaleVariable== 4);
              then:
              - switch.tun_off: LED2
      
      

      Es wird aber moniert, dass das Keyword "if" doppel vorhanden ist.
      Wie macht man sowas? (Einfach das zweite "if" weglassen geht auch nicht, dann wird das doppelte "condition" moniert)

      T 1 Reply Last reply Reply Quote 0
      • T
        ticaki Developer @WolfgangFB last edited by

        @wolfgangfb
        https://community.home-assistant.io/t/noob-question-chained-conditions-if-elseif/316585

        Sieht so aus, als wenn da ein then: hinter on_turn_off: gehört.

        Hab nur aus Neugier gesucht 🙂

        W 1 Reply Last reply Reply Quote 0
        • W
          WolfgangFB @ticaki last edited by

          @ticaki
          Hi

          Ne, wenn nur eine Bedingung erfüllt sein soll ist

              on_turn_off:
                if: 
                  condition:
                    lambda: return id(GlobaleVariable ==3);
                  then:
                  - switch.turn_on: LED1
          

          korrekt und funktioniert. Die Frage ist, wie ich die zweite Bedingung einbaue. Auch wenn ich hinter on_turn_off ein "then:" einfüge wird trotzdem dsas zweite "if" als "duplicate key" moniert.

          W 1 Reply Last reply Reply Quote 0
          • W
            WolfgangFB @WolfgangFB last edited by

            @wolfgangfb
            Die einzige was ich gefunden habe, ist alles in ein lambda zu packen und die Aktoren über die C++ Syntax zu setzen, also in der Art:

                on_press:
                  then:
                  - lambda: |
                      if (id(Hauszustand) == 0){id(LED).turn_on();}
                      if (id(Hauszustand) == 1){id(LED_Rot).turn_on();}
                     ....
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Support us

            ioBroker
            Community Adapters
            Donate
            FAQ Cloud / IOT
            HowTo: Node.js-Update
            HowTo: Backup/Restore
            Downloads
            BLOG

            962
            Online

            31.6k
            Users

            79.4k
            Topics

            1.3m
            Posts

            2
            4
            937
            Loading More Posts
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes
            Reply
            • Reply as topic
            Log in to reply
            Community
            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
            The ioBroker Community 2014-2023
            logo