Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Fragen zu createState.

    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

    Fragen zu createState.

    This topic has been deleted. Only users with topic management privileges can see it.
    • paul53
      paul53 @ChristianG last edited by paul53

      @ChristianG sagte:

      Kannst du mir einen Link schicken.

      Siehe unter Attribute für bestimmte Objekttypen / Datenpunkt.

      @ChristianG sagte in Fragen zu createState.:

      ein Beispiel

      Beispiel. Damals gab es die Funktion existsState(id) noch nicht.

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

        @paul53 sagte in Fragen zu createState.:

        setTimeout

        setObject akzeptiert einen Callback:
        https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#setobject
        Damit müsste man sofort nach dem Erstellen den Wert schreiben können, ohne künstlich länger zu warten.

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

          @paul53

          Danke für die Hilfe aber ich gebe auf ... habe nicht so wirklich den Plan von dem was ich da mache und die Punkte werden einfach nicht angelegt. Werde dann außerhalb von ioBroker die API nutzen und in meine Oberfläche einbauen.

          Hier für alle die doch noch versuchen wollen es ans laufen zu bekommen:

          function createOrUpdateDP(object_path,obj_id,common){
              const path = object_path;
              const id = path + '.' + obj_id;
              var obj;
              obj['type'] = 'state';
              obj['common'] = common;
              if(!existsState(id)) {
                  setObject(id, obj, function (err) {
                      if (err) log('Cannot write object: ' + err)
                      else {
                          var init = null;
                          if(common.def === undefined) {
                              if(common.type === 'number') init = 0;
                              if(common.type === 'boolean') init = false;
                              if(common.type === 'string') init = '';
                          } else init = common.def;
                          setState(id, init);
                      }
                  });
              }else{
                  setState(id, common.def);
              }
          }
          
          createOrUpdateDP('eufy-security.0.device'+device_count,'cam_id', {read: true, write: true, role: "state", desc: "", type: "string", def: device.device_id });
          
          AlCalzone paul53 2 Replies Last reply Reply Quote 0
          • AlCalzone
            AlCalzone Developer @ChristianG last edited by

            @ChristianG sagte in Fragen zu createState.:

            die Punkte werden einfach nicht angelegt

            Bist du 100% sicher, dass die Funktion überhaupt ausgeführt wird? Hast du in den Adaptereinstellungen setObject erlaubt?

            C 1 Reply Last reply Reply Quote 0
            • C
              ChristianG @AlCalzone last edited by

              @AlCalzone Bildschirmfoto 2020-07-06 um 08.48.13.png

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

                @ChristianG sagte:

                Hier für alle die doch noch versuchen wollen es ans laufen zu bekommen:

                Ich würde Zeile 4 - so wie im verlinkten Beispiel - ändern in:

                    var obj = {};
                
                C 1 Reply Last reply Reply Quote 0
                • C
                  ChristianG @paul53 last edited by

                  @paul53 geht nicht, dann gibt es einen Fehler.Bildschirmfoto 2020-07-06 um 08.59.56.png

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

                    @ChristianG Warum ist dein Skript auf TypeScript eingestellt?

                    C 1 Reply Last reply Reply Quote 0
                    • C
                      ChristianG @AlCalzone last edited by ChristianG

                      @AlCalzone weil ich sonst den import von

                      var axios = require('axios');
                      

                      nicht machen kann.

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

                        @ChristianG natürlich kannst du das.

                        C 2 Replies Last reply Reply Quote 0
                        • C
                          ChristianG @AlCalzone last edited by

                          @AlCalzone Okay, war rot hinterlegt aber ausführen geht 🙂 Danke!!! Dann lag es nur an der kleinen Sache 🙂

                          1 Reply Last reply Reply Quote 0
                          • C
                            ChristianG @AlCalzone last edited by

                            @AlCalzonem habe die Daten nun im ioBroker 🙂

                            Danke!

                            Wie kann ich das Skript nun noch automatisch stoppen, nachdem es fertig ist?

                            Also damit es nicht mehr als aktiviert zählt?

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

                              @ChristianG Üblicherweise stoppt man Skripte nicht. Oder ging es hier nur drum, die Daten einmalig einzulesen?

                              C 1 Reply Last reply Reply Quote 0
                              • C
                                ChristianG @AlCalzone last edited by

                                @AlCalzone Habs verstanden. Ich habe das Skript nun aktiv und wenn ich die Daten haben möchte führe ich das Skript mit Blockly aus.

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

                                  @ChristianG Ich glaube ich verstehe den Anwendungsfall nicht. Wenn es wirklich nur um Einlesen-on-demand geht, kannst du es einfach im Skript-Editor manuell starten und stoppen.
                                  Wenn es irgendwie automatisiert werden soll:
                                  Auf einen Datenpunkt triggern und diesen bei Bedarf beschreiben.

                                  1 Reply Last reply Reply Quote 0
                                  • C
                                    ChristianG last edited by

                                    Das geht doch auch:

                                    Bildschirmfoto 2020-07-06 um 20.19.22.png

                                    Kann ruhig beim Neustart ausführen oder alle 5 min wenn das Script triggered wurde.

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

                                      @ChristianG Wie du meinst... Die Lösung mit scriptEnabled ist nicht offiziell unterstützt und hat (wie man im Forum nachlesen kann) schon häufig zu Problemen geführt. Verwendung also auf eigene Gefahr - ich werde weiterhin davon abraten.

                                      Sauberer wäre ein Trigger-Datenpunkt (keine Ahnung warum du dich so dagegen sträubst, so brauchst du ein weiteres Skript) oder den Timer direkt ins betreffende Skript einbauen.

                                      C 1 Reply Last reply Reply Quote 0
                                      • C
                                        ChristianG @AlCalzone last edited by

                                        @AlCalzone Ja dann baue ich das direkt mit ins Skript ein, macht ja Sinn.

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

                                          @ChristianG sagte:

                                          dann baue ich das direkt mit ins Skript ein

                                          Verwende besser einen Zeitplan-Trigger für die zyklische Abfrage.

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

                                            @paul53 naja ich will jede 5 Minuten die neue Daten abrufen. Also mit nem Cronjob oder wie?

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            618
                                            Online

                                            31.9k
                                            Users

                                            80.2k
                                            Topics

                                            1.3m
                                            Posts

                                            javascript
                                            3
                                            31
                                            3283
                                            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