Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [Frage] zu Laufzeit erstellen State verarbeiten

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    [Frage] zu Laufzeit erstellen State verarbeiten

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

      Moin,

      gibt es eine Möglichkeit einen State der zur Laufzeit erstellt wurde im Skript abzufragen ?

      der 'Pfad' ist Teilweise vorher bekannt und würde in etwa javascript.0.Spotify.Devices.xxxx.Play lauten. xxxx ist nicht vorhersehbar !

      on({id:'javascript.0.Spotify.xxxx.Play',val:true}, function (obj){
        //bla bla 
        });
      

      würde ja nicht gehen…

      1 Reply Last reply Reply Quote 0
      • blauholsten
        blauholsten Developer last edited by

        @Lucky:

        Moin,

        gibt es eine Möglichkeit einen State der zur Laufzeit erstellt wurde im Skript abzufragen ?

        der 'Pfad' ist Teilweise vorher bekannt und würde in etwa javascript.0.Spotify.Devices.xxxx.Play lauten. xxxx ist nicht vorhersehbar !

        on({id:'javascript.0.Spotify.xxxx.Play',val:true}, function (obj){
          //bla bla 
          });
        

        würde ja nicht gehen… `
        Weis nicht ob ich dich richtig verstanden habe, aber…

        $('javascript.0.Spotify.*').on(function (obj){
          //bla bla 
          });
        

        geht vielleicht

        1 Reply Last reply Reply Quote 0
        • D
          dna909 last edited by

          @Lucky:

          Moin,

          gibt es eine Möglichkeit einen State der zur Laufzeit erstellt wurde im Skript abzufragen ?

          der 'Pfad' ist Teilweise vorher bekannt und würde in etwa javascript.0.Spotify.Devices.xxxx.Play lauten. xxxx ist nicht vorhersehbar !

          on({id:'javascript.0.Spotify.xxxx.Play',val:true}, function (obj){
            //bla bla 
            });
          

          würde ja nicht gehen… `

          Ich gehe mal davon aus, das xxxx irgendwann bekannt ist. Dann könntest Du, wenn der Wert von xxxx sich ändert, den State in einer Variable zusammenbauen.

          Dann fragst Du einfach die Variable ab:

          on({id: variable ,val:true}, function (obj){
            //bla bla 
            });
          

          Hoffe das ist verständlich 😉

          P.S.: eine Alternative wäre dann noch RegExp (siehe Beschreibung vom Javascript-Adapter).

          mfg dna909

          1 Reply Last reply Reply Quote 0
          • AlCalzone
            AlCalzone Developer last edited by

            @Lucky:

            xxxx ist nicht vorhersehbar ! `

            Wenn du zumindest ungefährt weißt, wie das aussehen wird, gehts mit RegExp:

            1. Fall: xxx sind Ziffern (0-9):

            on({id: /javascript\.0\.spotify\.\d+\.play/i, val:true}, [...])
            

            2. Fall: xxx sind Buchstaben/Ziffern/Unterstrich:

            on({id: /javascript\.0\.spotify\.\w+\.play/i, val:true}, [...])
            

            Andernfalls sag nochmal Bescheid, dann passen wir das Muster an.

            1 Reply Last reply Reply Quote 0
            • L
              Lucky last edited by

              die beiden Varianten funktionieren

                $('state[state.id=*.play]').on(function (obj) {
                console.log('GEDRÜCKT 3')
              });
              
                $('state[id=.play]').on(function (obj) {
                console.log('GEDRÜCKT 4')
              
              });
              

              allerdings nur wenn Role nicht als Button definiert ist, allerdings würde ich gerne bei Button bleiben, gibts da ne Möglichkeit ?

              1 Reply Last reply Reply Quote 0
              • AlCalzone
                AlCalzone Developer last edited by

                Meine Variante funktioniert nicht?

                1 Reply Last reply Reply Quote 0
                • L
                  Lucky last edited by

                  nein, leider nicht ..

                  1 Reply Last reply Reply Quote 0
                  • L
                    Lucky last edited by

                    on({id: /\.play$/, val:true},function (obj){
                     console.log('GEDRÜCKT 5')
                      });
                    
                    

                    funktioniert !

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

                      Und diese Variante ?

                      on({id: /^javascript\.0\.Spotify\..+\.play$/}, function (obj){
                        log('gedrückt: ' + obj.id);
                      });
                      
                      1 Reply Last reply Reply Quote 0
                      • AlCalzone
                        AlCalzone Developer last edited by

                        @Lucky:

                        on({id: /\.play$/, val:true},function (obj){
                         console.log('GEDRÜCKT 5')
                          });
                        
                        

                        funktioniert ! `
                        Hat aber den Nachteil, dass ALLE States gefunden werden, die auf ".play" enden, nicht nur die in javascript.0.Spotify. Probier mal Pauls Variante

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

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        804
                        Online

                        31.7k
                        Users

                        79.8k
                        Topics

                        1.3m
                        Posts

                        5
                        10
                        784
                        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