Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. [Gelöst] Javascript schreibt nicht in Datenpunkt

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Gelöst] Javascript schreibt nicht in Datenpunkt

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

      @arteck:

      ist jetzt nicht dein ernst oder…

      var stateDB = getState('result.e2powerstate.e2instandby').val;
      ```` `  
      

      Doch, ich bin da leider nicht erfahren. Allerdings kommt bei deinem Vorschlag folgende Meldung

      "getState "result.e2powerstate.e2instandby" not found (3)"

      Es geht auch hier darum, daß zuerst eine XML ausgelesen wird und dann der Wert in den Datenpunkt geschrieben werden soll.

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

        @LJSven:

        Doch, ich bin da leider nicht erfahren. Allerdings kommt bei deinem Vorschlag folgende Meldung

        "getState "result.e2powerstate.e2instandby" not found (3)" `

        Das macht schon Sinn wie du es hattest. result.e2powerstate.e2instandby ist eine Variable in deinem ausgelesenen Objekt und kein State in ioBroker.
        > Wrong type of javascript.0.Dreambox_OG_Standby_Status: "object"
        bedeutet aber, dass du nicht wie von Bluefox empfohlen den State mit Typ "boolean" (wahr/falsch) erstellst, sondern mit "object". Änder das erst mal und probiers dann nochmal.

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

          Offenbar enthält die Variable result.e2powerstate.e2instandby ein Objekt. Was ergibt ?

          log(JSON.stringify(result.e2powerstate.e2instandby));
          
          1 Reply Last reply Reply Quote 0
          • L
            LJSven last edited by

            @paul53:

            Offenbar enthält die Variable result.e2powerstate.e2instandby ein Objekt. Was ergibt ?

            log(JSON.stringify(result.e2powerstate.e2instandby));
            ```` `  
            

            javascript.0 script.js.common.Dreambox_OG.Standby_Status_DB_OG: ["true"]

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

              Das ist ein Array mit einem Element. Was ergibt ?

              log(result.e2powerstate.e2instandby[0] + ' ' + typeof result.e2powerstate.e2instandby[0]);
              
              1 Reply Last reply Reply Quote 0
              • L
                LJSven last edited by

                @paul53:

                Das ist ein Array mit einem Element. Was ergibt ?

                log(result.e2powerstate.e2instandby[0] + ' ' + typeof result.e2powerstate.e2instandby[0]);
                ```` `  
                

                Das ergibt:

                ! javascript.0 script.js.common.Dreambox_OG.Standby_Status_DB_OG: false string

                Wenn ich es so mache, scheint es zu gehen:

                stateDB = JSON.parse(result.e2powerstate.e2instandby);
                

                Ist das okay?

                Kann ich ein Javascript via Blockly starten / stoppen?

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

                  @LJSven:

                  var stateDB = JSON.parse(result.e2powerstate.e2instandby);
                  

                  Ist das okay? `
                  Ja.

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

                    Prima! Kann als gelöst markiert werden.

                    PS. Wenn noch jemand eine Antwort hat, ob ich ein Scirpt per Blockly starten kann, bin ich happy.

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

                      Ja, das geht.

                      Gibt einen Datenpunkt zu deinem Script der heißt etwas mit „script.enabled“.

                      Z.B.

                      999_f84ea20d-0854-45b7-a64f-ced5c1869903.jpeg

                      Denn kannst du über eine Blockly per Cron z.B. Für 2-3 Sekunden auf „true“ setzen.

                      Das````
                      [Gelöst]

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

                        Hier mein Script um die Dreambox (Enigma2) den Standby Status abzufragen:

                        ! const request = require('request');
                        ! const parser = require('xml2js').parseString;
                        ! createState('javascript.0.Dreambox_OG_Standby_Status', false, {
                        ! read: true,
                        ! write: true,
                        ! desc: "DB500 Standby Status",
                        ! type: "object",
                        ! def: false
                        ! });
                        ! function getDB500Status(xml) {
                        ! parser(xml, function (err, result) {
                        ! if(err) log('Fehler XML-Parsen: ' + err, 'error');
                        ! else {
                        ! var stateDB;
                        ! stateDB = JSON.parse(result.e2powerstate.e2instandby);
                        ! setState('javascript.0.Dreambox_OG_Standby_Status', stateDB);
                        ! console.log(JSON.parse(result.e2powerstate.e2instandby));
                        ! }
                        ! });
                        ! }
                        ! function getXML() {
                        ! request('http://root:%2A%2A%2A%2A%2A%2A%2A%2A@192.168.178.220:88/web/powerstate', function (error, response, body) {
                        ! if (error) log("Fehler beim Herunterladen: " + error, 'error');
                        ! else getDB500Status(body);
                        ! });
                        ! }
                        ! schedule('* * * * *', getXML); // jede Minute

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

                          Danke fürs teilen!

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

                            @LJSven:

                            createState('javascript.0.Dreambox_OG_Standby_Status', false, {

                            read: true,

                            write: true,

                            desc: "DB500 Standby Status",

                            type: "object",

                            def: false

                            }); `
                            Der Datenpunkt-Typ ist falsch !

                            createState('javascript.0.Dreambox_OG_Standby_Status', false, {
                               read: true,
                               write: true,
                               desc: "DB500 Standby Status",
                               type: "boolean",
                               def: false
                            });
                            
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post

                            Support us

                            ioBroker
                            Community Adapters
                            Donate

                            844
                            Online

                            32.0k
                            Users

                            80.4k
                            Topics

                            1.3m
                            Posts

                            7
                            18
                            1312
                            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