Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Bei Druck eines Tasters Toggeln

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Bei Druck eines Tasters Toggeln

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

      Hallo,

      ich verzweifle gerade mal wieder an Javascript 😞

      Ich versuche mir ein Script zu stricken, das beim betätigen eines Tasters den Schaltzustand eines Zwischensteckers auf true oder false prüft und dann den jeweiligen anderen Zustand schaltet.

      on("hm-rpc.0.JEQ0696242.3.PRESS_SHORT", function(obj) {
          if(obj.newState.val ===false) {setState("hm-rpc.0.JEQ0697674.1.STATE" ,true);}
          else {setState("hm-rpc.0.JEQ0697674.1.STATE" ,false);}
      });
      

      Wo liegt nur der Fehler?

      Kann mir jemand helfen?

      1 Reply Last reply Reply Quote 0
      • paul53
        paul53 last edited by

        Versuche es mal so:

        on({id: "hm-rpc.0.JEQ0696242.3.PRESS_SHORT", val: true}, function() {
            if(getState("hm-rpc.0.JEQ0697674.1.STATE").val) {setState("hm-rpc.0.JEQ0697674.1.STATE" ,false);}
            else {setState("hm-rpc.0.JEQ0697674.1.STATE" ,true);}
        });
        
        1 Reply Last reply Reply Quote 0
        • T
          Tom last edited by

          Funktioniert bestens 😄

          Vielen Dank für Deine Unterstützung!

          1 Reply Last reply Reply Quote 0
          • P
            pix last edited by

            Man kann es noch weiter abkürzen mit der Kurzschreibweise:

            on({id: "hm-rpc.0.JEQ0696242.3.PRESS_SHORT", val: true}, function() {
                x = (getState("hm-rpc.0.JEQ0697674.1.STATE").val === true) ? false : true;
                setState("hm-rpc.0.JEQ0697674.1.STATE", x);
            });
            
            ````Lohnt sich hier aber kaum :lol:
            
            Gruß,
            
            Pix
            1 Reply Last reply Reply Quote 0
            • paul53
              paul53 last edited by

              Es müsste noch kürzer ebenfalls funktionieren:

              on({id: "hm-rpc.0.JEQ0696242.3.PRESS_SHORT", val: true}, function() {
                  setState("hm-rpc.0.JEQ0697674.1.STATE", !getState("hm-rpc.0.JEQ0697674.1.STATE").val);
              });
              
              1 Reply Last reply Reply Quote 0
              • P
                pix last edited by

                Das kannte ich noch gar nicht. Steht das ! fürs Umkehren des Wertes? Wieder was gelernt, das probiere ich morgen mal aus.

                Danke,

                Pix

                Gesendet mit Tapatalk

                1 Reply Last reply Reply Quote 0
                • paul53
                  paul53 last edited by

                  @pix:

                  Steht das ! fürs Umkehren des Wertes? `
                  Ja, ! vor einem Wert (boolean) bedeutet https://wiki.selfhtml.org/wiki/JavaScript/Operatoren/Logische_Operatoren.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post

                  Support us

                  ioBroker
                  Community Adapters
                  Donate

                  412
                  Online

                  31.9k
                  Users

                  80.2k
                  Topics

                  1.3m
                  Posts

                  3
                  7
                  1293
                  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