Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Ein- Ausschalten per Script

    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

    Ein- Ausschalten per Script

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

      Hallo,

      ich versuche über einen virtuellen Schalter eine Sonoff Steckdose zu schalten.
      Leider bekomme ich es nur mit STATE True oder STATE False hin. Das hilft mir aber nicht weiter weil ich ja AN und AUSSCHALTEN möchte. Mit SWITCH geht es leider nicht.

      on({id: 'hm-rpc.2.CUX2801001.9.PRESS_SHORT', change: "any"}, function (obj) {
      setState("hm-rpc.2.CUX2801002.1.STATE", true);
      });
      
      

      Geht es nur über eine Schleife (if) oder gibt es eine einfachere Lösung?
      Vielen Dank im Voraus für eure Unterstützung.

      F paul53 2 Replies Last reply Reply Quote 0
      • F
        fastfoot @Andre Liebgott last edited by

        @Andre-Liebgott sagte in Ein- Ausschalten per Script:

        Geht es nur über eine Schleife (if) oder gibt es eine einfachere Lösung?
        Vielen Dank im Voraus für eure Unterstützung.

        in Blockly wird das Umschalten so gelöst

        getState("Object ID", function (err, state) {
            setState("Object ID", state ? !state.val : true);
        });
        
        1 Reply Last reply Reply Quote 0
        • paul53
          paul53 @Andre Liebgott last edited by paul53

          @Andre-Liebgott sagte:

          AN und AUSSCHALTEN möchte.

          Also toggle ? Vorschlag:

          var state = getState('hm-rpc.2.CUX2801002.1.STATE').val;
          on({id: 'hm-rpc.2.CUX2801001.9.PRESS_SHORT'}, function ()  {
             state = !state;
             setState("hm-rpc.2.CUX2801002.1.STATE", state);
          });
          

          oder

          on({id: 'hm-rpc.2.CUX2801001.9.PRESS_SHORT'}, function ()  {
             setState("hm-rpc.2.CUX2801002.1.STATE", !getState('hm-rpc.2.CUX2801002.1.STATE').val);
          });
          
          Andre Liebgott 1 Reply Last reply Reply Quote 0
          • Andre Liebgott
            Andre Liebgott @paul53 last edited by

            @paul53 DANKESCHÖN, du hast mir sehr geholfen. Vielen Dank!

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

            Support us

            ioBroker
            Community Adapters
            Donate

            826
            Online

            31.8k
            Users

            80.0k
            Topics

            1.3m
            Posts

            3
            4
            228
            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