Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Gelöst: Reaktion auf Änderung eines Zustandes

    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

    Gelöst: Reaktion auf Änderung eines Zustandes

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

      Hallöchen
      ich möchte auf die Änderung des Zustandes eines Datenpunktens rasch reagieren.
      z.Zt nutze ich folgende Variante:


      const idHue = 'hue.0.Philips_hue.Keller.scene_entspannen';
      const idHueOn = 'hue.0.Philips_hue.Keller.on';
      const idMotion = 'hm-rpc.0.KEQ0972283.1.MOTION';
      const idSonosOn = 'sonos.0.root.192_168_178_49.state_simple';

      var sonosState = getState(idSonosOn).val;
      log("Bewegung erkannt: " + getState(idMotion).val);
      log("Sonos State: " + getState(idSonosOn).val);
      schedule("* * * * *", function () {
      if (sonosState == true){setState(idHue, true);
      } else if
      (sonosState == false){setState(idHueOn, false);
      };
      });


      Reagieren möchte ich auf die Zustandsänderung von sonosState.
      on({id: sonosState.... hat irgendwie nicht reagiert.
      Gruß
      Michael

      Peoples paul53 2 Replies Last reply Reply Quote 0
      • Peoples
        Peoples @michihorn last edited by Peoples

        Ich mache das so

        on({id:"javascript.0.Photovoltaik.Eigenverbrauch_PV", change: 'any'}, function (db){
            calc_PercentageOwnConsumption(); 
        });
        

        Wenn du also:

        const idHue = 'hue.0.Philips_hue.Keller.scene_entspannen';
        const idHueOn = 'hue.0.Philips_hue.Keller.on';
        const idMotion = 'hm-rpc.0.KEQ0972283.1.MOTION';
        const idSonosOn = 'sonos.0.root.192_168_178_49.state_simple';
        
        var sonosState = getState(idSonosOn).val;
        
        on({id:"sonos.0.root.192_168_178_49.state_simple", change: 'any'}, function (db){
            if(db.state.val === true){
                setState(idHue, true)
            }
           else{
                  setState(idHueOn, false);
           }
        });
        

        machst geht es nicht?

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

          @michihorn sagte in Reaktion auf Änderung eines Zustandes:

          on({id: sonosState.... hat irgendwie nicht reagiert.

          sonosState ist keine ID, sondern der Wert des Datenpunktes. Richtig:

          on({id: sonosOn, ....
          
          M 1 Reply Last reply Reply Quote 0
          • M
            michihorn last edited by

            Doch...Mercy klappt

            1 Reply Last reply Reply Quote 0
            • M
              michihorn @paul53 last edited by

              @paul53 Ja

              1 Reply Last reply Reply Quote 0
              • M
                michihorn last edited by michihorn

                Für alle Anfänger bei den Scripten, es gibt WebSites die überprüfen den Code, geben zumindest gute Hinweis auf Fehlerquellen, damit übe ich gerne:
                Link Text
                oder
                Link Text
                Natürlich bin ich sehr dankbar für die Unterstützung der Fachleute hier im Forum.
                Gruß Michael

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

                  Der Javascript Adapter gibt mittlerweile auch schon wirklich gute Infos

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

                  Support us

                  ioBroker
                  Community Adapters
                  Donate

                  633
                  Online

                  31.9k
                  Users

                  80.2k
                  Topics

                  1.3m
                  Posts

                  javascript
                  3
                  7
                  264
                  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