Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [Gelöst] Trigger auf state change innerhalb einer gruppe mit rueckgabe der id

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    [Gelöst] Trigger auf state change innerhalb einer gruppe mit rueckgabe der id

    This topic has been deleted. Only users with topic management privileges can see it.
    • Dutchman
      Dutchman Developer Most Active Administrators last edited by

      Hi,

      Ich habe merere werte die ein script ausloesen sollen, einzeln programmiert geht ja:

          on({id: "javascript.0.domoticz.1.STATE", change: "ne"}, function (obj) {
        var URL = 'http://192.168.1.152';
        var port = '8080';
        var value = obj.state.val;
        var device = '1';
      
      

      2 Loesugsfragen:

      1:

      Die variabele "device" ist jetzt fest gesetzt sollte aber javascript.0.domoticz. * .State darstellen

      979_values.jpg

      2:

      Das script loest nur bei javascript.0.domoticz.1 aus sollte aber bei javascript.0.domoticz. * .State triggeren wobei ich fuer * den wert als device zurueck bekommen mus

      thanks !

      Dutch

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

        Dann suche mal nach RegExp.

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

          @Dutchman:

          2:

          Das script loest nur bei javascript.0.domoticz.1 aus sollte aber bei javascript.0.domoticz. * .State triggeren wobei ich fuer * den wert als device zurueck bekommen mus `

          probier mal:

          on({id: /^javascript\.\d\.domoticz\.\d+\.STATE$/ , change: "ne"}, function (obj) {
            var value = obj.state.val;
            var objArr  = obj.id.match(/(^.+)\.(.+)\.(.+)$/, ""); //Aufteilung in Pfad + Device + CMD
            var device  = objArr[2]; 
            log("device: " + device +" - State: " + value);
          });
          
          
          1 Reply Last reply Reply Quote 0
          • Dutchman
            Dutchman Developer Most Active Administrators last edited by

            @paul53:

            Dann suche mal nach RegExp. `

            danke das haetten wir:

            
            //    on({id: /\.STATE$/, change: "ne"}, function (obj) {
                on({id: /javascript\.0\.domoticz\..*\.STATE/, change: "ne"}, function (obj) {
            
            	var device = obj.id;
             	log(device);
            
            });
            
            

            jetzt fehlt mir nur ruckgabe der ID dabei noch nen tip ? Ich brauche die zahl

            javascript.0.domoticz.1.STATE

            1 Reply Last reply Reply Quote 0
            • Dutchman
              Dutchman Developer Most Active Administrators last edited by

              @ruhr70:

              probier mal:

              on({id: /^javascript\.\d\.domoticz\.\d+\.STATE$/ , change: "ne"}, function (obj) {
                var value = obj.state.val;
                var objArr  = obj.id.match(/(^.+)\.(.+)\.(.+)$/, ""); //Aufteilung in Pfad + Device + CMD
                var device  = objArr[2]; 
                log("device: " + device +" - State: " + value);
              });
              
              ```` `  
              

              Super danke das hat geklappt !

              Falls es jemand gebrauchen kan, script reagiert auf trigger innerhalb der gruppe und abhaenging von status verschikt er ein commando per URL:

              //    on({id: /javascript\.0\.domoticz\..*\.STATE/, change: "ne"}, function (obj) {
              
              on({id: /^javascript\.\d\.domoticz\.\d+\.STATE$/ , change: "ne"}, function (obj) {
                var value = obj.state.val;
                var objArr  = obj.id.match(/(^.+)\.(.+)\.(.+)$/, ""); //Aufteilung in Pfad + Device + CMD
                var device  = objArr[2]; 
                log("device: " + device +" - State: " + value);
                log(device);
              
                var URL = 'http://192.168.1.152';
                var port = '8080';
              
                if (getState("javascript.0.domoticz." + device + ".STATE").val == '1') {
                  try {
                    require("request")( URL + ':' + port + '/json.htm?type=command¶m=switchlight&idx=' + device + '&switchcmd=On');
                  } catch (e) { console.error(e); }
                  console.log("request: " + URL + ':' + port + '/json.htm?type=command¶m=switchlight&idx=' + device + '&switchcmd=On');
                } else {
                  try {
                    require("request")(URL + ':' + port + '/json.htm?type=command¶m=switchlight&idx=' + device + '&switchcmd=Off');
                  } catch (e) { console.error(e); }
                  console.log("request: " + URL + ':' + port + '/json.htm?type=command¶m=switchlight&idx=' + device + '&switchcmd=Off');
                }
              });
              
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post

              Support us

              ioBroker
              Community Adapters
              Donate

              819
              Online

              31.7k
              Users

              79.8k
              Topics

              1.3m
              Posts

              3
              5
              1366
              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