Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Hilfe für Javascript Legastheniker und js v8.3.x

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Hilfe für Javascript Legastheniker und js v8.3.x

    This topic has been deleted. Only users with topic management privileges can see it.
    • apollon77
      apollon77 @haus-automatisierung last edited by

      @haus-automatisierung Vllt machen wir wie bei anderen deprecations eine "info" log draus? damit man es im Log unterdrücken kann? oder nur einmal die warnung per skript per vorkommen? Weil wenn ich alle 5s einen "request" call mache dann ist das schon viel log 🙂

      haus-automatisierung 1 Reply Last reply Reply Quote 0
      • haus-automatisierung
        haus-automatisierung Developer Most Active @apollon77 last edited by

        @apollon77 sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

        Vllt machen wir wie bei anderen deprecations eine "info" log draus?

        Dann macht wieder keiner was und die Leute, welche das Loglevel jetzt schon angepasst haben, sind am Ende wieder überrascht warum es "plötzlich" nicht mehr geht. 😞

        apollon77 1 Reply Last reply Reply Quote 0
        • apollon77
          apollon77 @haus-automatisierung last edited by

          @haus-automatisierung Ja ich weiss, aber glabe mir, wir haben da so einige Erfahrungen mit Deprecations und Usern ... und beim JavaScript Adapter ist das - wie man hier auch sieht, wo Kenntnisswelten aufeinanderprallen - nochmal ne andere Baustelle.

          Viele User haben sich irgendwann man Skripte herkopiert und vllt "zurechtgepfuscht" (Alles gut - weil Sie es nicht besser können) ... die Rennen jetzt dann alle da rein. Sollten wir. auch bedenken.
          Wir haben verschiedenene User-Typen hier und ganz viele sind halt keine (Skript) Profis. Von daher finde ich Rainers ansinnen super hier im Forum eine deutsche und ausführlichere Variante der Migration-Infos zu haben.

          O 1 Reply Last reply Reply Quote 3
          • O
            oFbEQnpoLKKl6mbY5e13 @apollon77 last edited by oFbEQnpoLKKl6mbY5e13

            Ich finde es gut, dass @Homoran versucht, eine für Anwender verständliche Anleitung zum Umbau von request auf httpget zu erstellen. Ich finde es auch richtig, von request wegzukommen.

            Danke an @haus-automatisierung !

            Aber auch ich nutze ein Skript, welches ich von hier kopiert habe:

            https://github.com/volkerrichert/ioBroker.mymuell

            Ich kann das trotz der Hinweise von @Homoran nicht umbauen.

            Hier das Original:

            const city_id = XXXXX;
            const area_id = XXX;
            const logging = false;
            const name = 'Müllabfuhr';
            const numberOfEntries = 69;
            
            const request = require('request');
            const instanz = '0_userdata.' + instance + '.muell';
            
            if (logging) log('starting muell.' + instanz);
            
            extendObject(instanz, {
                   type: "device",
                   common: {
                       name: name
                   }
               }, function (err) {
                   if (err) {
                       log('could not create device: ', 'warn');
                       return;
                   }
               
               }
            );
            let baseData = {};
            
            // query names first
            request({
               url: 'https://mymuell.jumomind.com/mmapp/api.php?r=trash&city_id=' + city_id + '&area_id=' + area_id, 
               method: 'GET', 
               headers: { 'Accept': 'application/json' }
               }, function(error, response, body) {
                   if (!error && response.statusCode == 200) {
                       var data = JSON.parse(body);  // info ist ein Objekt
                       data.forEach((v, i) => {
                           baseData[v._name] = v;
                       })
                       updateMuell();
                   }
               }
            );
            
            schedule('{"time":{"exactTime":true,"start":"12:17"},"period":{"days":1}}', updateMuell);
            
            function updateMuell() {
               var options = {url: 'https://mymuell.jumomind.com/webservice.php?idx=termins&city_id=' + city_id + '&area_id=' + area_id + '&ws=3', method: 'GET', headers: { 'Accept': 'application/json' }};
            
               request(options, function(error, response, body) {
                   if (!error && response.statusCode == 200) {
                       var info = JSON.parse(body);  // info ist ein Objekt
                       if (info[0].Ack === 'Success') {
                           var data = info[0]._data;  // xy ist eine Eigenschaft des Objektes info
                           let counter = 0;
                           const date = (new Date())
                           const todayStr = date.getFullYear() + "-" + ('00' + (date.getMonth() + 1 )).slice(-2) + "-" + ('00' + date.getDate()).slice(-2)
                           log(todayStr);
                           data.forEach((v, i) => {
                               if (todayStr < v.cal_date && counter <= numberOfEntries) {
                                   
                                   const basePath = instanz + '.' + ('000' + counter).slice(-3);
                                   log(v.cal_date + ' -> ' + basePath, 'debug');
                                   // States erstellen
                                   extendObject(basePath, {
                                           type: "channel",
                                           common: {
                                               name: v.cal_date_normal
                                           }
                                       }, function (err) {
                                           if (err) {
                                               log('could not create device: ', 'warn');
                                               return;
                                           }
                                       
                                       }
                                   );
                                   createState(basePath + '.date', v.cal_date_normal, {
                                       name: 'Datum',
                                       desc: 'Datum der Abholung',
                                       type: 'string',
                                       read: true,
                                       write: false
                                   }, () => {
                                       setState(basePath + '.date', v.cal_date_normal, true);
                                   });
                                   
                                   createState(basePath + '.desc', baseData[v.cal_garbage_type].title, {
                                       name: 'Beschreibung',
                                       desc: 'Beschreibung der Abholung',
                                       type: 'string',
                                       read: true,
                                       write: false
                                   }, () => {
                                       setState(basePath + '.desc', baseData[v.cal_garbage_type].title, true);
                                   });
                                   createState(basePath + '.color', {
                                       name: 'Farbe',
                                       desc: 'Farbe',
                                       type: 'string',
                                       role: 'level.color',
                                       read: true,
                                       write: false
                                   }, () => {
                                       setState(basePath + '.color', baseData[v.cal_garbage_type].color, true);
                                   });
            
                                   counter++;
                               }
                           });
                       }
                   }
               });
            };
            

            Hier mein Versuch (Funktion nicht getestet):

            const city_id = XXXXX;
            const area_id = XXX;
            const logging = false;
            const name = 'Müllabfuhr';
            const numberOfEntries = 69;
            
            const axios = require('axios');
            const instanz = '0_userdata.' + instance + '.muell';
            
            if (logging) log('starting muell.' + instanz);
            
            extendObject(instanz, {
                   type: "device",
                   common: {
                       name: name
                   }
               }, function (err) {
                   if (err) {
                       log('could not create device: ', 'warn');
                       return;
                   }
               
               }
            );
            let baseData = {};
            
            // query names first
            httpGet({
               url: 'https://mymuell.jumomind.com/mmapp/api.php?r=trash&city_id=' + city_id + '&area_id=' + area_id, 
               method: 'GET', 
               headers: { 'Accept': 'application/json' }
               }, function(error, response) {
                   if (!error && response.data == 200) {
                       var data = JSON.parse(body);  // info ist ein Objekt
                       data.forEach((v, i) => {
                           baseData[v._name] = v;
                       })
                       updateMuell();
                   }
               }
            );
            
            schedule('{"time":{"exactTime":true,"start":"12:17"},"period":{"days":1}}', updateMuell);
            
            function updateMuell() {
               var options = {url: 'https://mymuell.jumomind.com/webservice.php?idx=termins&city_id=' + city_id + '&area_id=' + area_id + '&ws=3', method: 'GET', headers: { 'Accept': 'application/json' }};
            
               httpGet(options, (error, response) {
                   if (!error && response.data == 200) {
                       var info = JSON.parse(body);  // info ist ein Objekt
                       if (info[0].Ack === 'Success') {
                           var data = info[0]._data;  // xy ist eine Eigenschaft des Objektes info
                           let counter = 0;
                           const date = (new Date())
                           const todayStr = date.getFullYear() + "-" + ('00' + (date.getMonth() + 1 )).slice(-2) + "-" + ('00' + date.getDate()).slice(-2)
                           log(todayStr);
                           data.forEach((v, i) => {
                               if (todayStr < v.cal_date && counter <= numberOfEntries) {
                                   
                                   const basePath = instanz + '.' + ('000' + counter).slice(-3);
                                   log(v.cal_date + ' -> ' + basePath, 'debug');
                                   // States erstellen
                                   extendObject(basePath, {
                                           type: "channel",
                                           common: {
                                               name: v.cal_date_normal
                                           }
                                       }, function (err) {
                                           if (err) {
                                               log('could not create device: ', 'warn');
                                               return;
                                           }
                                       
                                       }
                                   );
                                   createState(basePath + '.date', v.cal_date_normal, {
                                       name: 'Datum',
                                       desc: 'Datum der Abholung',
                                       type: 'string',
                                       read: true,
                                       write: false
                                   }, () => {
                                       setState(basePath + '.date', v.cal_date_normal, true);
                                   });
                                   
                                   createState(basePath + '.desc', baseData[v.cal_garbage_type].title, {
                                       name: 'Beschreibung',
                                       desc: 'Beschreibung der Abholung',
                                       type: 'string',
                                       read: true,
                                       write: false
                                   }, () => {
                                       setState(basePath + '.desc', baseData[v.cal_garbage_type].title, true);
                                   });
                                   createState(basePath + '.color', {
                                       name: 'Farbe',
                                       desc: 'Farbe',
                                       type: 'string',
                                       role: 'level.color',
                                       read: true,
                                       write: false
                                   }, () => {
                                       setState(basePath + '.color', baseData[v.cal_garbage_type].color, true);
                                   });
            
                                   counter++;
                               }
                           });
                       }
                   }
               });
            };
            

            haus-automatisierung Homoran 3 Replies Last reply Reply Quote 0
            • haus-automatisierung
              haus-automatisierung Developer Most Active @oFbEQnpoLKKl6mbY5e13 last edited by

              @ofbeqnpolkkl6mby5e13 MyMüll hab ich im Trashschedule Adapter doch schon integriert 🙃

              O 1 Reply Last reply Reply Quote 0
              • Homoran
                Homoran Global Moderator Administrators @oFbEQnpoLKKl6mbY5e13 last edited by

                @ofbeqnpolkkl6mby5e13 sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                Hier mein Versuch

                du hast auf axios umgebaut?
                die Hinweise sind für httpGet

                1 Reply Last reply Reply Quote 0
                • Homoran
                  Homoran Global Moderator Administrators @oFbEQnpoLKKl6mbY5e13 last edited by Homoran

                  @ofbeqnpolkkl6mby5e13 sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                  var data = JSON.parse(body); // info ist ein Objekt

                  und zumindest da ist noch ein body anstelle von response.data

                  1 Reply Last reply Reply Quote 0
                  • O
                    oFbEQnpoLKKl6mbY5e13 @haus-automatisierung last edited by oFbEQnpoLKKl6mbY5e13

                    @haus-automatisierung

                    Könntest du bitte trotz Trashschedule-Adapter helfen, das Skript auf httpGet umzustellen?

                    Mein aktueller Stand:

                    const city_id = XXXXX;
                    const area_id = XXX;
                    const logging = false;
                    const name = 'Müllabfuhr';
                    const numberOfEntries = 69;
                    
                    const instanz = '0_userdata.' + instance + '.muell-test';
                    
                    if (logging) log('starting muell.' + instanz);
                    
                    extendObject(instanz, {
                           type: "device",
                           common: {
                               name: name
                           }
                       }, function (err) {
                           if (err) {
                               log('could not create device: ', 'warn');
                               return;
                           }
                       
                       }
                    );
                    let baseData = {};
                    
                    // query names first
                    httpGet('https://mymuell.jumomind.com/mmapp/api.php?r=trash&city_id=' + city_id + '&area_id=' + area_id, { timeout: 2000 }, (error, response) => {
                       if (!error && response.data == 200) {
                           console.log(response.statusCode);
                           console.log(response.data);
                       } else {
                           console.error(error);
                       var data = JSON.parse(response.data);  // info ist ein Objekt
                               data.forEach((v, i) => {
                                   baseData[v._name] = v;
                               })
                       updateMuell();	
                       }
                    });
                    
                    schedule('{"time":{"exactTime":true,"start":"12:17"},"period":{"days":1}}', updateMuell);
                    
                    function updateMuell() {
                       var options = 'https://mymuell.jumomind.com/webservice.php?idx=termins&city_id=' + city_id + '&area_id=' + area_id + '&ws=3'
                    
                       httpGet(options), (error, response)
                           if (!error && response.data == 200) 
                               var info = JSON.parse(response.data);  // info ist ein Objekt
                               if (info[0].Ack === 'Success') {
                                   var data = info[0]._data;  // xy ist eine Eigenschaft des Objektes info
                                   let counter = 0;
                                   const date = (new Date())
                                   const todayStr = date.getFullYear() + "-" + ('00' + (date.getMonth() + 1 )).slice(-2) + "-" + ('00' + date.getDate()).slice(-2)
                                   log(todayStr);
                                   data.forEach((v, i) => {
                                       if (todayStr < v.cal_date && counter <= numberOfEntries) {
                                           
                                           const basePath = instanz + '.' + ('000' + counter).slice(-3);
                                           log(v.cal_date + ' -> ' + basePath, 'debug');
                                           // States erstellen
                                           extendObject(basePath, {
                                                   type: "channel",
                                                   common: {
                                                       name: v.cal_date_normal
                                                   }
                                               }, function (err) {
                                                   if (err) {
                                                       log('could not create device: ', 'warn');
                                                       return;
                                                   }
                                               
                                               }
                                           );
                                           createState(basePath + '.date', v.cal_date_normal, {
                                               name: 'Datum',
                                               desc: 'Datum der Abholung',
                                               type: 'string',
                                               read: true,
                                               write: false
                                           }, () => {
                                               setState(basePath + '.date', v.cal_date_normal, true);
                                           });
                                           
                                           createState(basePath + '.desc', baseData[v.cal_garbage_type].title, {
                                               name: 'Beschreibung',
                                               desc: 'Beschreibung der Abholung',
                                               type: 'string',
                                               read: true,
                                               write: false
                                           }, () => {
                                               setState(basePath + '.desc', baseData[v.cal_garbage_type].title, true);
                                           });
                                           createState(basePath + '.color', {
                                               name: 'Farbe',
                                               desc: 'Farbe',
                                               type: 'string',
                                               role: 'level.color',
                                               read: true,
                                               write: false
                                           }, () => {
                                               setState(basePath + '.color', baseData[v.cal_garbage_type].color, true);
                                           });
                    
                                           counter++;
                                       }
                                   });
                               }
                           };
                       
                    

                    2024-05-26 18:33:57.582  - info: javascript.0 (3416) Start JavaScript script.js.common._Tests.Test_17 (JavaScript/js)
                    2024-05-26 18:33:57.614  - info: javascript.0 (3416) script.js.common._Tests.Test_17: registered 0 subscriptions, 1 schedule, 0 messages, 0 logs and 0 file subscriptions
                    2024-05-26 18:33:57.705  - error: javascript.0 (3416) script.js.common._Tests.Test_17: null
                    2024-05-26 18:33:57.707  - error: javascript.0 (3416) Error in callback: TypeError: Cannot read properties of undefined (reading 'headers')
                    2024-05-26 18:33:57.708  - error: javascript.0 (3416)     at getHttpRequestConfig (/opt/iobroker/node_modules/iobroker.javascript/lib/tools.js:139:18)
                    2024-05-26 18:33:57.708  - error: javascript.0 (3416)     at httpGet (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1179:20)
                    2024-05-26 18:33:57.708  - error: javascript.0 (3416)     at updateMuell (script.js.common._Tests.Test_17:47:5)
                    2024-05-26 18:33:57.709  - error: javascript.0 (3416)     at Object.<anonymous> (script.js.common._Tests.Test_17:38:5)
                    2024-05-26 18:33:57.709  - error: javascript.0 (3416)     at /opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1189:38
                    2024-05-26 18:33:57.709  - error: javascript.0 (3416)     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
                    2024-05-26 18:33:59.284  - info: javascript.0 (3416) Stopping script script.js.common._Tests.Test_17
                    
                    T Homoran 2 Replies Last reply Reply Quote 0
                    • T
                      TT-Tom @oFbEQnpoLKKl6mbY5e13 last edited by

                      @ofbeqnpolkkl6mby5e13

                      response.data sind deine Daten die zurückkommen, die wirst du nicht auf den Status prüfen wollen.
                      Da müsste also response.statusCode stehen.

                      if (!error && response.data == 200)
                      
                      O Homoran 2 Replies Last reply Reply Quote 0
                      • O
                        oFbEQnpoLKKl6mbY5e13 @TT-Tom last edited by oFbEQnpoLKKl6mbY5e13

                        @tt-tom

                        Okay, danke, das klingt plausibel. Habe ich angepasst.

                        Edit:
                        Damit ist der Fehler weg, aber die Objektstruktur wird nicht angelegt. Nur der oberste Ordner Muell-Test.
                        Auf der Konsole werden Infos ausgegeben, die das alte Skript nicht ausgibt:

                        2024-05-26 20:13:44.259  - info: javascript.0 (3416) Start JavaScript script.js.common._Tests.Test_17 (JavaScript/js)
                        2024-05-26 20:13:44.302  - info: javascript.0 (3416) script.js.common._Tests.Test_17: registered 0 subscriptions, 1 schedule, 0 messages, 0 logs and 0 file subscriptions
                        2024-05-26 20:13:44.397  - info: javascript.0 (3416) script.js.common._Tests.Test_17: 200
                        2024-05-26 20:13:44.398  - info: javascript.0 (3416) script.js.common._Tests.Test_17: [{"title":"Bioabfall","name":"SZ_BIO","_name":"SZ_BIO","color":"a52a2a"},{"title":"Gelber Sack","name":"SZ_G","_name":"SZ_G","color":"FFFF00"},{"title":"Altpapier (120l, 240l)","name":"SZ_P","_name":"SZ_P","color":"2fc2e8"},{"title":"Restabfall (bis 240l)","name":"SZ_R","_name":"SZ_R","color":"2F4F4F"},{"title":"Weihnachtsbaum","name":"SZ_W","_name":"SZ_W","color":"36b515"}]
                        2024-05-26 20:14:15.701  - info: javascript.0 (3416) Stopping script script.js.common._Tests.Test_17
                        
                        T 1 Reply Last reply Reply Quote 0
                        • Homoran
                          Homoran Global Moderator Administrators @TT-Tom last edited by Homoran

                          @tt-tom sorry dass ich hier nochmal reingrätsche.
                          Ich hab ein altes wiffi-script auch noch umbauen wollten und natürlich nicht hinbekommen. Größenwahnsinnig wie ich durch die ersten Erfolge geworden bin hab ich natürlich duesmal keine Kopie erstellt.

                          Also den Rat von @haus-automatisierung beherzigt und mal eben versucht das ganze in Blockly nachzubauen.
                          nach gefühlten Stunden kopieren und konfigurieren von Blöcken hatte ich die Hauptfunktion laufen.

                          Screenshot_20240526-191624_Firefox.jpg

                          Jetzt kommt immer wieder timeout überschritten, cannot get vars of null

                          wie fange ich error im Blockly ab?
                          if !error....

                          1 Reply Last reply Reply Quote 0
                          • T
                            TT-Tom last edited by

                            @homoran
                            Bin leider nur am Handy unterwegs, kann aber nachher nochmal nachschauen. Aber auf error prüfen ist schon mal die richtige Richtung. Wie sieht das Blockly denn in JS aus.

                            Homoran 1 Reply Last reply Reply Quote 0
                            • T
                              TT-Tom @oFbEQnpoLKKl6mbY5e13 last edited by TT-Tom

                              @ofbeqnpolkkl6mby5e13

                              Hast du auch beide Zeilen angepasst? Der Fehler kam zweimal vor. Zeile 47 glaube ich

                              O 1 Reply Last reply Reply Quote 0
                              • Homoran
                                Homoran Global Moderator Administrators @TT-Tom last edited by Homoran

                                @tt-tom sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                                kann aber nachher nochmal nachschauen

                                danke schonmal. hab jetzt als erste Hilfe den Timeout hochgesetzt.

                                @tt-tom sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                                Wie sieht das Blockly denn in JS aus.

                                ist nur ein gaaanz kleiner Teil des Originals

                                schedule("*/4 * * * *", async () => {
                                  httpGet('http://192.168.138.62/?json:', { timeout: 4000, responseType: 'text' }, async (err, response) => {
                                    if (err) {
                                      console.error(err);
                                    }
                                    setState('javascript.1.WIFFI.Systeminfo.ip_Homematic_CCU' /* ip_Homematic_CCU */, getAttr(response.data, 'vars.0.value'), true);
                                    setState('javascript.1.WIFFI.wz_co2' /* Luftqualitaet */, getAttr(response.data, 'vars.1.value'), true);
                                    setState('javascript.1.WIFFI.wz_temp' /* Temperatur */, getAttr(response.data, 'vars.2.value'), true);
                                    setState('javascript.1.WIFFI.wz_feuchte' /* Luftfeuchte */, getAttr(response.data, 'vars.3.value'), true);
                                    setState('javascript.1.WIFFI.wz_taupunkt' /* Taupunkt */, getAttr(response.data, 'vars.4.value'), true);
                                    setState('javascript.1.WIFFI.wz_feuchte_abs' /* Absolutfeuchte */, getAttr(response.data, 'vars.5.value'), true);
                                    setState('javascript.1.WIFFI.wz_baro' /* Luftdruck */, getAttr(response.data, 'vars.6.value'), true);
                                    setState('javascript.1.WIFFI.wz_luftdrucktrend' /* Luftdrucktrend */, getAttr(response.data, 'vars.7.value'), true);
                                    setState('javascript.1.WIFFI.wz_lux' /* Helligkeit */, getAttr(response.data, 'vars.8.value'), true);
                                    setState('javascript.1.WIFFI.wz_motion_left' /* Bewegung links */, getAttr(response.data, 'vars.9.value'), true);
                                    setState('javascript.1.WIFFI.wz_motion_right' /* Bewegung rechts */, getAttr(response.data, 'vars.10.value'), true);
                                    setState('javascript.1.WIFFI.wz_noise' /* Geraeusch */, getAttr(response.data, 'vars.12.value'), true);
                                    setState('javascript.1.WIFFI.wz_elevation' /* Sonne-Elevation */, getAttr(response.data, 'vars.13.value'), true);
                                    setState('javascript.1.WIFFI.wz_azimut' /* Sonne-Azimut */, getAttr(response.data, 'vars.14.value'), true);
                                    setState('javascript.1.WIFFI.wz_buzzer' /* Buzzer */, getAttr(response.data, 'vars.15.value'), true);
                                  });
                                });
                                

                                ooh.
                                sehe gerade das ist ja "hard-coded" if (err) {console.error(err);}
                                das kann man dann wohl nicht unterbinden

                                T 1 Reply Last reply Reply Quote 0
                                • T
                                  TT-Tom @Homoran last edited by

                                  @homoran

                                  Das ist so richtig, damit du auch eine log-Ausgabe bekommst. Das if-Statement bedeutet soviel wie: Wenn ein Fehler vorliegt, dann schreibe ins Log die Fehlermeldung.

                                  Mann könnte jetzt das ganze so um stellen, dass bei einem Fehler keine Auswertung gemacht wird.

                                  Homoran 1 Reply Last reply Reply Quote 1
                                  • Homoran
                                    Homoran Global Moderator Administrators @TT-Tom last edited by

                                    @tt-tom sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                                    dass bei einem Fehler keine Auswertung gemacht wird.

                                    aber das log wird trotzdem zugemüllt.
                                    Allerdings dann (hoffentlich) nur noch mit timeout of x msec exceeded und nicht mehr die ganzen null Meldungen

                                    T paul53 2 Replies Last reply Reply Quote 0
                                    • O
                                      oFbEQnpoLKKl6mbY5e13 @TT-Tom last edited by

                                      @tt-tom

                                      Inzwischen ja. Leider wird weiterhin keine Objektstruktur angelegt. Hier der aktuelle Stand:

                                      const city_id = XXXXX;
                                      const area_id = XXX;
                                      const logging = false;
                                      const name = 'Müllabfuhr';
                                      const numberOfEntries = 69;
                                      
                                      const instanz = '0_userdata.' + instance + '.muell-test';
                                      
                                      if (logging) log('starting muell.' + instanz);
                                      
                                      extendObject(instanz, {
                                             type: "device",
                                             common: {
                                                 name: name
                                             }
                                         }, function (err) {
                                             if (err) {
                                                 log('could not create device: ', 'warn');
                                                 return;
                                             }
                                         
                                         }
                                      );
                                      let baseData = {};
                                      
                                      // query names first
                                      httpGet('https://mymuell.jumomind.com/mmapp/api.php?r=trash&city_id=' + city_id + '&area_id=' + area_id, { timeout: 2000 }, (error, response) => {
                                         if (!error && response.statusCode == 200) {
                                             console.log(response.statusCode);
                                             console.log(response.data);
                                         } else {
                                             console.error(error);
                                         var data = JSON.parse(response.data);  // info ist ein Objekt
                                                 data.forEach((v, i) => {
                                                     baseData[v._name] = v;
                                                 })
                                         updateMuell();	
                                         }
                                      });
                                      
                                      schedule('{"time":{"exactTime":true,"start":"12:17"},"period":{"days":1}}', updateMuell);
                                      
                                      function updateMuell() {
                                         var options = 'https://mymuell.jumomind.com/webservice.php?idx=termins&city_id=' + city_id + '&area_id=' + area_id + '&ws=3'
                                      
                                         httpGet(options), (error, response)
                                             if (!error && response.statusCode == 200) 
                                                 var info = JSON.parse(response.data);  // info ist ein Objekt
                                                 if (info[0].Ack === 'Success') {
                                                     var data = info[0]._data;  // xy ist eine Eigenschaft des Objektes info
                                                     let counter = 0;
                                                     const date = (new Date())
                                                     const todayStr = date.getFullYear() + "-" + ('00' + (date.getMonth() + 1 )).slice(-2) + "-" + ('00' + date.getDate()).slice(-2)
                                                     log(todayStr);
                                                     data.forEach((v, i) => {
                                                         if (todayStr < v.cal_date && counter <= numberOfEntries) {
                                                             
                                                             const basePath = instanz + '.' + ('000' + counter).slice(-3);
                                                             log(v.cal_date + ' -> ' + basePath, 'debug');
                                                             // States erstellen
                                                             extendObject(basePath, {
                                                                     type: "channel",
                                                                     common: {
                                                                         name: v.cal_date_normal
                                                                     }
                                                                 }, function (err) {
                                                                     if (err) {
                                                                         log('could not create device: ', 'warn');
                                                                         return;
                                                                     }
                                                                 
                                                                 }
                                                             );
                                                             createState(basePath + '.date', v.cal_date_normal, {
                                                                 name: 'Datum',
                                                                 desc: 'Datum der Abholung',
                                                                 type: 'string',
                                                                 read: true,
                                                                 write: false
                                                             }, () => {
                                                                 setState(basePath + '.date', v.cal_date_normal, true);
                                                             });
                                                             
                                                             createState(basePath + '.desc', baseData[v.cal_garbage_type].title, {
                                                                 name: 'Beschreibung',
                                                                 desc: 'Beschreibung der Abholung',
                                                                 type: 'string',
                                                                 read: true,
                                                                 write: false
                                                             }, () => {
                                                                 setState(basePath + '.desc', baseData[v.cal_garbage_type].title, true);
                                                             });
                                                             createState(basePath + '.color', {
                                                                 name: 'Farbe',
                                                                 desc: 'Farbe',
                                                                 type: 'string',
                                                                 role: 'level.color',
                                                                 read: true,
                                                                 write: false
                                                             }, () => {
                                                                 setState(basePath + '.color', baseData[v.cal_garbage_type].color, true);
                                                             });
                                      
                                                             counter++;
                                                         }
                                                     });
                                                 }
                                             };
                                         
                                      

                                      T Homoran 2 Replies Last reply Reply Quote 0
                                      • T
                                        TT-Tom @Homoran last edited by

                                        @homoran
                                        Ja davon gehe aus. Muss mir das aber zu Hause erst anschauen.
                                        Wobei der Timeout eventuell auch höher muss, wenn die Daten nicht so schnell da sind.

                                        1 Reply Last reply Reply Quote 1
                                        • T
                                          TT-Tom @oFbEQnpoLKKl6mbY5e13 last edited by

                                          @ofbeqnpolkkl6mby5e13
                                          Wie gesagt bin noch am Handy und schaue nachher mir das dann an. Das JSON kommt aber jetzt richtig rein?

                                          Setze das mal in Zeile 48 mit rein, damit du sehen kannst was da kommt.

                                          console.log(response.data);
                                          
                                          Homoran O 2 Replies Last reply Reply Quote 0
                                          • Homoran
                                            Homoran Global Moderator Administrators @TT-Tom last edited by

                                            @tt-tom sagte in Hilfe für Javascript Legastheniker und js v8.3.x:

                                            Setze das mal in Zeile 48 mit rein,

                                            steht schon in Zeile 30

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            826
                                            Online

                                            31.7k
                                            Users

                                            79.8k
                                            Topics

                                            1.3m
                                            Posts

                                            8
                                            104
                                            6139
                                            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