Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Request ablösen durch httpget

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Request ablösen durch httpget

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

      Ich hätte hier auch ein Script was ungestellt werden müsste, leider bin ich nicht so fit in Java.

      var options = {url: 'https://api.forecast.solar/estimate/51,11,23/9,12,54/30/28/12.73', method: 'GET', headers: { 'User-Agent': 'request' }};
       
      function GetSolar() {
          request(options, function(error, response, body) {
              if (!error && response.statusCode == 200) {
                  let res = JSON.parse(body).result.watts;  // res ist ein Objekt
                  for(let key in res) {
                      let ts = new Date(key).getTime(); 
                      let watt = res[key];
                      //log(ts + ': ' + watt);
                      sendTo('influxdb.0', 'storeState', {id: 'javascript.0.e3dc.PV_Forecast', state: {ts: ts, val: watt, ack: true, from: "javascript.0", q: 0}});
                      
                  }
              }
          });
      }
       
      schedule('*/30 * * * *', GetSolar);
      
      
      Homoran haus-automatisierung paul53 3 Replies Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators @glitzi last edited by

        @glitzi warum Doppelpost?

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

          @glitzi Warum nutzt Du nicht https://github.com/iobroker-community-adapters/ioBroker.pvforecast

          G 1 Reply Last reply Reply Quote 0
          • G
            glitzi last edited by

            Sorry,
            irgendwie konnte ich kein neues Thema erstellen und habe mich an ein anderes drangehangen, nach einem Browser Neustart funktioniert es jetzt.

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

               schedule('*/30 * * * *', () => {
                  httpGet('https://api.forecast.solar/estimate/51,11,23/9,12,54/30/28/12.73', { timeout: 2000 }, (err, response) => {
                      if (err) {
                          console.error(err);
                      } else if (response.statusCode == 200) {
                          const res = JSON.parse(response.data).result.watts;  // res ist ein Objekt
                          for (const key in res) {
                              const ts = new Date(key).getTime(); 
                              const val = res[key];
              
                              sendTo('influxdb.0', 'storeState', {
                                  id: 'javascript.0.e3dc.PV_Forecast',
                                  state: {
                                      ts,
                                      val,
                                      ack: true,
                                      from: 'javascript.0',
                                      q: 0
                                  }
                              });
                          }
                      }
                  });
              });
              

              oder etwas eleganter

               schedule('*/30 * * * *', () => {
                  httpGet('https://api.forecast.solar/estimate/51,11,23/9,12,54/30/28/12.73', { timeout: 2000 }, (err, response) => {
                      if (err) {
                          console.error(err);
                      } else if (response.statusCode == 200) {
                          const res = JSON.parse(response.data).result.watts;
              
                          for (const [key, val] of Object.entries(res)) {
                              sendTo('influxdb.0', 'storeState', {
                                  id: 'javascript.0.e3dc.PV_Forecast',
                                  state: {
                                      ts: new Date(key).getTime(),
                                      val,
                                      ack: true,
                                      from: 'javascript.0',
                                      q: 0
                                  }
                              });
                          }
                      }
                  });
              });
              
              G 1 Reply Last reply Reply Quote 1
              • G
                glitzi @haus-automatisierung last edited by

                @haus-automatisierung

                Perfekt,

                das ist die Lösung!
                Das ist ja viel bequemer wie mein altes Script.

                Danke !

                1 Reply Last reply Reply Quote 2
                • paul53
                  paul53 @glitzi last edited by paul53

                  @glitzi sagte: Script was ungestellt werden müsste

                  Welche Version des Javascript-Adapters? Mit neuer Version dürfte das Skript mit request so nicht mehr funktionieren.

                  G 1 Reply Last reply Reply Quote 1
                  • G
                    glitzi @paul53 last edited by glitzi

                    @paul53

                    v8.3.1, glaube gestern erst ein update gemacht, daher bin ich aktiv geworden 😉

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

                      @haus-automatisierung sagte in Request ablösen durch httpget:

                                                                                                                                                   schedule('*/30 * * * *', () => {                                                                                                                                                                                httpGet('https://api.forecast.solar/estimate/51,11,23/9,12,54/30/28/12.73', { timeout: 2000 }, (err, response) => {                                                                                                                                                                                    if (err) {                                                                                                                                                                                        console.error(err);                                                                                                                                                                                    } else if (response.statusCode == 200) {                                                                                                                                                                                        const res = JSON.parse(response.data).result.watts;                                                                                                                                                                                                                                                                                                                                                                     for (const [key, val] of Object.entries(res)) {                                                                                                                                                                                            sendTo('influxdb.0', 'storeState', {                                                                                                                                                                                                id: 'javascript.0.e3dc.PV_Forecast',                                                                                                                                                                                                state: {                                                                                                                                                                                                    ts: new Date(key).getTime(),                                                                                                                                                                                                    val,                                                                                                                                                                                                    ack: true,                                                                                                                                                                                                    from: 'javascript.0',                                                                                                                                                                                                    q: 0                                                                                                                                                                                                }                                                                                                                                                                                            });                                                                                                                                                                                        }                                                                                                                                                                                    }                                                                                                                                                                                });                                                                                                                                                                            });                                            
                      

                      Funktioniert, Danke!

                      metaxa 1 Reply Last reply Reply Quote 0
                      • metaxa
                        metaxa @glitzi last edited by

                        @Alle

                        Habe heute auch auf JS v8.3.1 upgedated.

                        Vor gefühlt 10 Jahren habe ich meine ersten und letzten Schritte in JS getan und bin nachwievor jeden Tag vom Ergebnis überrascht 😊

                        Nun habe ich auch die Aufforderung "request" umzustellen und schaffe es nicht. Bitte um eure Hilfe!

                        Original, funkt immer noch jedoch mit "httpGet" Warnung:

                        // Original von Greogorius https://forum.iobroker.net/topic/20314/skripten-des-e-control-spritpreisrechners/188
                        
                        // schedule("2,32 * * * *", function (){       //jede 2. und 32 Minute
                        // schedule("*/10 * * * *", function (){    //alle 10 Minuten
                        schedule("* * * * *", function (){       //alle Minuten
                        
                        /// console.log("Start Infos holen");
                        var result = "";
                            try {
                                require("request")('https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.xxxxxxxx&longitude=16.xxxxxxxxxx&fuelType=DIE&includeClosed=true', function (error, response, result) {
                                // require("httpGet")('https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.xxxxxxx&longitude=16.xxxxxxxxxx&fuelType=DIE&includeClosed=true', function (error, response, result) {  
                                  console.log(result);
                                  createState("javascript.0.scriptDatenPunkte.Sprit_AT.Parser.JSON", 0,{type: 'mixed',name: 'JSON', read: true, write: true});
                                  // setState("a_andreas.0.eigene_dp.Spritpreisrechner.JSON", result); //ich wollte die Ergebnisse in einer anderen Struktur haben, geht aber nicht weil über JS nur unter JS möglich
                                  setState("javascript.0.scriptDatenPunkte.Sprit_AT.Parser.JSON", result);
                                }).on("error", function (e) {console.error(e);});
                            } catch (e) { console.error(e); }
                            console.debug("request: " + 'https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.xxxxxxx&longitude=16.xxxxxxxx&fuelType=DIE&includeClosed=true');
                        /// console.log("Ende Infos holen");
                        });
                        
                        on({id: 'javascript.0.scriptDatenPunkte.Sprit_AT.Parser.JSON'/*Sprit JSON*/, change: 'any'}, function(obj)
                        // on({id: 'a_andreas.0.sys_variablen.Objekt_JSON'/*Sprit JSON*/, change: 'any'}, function(obj) //funktioniert vor selbst URL abholen
                        // on({id: 'parser.0.Spritpreisrechner'/*Sprit JSON*/, change: 'any'}, function(obj)
                        {
                            var index = 0;
                            // var price = "undefined";
                            var gasStation = JSON.parse(obj.state.val); 
                            if (gasStation.length === 0) return;
                         
                            /// console.log((String('Start Durchlauf')));
                            for (index = 0; index < gasStation.length; index++)
                            {
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Index", 0,{type: 'number', name: 'ID', read: true, write: true});
                                setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Index", gasStation[index].id);
                        
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".name", 0,{type: 'string', name: 'Name', read: true, write: true});
                                setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".name", gasStation[index].name);
                        
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Preis", 0,{type: 'string', name: 'Preis', read: true, write: true});
                                if ((gasStation[index].prices[0])!=undefined){
                                    setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Preis", (gasStation[index].prices[0].amount).toString().replace(".",","));
                                };
                        
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".PreisNumber", 0,{type: 'number', name: 'Preis', read: true, write: true});
                                if ((gasStation[index].prices[0])!=undefined){
                                    setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".PreisNumber", gasStation[index].prices[0].amount);
                                };
                        
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Strasse", 0,{type: 'string', name: 'Strasse', read: true, write: true});
                                setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Strasse", gasStation[index].location.address);
                        
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".PLZ & Ort", 0,{type: 'string', name: 'PLZ & Ort', read: true, write: true});
                                setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".PLZ & Ort", gasStation[index].location.postalCode + " "+ gasStation[index].location.city);
                        
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Distanz", 0,{type: 'string', name: 'Luftlinie/km', read: true, write: true});
                                setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Distanz", ((Math.round((gasStation[index].distance)*100)/100).toString().replace(".",",")));
                        
                                createState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Offen", 0,{type: 'boolean', name: 'Offen', read: true, write: true});
                                setState("javascript.0.scriptDatenPunkte.Sprit_AT.Tankstelle_"+index+".Offen", gasStation[index].open);
                            }
                            /// console.log((String('Ende Durchlauf')));
                        
                            /// console.log((String('Start eine Tankstelle finden')));
                            createState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Preis", 0,{type: 'string', name: 'Preis', read: true, write: true});
                            createState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Name", 0,{type: 'string', name: 'Name', read: true, write: true});
                            createState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Adresse", 0,{type: 'string', name: 'Adresse', read: true, write: true});
                            createState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Offen", 0,{type: 'boolean', name: 'Offen', read: true, write: true});
                            setState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Preis", "kein Preis verfügbar");
                            for (index = 0; index < gasStation.length; index++)
                            {
                                if (gasStation[index].id == 1469126) {    //Turmoil, Willergasse
                        
                                    if ((gasStation[index].prices[0])!=undefined){
                                        setState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Preis", (gasStation[index].prices[0].amount).toString().replace(".",","));
                                    };
                        
                                    setState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Name", gasStation[index].name);
                                    setState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Adresse", gasStation[index].location.postalCode + " " + gasStation[index].location.city + ", " + gasStation[index].location.address);
                                    setState("javascript.0.scriptDatenPunkte.Sprit_AT.Favorit.Offen", gasStation[index].open);
                                }
                            }
                            /// console.log((String('Ende eine Tankstelle finden')));
                            
                        }
                        );
                        

                        Log:

                        javascript.0	23:35:00.002	warn	script.js.common.900-919_Information.904_Spritpreise_AT_von_e-Control: request package is deprecated - please use httpGet (or a stable lib like axios) instead!
                        javascript.0	23:35:00.202	info	script.js.common.900-919_Information.904_Spritpreise_AT_von_e-Control: [{"id":33395,"name":"SOCAR Perchtoldsdorf","location":{"address":"Ketzergasse 191a","postalCode":"2380","city":"Perchtoldsdorf","latitude":48.1301731,"longitude":16.2919418},"contact":{"telephone":"4318674570","fax":"4318674804","mail":"office-at@socarenergy.com","website":"https://www.socarenergy.at/"},"openingHours":[{"day":"MO","label":"Montag","order":1,"from":"00:00","to":"24:00"},{"day":"DI","label":"Dienstag","order":2,"from":"00:00","to":"24:00"},{"day":"MI","label":"Mittwoch","order":3,"from":"00:00","to":"24:00"},{"day":"DO","label":"Donnerstag","order":4,"from":"00:00","to":"24:00"},{"day":"FR","label":"Freitag","order":5,"from":"00:00","to":"24:00"},{"day":"SA","label":"Samstag","order":6,"from":"00:00","to":"24:00"},{"day":"SO","label":"Sonntag","order":7,"from":"00:00","to":"24:00"},{"day":"FE","label":"Feiertag","order":8,"from":"00:00","to":"24:00"}],"offerInformation":{"service":false,"selfService":true,"unattended":true},"paymentMethods":{"cash":true,"debitCard":true,"creditCard":true,"others":"UTA, DKV, Socarcard"},"paymentArrangements":{"cooperative":false,"clubCard":false},"position":1,"open":true,"distance":4.248287202581326,"prices":[{"fuelType":"DIE","amount":1.554,"label":"Diesel"}]},{"id":1469126,"name":"Turmöl Quick","location":{"address":"Breitenfurterstraße 473","postalCode":"1230","city":"Wien","latitude":48.137832,"longitude":16.257546},"contact":{"mail":"marketing-box@doppler.at"},"openingHours":[{"day":"MO","label":"Montag","o
                        

                        Mein diletanischer Versuch:

                        // Original von Greogorius https://forum.iobroker.net/topic/20314/skripten-des-e-control-spritpreisrechners/188
                        
                        // schedule("2,32 * * * *", function (){       //jede 2. und 32 Minute
                        // schedule("*/10 * * * *", function (){    //alle 10 Minuten
                        schedule("* * * * *", function (){       //alle Minuten
                        
                        /// console.log("Start Infos holen");
                        var result = "";
                            try {
                                // require("request")('https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.xxxxxxx&longitude=16.xxxxxx&fuelType=DIE&includeClosed=true', function (error, response, result) {
                                require("httpGet")('https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.xxxxxxx&longitude=16.xxxxxxxx&fuelType=DIE&includeClosed=true', function (error, response, result) {  
                                  console.log(result);
                                  createState("javascript.0.scriptDatenPunkte.Sprit_AT.Parser.JSON", 0,{type: 'mixed',name: 'JSON', read: true, write: true});
                                  // setState("a_andreas.0.eigene_dp.Spritpreisrechner.JSON", result); //ich wollte die Ergebnisse in einer anderen Struktur haben, geht aber nicht weil über JS nur unter JS möglich
                                  setState("javascript.0.scriptDatenPunkte.Sprit_AT.Parser.JSON", result);
                                }).on("error", function (e) {console.error(e);});
                            } catch (e) { console.error(e); }
                            console.debug("request: " + 'https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.xxxxxxx&longitude=16.xxxxxxx&fuelType=DIE&includeClosed=true');
                        /// console.log("Ende Infos holen");
                        });
                        .............
                        

                        Log:

                        javascript.0	23:32:00.008	error	script.js.common.900-919_Information.904_Spritpreise_AT_von_e-Control: Error: Cannot find module 'httpGet'
                        javascript.0	23:32:00.008	error	at Object.<anonymous> (script.js.common.900-919_Information.904_Spritpreise_AT_von_e-Control:12:9)
                        javascript.0	23:32:00.008	error	script.js.common.900-919_Information.904_Spritpreise_AT_von_e-Control: TypeError: require(...) is not a function at Object.<anonymous> (script.js.common.900-919_Information.904_Spritpreise_AT_von_e-Control:13:27) at Job.job (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1769:34) at Job.invoke (/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-schedule/lib/Job.js:171:15) at /opt/iobroker/node_modules/iobroker.javascript/node_modules/node-schedule/lib/Invocation.js:268:28 at Timeout._onTimeout (/opt/iobroker/node_modules/iobroker.javascript/node_modules/node-schedule/lib/Invocation.js:228:7) at listOnTimeout (node:internal/timers:569:17) at processTimers (node:internal/timers:512:7)
                        

                        In den JS Adapter Einstellungen kann ich nix mehr hinzufügen, dachte das wäre die Lösung. Geht aber nicht, oder ich raffe es nicht.

                        093af252-4cae-4bad-899e-91e938515758-image.png

                        Bitte um Eure Unterstzützung!

                        liv-in-sky 1 Reply Last reply Reply Quote 0
                        • liv-in-sky
                          liv-in-sky @metaxa last edited by liv-in-sky

                          @metaxa

                          teste mal das

                          // Original von Greogorius https://forum.iobroker.net/topic/20314/skripten-des-e-control-spritpreisrechners/188
                           
                          // schedule("2,32 * * * *", function (){       //jede 2. und 32 Minute
                          // schedule("*/10 * * * *", function (){    //alle 10 Minuten
                          schedule(" * * * * *", function (){       //alle Minuten
                           
                          /// console.log("Start Infos holen");
                          //var result = "";
                              try {
                                  // require("request")('https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.xxxxxxx&longitude=16.xxxxxx&fuelType=DIE&includeClosed=true', function (error, response, result) {
                                  httpGet('https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.11&longitude=16.22&fuelType=DIE&includeClosed=true', function (error, response) {  
                                    console.log(response.data);
                                    createState("javascript.0.scriptDatenPunkte.Sprit_AT.Parser.JSON", 0,{type: 'mixed',name: 'JSON', read: true, write: true});
                                    // setState("a_andreas.0.eigene_dp.Spritpreisrechner.JSON", result); //ich wollte die Ergebnisse in einer anderen Struktur haben, geht aber nicht weil über JS nur unter JS möglich
                                    setState("javascript.0.scriptDatenPunkte.Sprit_AT.Parser.JSON", response.data);
                                  })
                              } catch (e) { console.error(e); }
                             // console.debug("request: " + 'https://api.e-control.at/sprit/1.0/search/gas-stations/by-address?latitude=48.11&longitude=16.22&fuelType=DIE&includeClosed=true');
                          /// console.log("Ende Infos holen");
                          });
                          
                          metaxa 1 Reply Last reply Reply Quote 1
                          • metaxa
                            metaxa @liv-in-sky last edited by

                            @liv-in-sky Top Arbeit!

                            Ich bedanke mich herzlichst! Läuft ohne Fehlermeldung durch und liefert Daten.

                            Jetzt kann ich mich ohne Stress mit Blockly auseinandersetzen und schauen ob ich es dort nachbauen kann.

                            lg, mxa

                            liv-in-sky 1 Reply Last reply Reply Quote 0
                            • liv-in-sky
                              liv-in-sky @metaxa last edited by

                              @metaxa sagte in Request ablösen durch httpget:

                              ohne Stress mit Blockly auseinandersetzen

                              ist einfacher mit blockly - gibt schon einige beispiele im forum

                              1 Reply Last reply Reply Quote 2
                              • bergjet
                                bergjet last edited by

                                Ich bräuchte hier jetzt auch einmal eure Hilfe.
                                Bekomme nun auch diesen Fehler: ReferenceError: request is not defined

                                request(
                                  {
                                    url: "http://admin:tester@192.168.1.214/record/current.jpg",
                                    encoding: null,
                                  },
                                  (error, response, body) => {
                                    if (!error && body) {
                                    writeFile("vis.0", "/current.jpg", body);
                                    }
                                  }
                                );
                                

                                Bist jetzt hat es funktioniert, habe aber keine Ahnung, was ich da machen soll.

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

                                  @bergjet

                                  Schau dir das mal an , ist aus der Doku vom JavaScript Adapter.

                                  httpGet('http://1.2.3.4/image.jpg', { responseType: 'arraybuffer' }, async (err, response) => {
                                      if (!err) {
                                          writeFile('0_userdata.0', 'test.jpg', response.data, (err) => {
                                              if (err) {
                                                  console.error(err);
                                              }
                                          });
                                      } else {
                                          console.error(err);
                                      }
                                  });
                                  

                                  Sollte für dich passen, musst du nur mit deinen Werten anpassen.

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

                                    @tt-tom Hervorragend, danke dir vielmals. Funktioniert.

                                    1 Reply Last reply Reply Quote 0
                                    • A
                                      ATARI last edited by

                                      @all
                                      Ich häng mich mal mit dran.
                                      Nachfolgendes Script erstellt oder aktualisiert globale Variablen im Fibaro HomeController HC2.
                                      Original Code von Nico Bode - www.iqHaus.de

                                      Da hier das 'request' anders als im Example-Code verwendet wird und ich nicht so fit in JS bin,
                                      kann ich das nicht nach 'httpGet' oder 'httpPut' umstellen.

                                      Kann mir dabei bitte jemand helfen?

                                      Gruß
                                      ATARI

                                          var request = require('request');
                                          var fibaro_username = 'username';       // Fibaro Admin Loginname
                                          var fibaro_password = 'password';       // Fibaro Password
                                          var fibaro_ip = 'ip_adresse';           // Fibaro IP adresse
                                       
                                      function fibaro_create_global_var(fibaro_global_name,fibaro_global_value,fibaro_create_when_not_exist=true) {
                                      
                                      request.post({
                                          url:     'http://'+fibaro_username+':'+fibaro_password+'@'+fibaro_ip+'/api/globalVariables/',
                                          form:    '{"name":"'+fibaro_global_name+'","value":"'+fibaro_global_value+'"}'
                                          
                                      }, function(error, response, body) {
                                          if (error) {
                                           //log(error, 'error');   
                                          } else {
                                              if (response.statusCode == 201) {
                                                  log('Variable '+ fibaro_global_name+' bei Fibaro mit dem Wert '+fibaro_global_value+' angelegt ','info');
                                              } else {
                                                  log('HTTP Fehler2','info');
                                                  log(JSON.stringify(response), 'error');            
                                              }
                                          }
                                      });
                                      }
                                      
                                      
                                      function fibaro_update_global_var(fibaro_global_name,fibaro_global_value,fibaro_create_when_not_exist=true) {
                                          
                                      String(fibaro_global_name);
                                      String(fibaro_global_value);
                                      
                                      request.put({
                                          url:     'http://'+fibaro_username+':'+fibaro_password+'@'+fibaro_ip+'/api/globalVariables/'+fibaro_global_name,
                                          form:    '{"name":"'+fibaro_global_name+'","value":"'+fibaro_global_value+'","invokeScenes":true}'
                                          
                                      }, function(error, response, body) {
                                          if (error) {
                                           log(error, 'error');   
                                          } else {
                                              if (response.statusCode == 200) {
                                                  log('Variable '+ fibaro_global_name+' bei Fibaro mit dem Wert '+fibaro_global_value+' gespeichert ','info');
                                              } else {
                                                  
                                                  if(response.statusCode == 404 && fibaro_create_when_not_exist === true) {
                                                      log('Variable wird angelegt','info');
                                                      fibaro_create_global_var(fibaro_global_name,fibaro_global_value);
                                                  } else {
                                                      log('HTTP Fehler','info');
                                                      log(JSON.stringify(response), 'error');            
                                                  }
                                              }
                                          }
                                      });
                                      }
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • Paulchen67
                                        Paulchen67 last edited by Paulchen67

                                        Hallo Zusammen,
                                        Ich habe hier auch ein Script das umgestellt werden müsste.
                                        Habe es anhand der Beispiele hier schon selbst versucht bekomme es aber nicht hin.
                                        Vermutlich nur ne Kleinigkeit aber mir fehlt das nötige Wissen.

                                        var source_url = 'http://XXX.XXX.XXX.XXX:88/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=XXX&pwd=XXX', // Kamerabild zB http://CamIP:Port/image1.jpg
                                            dest_path = '/opt/iobroker/iobroker-data/Bilder/';
                                        
                                        var request = require('request');
                                        var fs      = require('fs');
                                        
                                        
                                        // Bild an telegram schicken
                                        function sendImage (pfad) {
                                            setTimeout(function() {
                                                sendTo('telegram.0', 'send', {text: pfad, disable_notification: true});
                                                log('Webcam Bild per telegram verschickt');
                                            }, 2 * 1000)
                                        }
                                        
                                        // Bild speichern
                                        function saveImage() {
                                            request.get({url: source_url, encoding: 'binary'}, function (err, response, body) {
                                                fs.writeFile(dest_path + 'image3.jpg', body, 'binary', function(err) {
                                        
                                                if (err) {
                                                    log('Fehler beim Bild speichern: ' + err, 'warn');
                                                } else {
                                                    log('Webcam Bild gespeichert');
                                                    sendImage(dest_path + 'image3.jpg');
                                                }
                                              }); 
                                            });
                                        }
                                        
                                        
                                        // bei Skriptstart ausführen
                                        saveImage();
                                        

                                        Das Script funktioniert noch, spuckt aber immer ne Warnung aus.

                                        Was muss ich wo ändern damit das Script immer noch macht was es soll,
                                        aber keine Warnung mehr raushaut.

                                        Vielen Dank.

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

                                          @paulchen67

                                          Kannst du das Script in die codetags <|> packen, dann kann man auch besser helfen.

                                          Ansonsten schau mal ein paar Posts höher.

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

                                            @TT-Tom
                                            Kann ich nachher machen wenn ich am PC sitze, am Tablet lässt sich das Script nicht markieren und in die Zwischenablage legen.
                                            Daher nur der Screenshot, dachte mir schon dass das vielleicht nicht so ideal ist.

                                            Edit!
                                            Ist jetzt in den Codetags.
                                            Habe es schon anhand den Posts selber versucht aber nicht hinbekommen.

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

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            894
                                            Online

                                            31.6k
                                            Users

                                            79.5k
                                            Topics

                                            1.3m
                                            Posts

                                            javascript
                                            11
                                            30
                                            2103
                                            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