Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [gelöst] Check DP schon vorhanden

    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] Check DP schon vorhanden

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

      Hallo zusammen, ich bin eher mit Blockly unterwegs und benötige daher Hilfe.

      Meine DPs und Alias erstelle ich per Javascript.

      Wie prüft man, ob ein DP, der erstellt werden soll, schon existiert?

      Vielen Dank schon einmal

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

        @kuddel sagte: Wie prüft man, ob ein DP, der erstellt werden soll, schon existiert?

        if(existsState(id))  
        
        K 1 Reply Last reply Reply Quote 0
        • K
          Kuddel @paul53 last edited by

          @paul53 geht auch if not ?

          Wäre das dann if(!(existsState)(id)) ?

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

            @kuddel sagte: Wäre das dann if(!(existsState)(id)) ?

            Prüfung auf "nicht vorhanden":

            if(!existsState(id))
            
            K 1 Reply Last reply Reply Quote 0
            • K
              Kuddel @paul53 last edited by

              @paul53 super, vielen Dank

              Wszene 1 Reply Last reply Reply Quote 0
              • Wszene
                Wszene @Kuddel last edited by

                @kuddel

                Hallo
                Kannst du mir dein Script zur Verfügung stellen?

                K 1 Reply Last reply Reply Quote 0
                • K
                  Kuddel @Wszene last edited by

                  @wszene so sieht es aktuell mit der Einrichtung von DPs aus (achtung, noch ungetestet)

                  let objekte = [
                      //3D-Drucker
                      //  Job
                      {"pfad": "0_userdata.0.3d_drucker.Job", "name": "Jobname", "type": "string", "value": "", "unit": ""},
                      {"pfad": "0_userdata.0.3d_drucker.Job", "name": "Jobname_VIS", "type": "string", "value": "", "unit": ""},
                      //  Farben
                      {"pfad": "0_userdata.0.3d_drucker.LED-Steeurung", "name": "Anschalten", "type": "boolean", "value": "false", "unit": ""},
                      {"pfad": "0_userdata.0.3d_drucker.LED-Steeurung", "name": "Farbe_Gelb", "type": "boolean", "value": "false", "unit": ""},
                      {"pfad": "0_userdata.0.3d_drucker.LED-Steeurung", "name": "Farbe_Gruen", "type": "boolean", "value": "false", "unit": ""},
                      {"pfad": "0_userdata.0.3d_drucker.LED-Steeurung", "name": "Farbe_Weiss", "type": "boolean", "value": "false", "unit": ""},
                  ];
                  
                  //Jeden DP erstellen, wenn noch nicht vorhanden
                  objekte.forEach(objekt => {
                  
                      //Pfad zusammenbauen
                      var id = 'objekt.pfad' + '.' + 'objekt.name';
                      
                      //DP erstellen, wenn noch nicht vorhanden
                      if(!existsState('id')){createState('id', objekt.value, {type: objekt.type ,name: objekt.name, unit: objekt.unit});}
                      else{console.log('Datenpunkt ' + 'id' + 'ist schon vorhanden');}
                  
                  
                  });
                  
                  
                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post

                  Support us

                  ioBroker
                  Community Adapters
                  Donate

                  728
                  Online

                  31.9k
                  Users

                  80.1k
                  Topics

                  1.3m
                  Posts

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