Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. the78mole

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 1
    • Best 0
    • Groups 0

    the78mole

    @the78mole

    0
    Reputation
    11
    Profile views
    1
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    the78mole Follow

    Latest posts made by the78mole

    • RE: Ölpreis

      Hallo zusammen,

      ich möchte meine sehr einfache Lösung auch noch kurz vorstellen. Ich nutze im Wesentlichen eine (undokumentierte) API von heizoel24.de, die sich aus deren Backend die Daten für den kleinen Chart holt.

      createState('EXTERN.prices.oil.price',     0,    {type: 'number'});
      createState('EXTERN.prices.oil.currency',  null, {type: 'string'});
      createState('EXTERN.prices.oil.name',      null, {type: 'string'});
      createState('EXTERN.prices.oil.unit',      null, {type: 'string'});
      createState('EXTERN.prices.oil.change',    0,    {type: 'number'});
      createState('EXTERN.prices.oil.timestamp', 0,    {type: 'number'});
      createState('EXTERN.prices.oil.url',       null, {type: "string"});
      createState('EXTERN.prices.oil.raw',       null, {type: "string"});
      
      var maxDate = new Date();
      var minDate = new Date(maxDate.getTime() - 86400000);
      var minDateEnc = encodeURIComponent(minDate.toDateString());
      var maxDateEnc = encodeURIComponent(maxDate.toDateString());
      //log("Min:" + minDateEnc);
      //log("Max:" + maxDateEnc);
      
      var priceUrl = "https://www.heizoel24.de/api/chartapi/GetAveragePriceHistory" 
          + "?countryId=1" 
          + "&minDate=" + minDateEnc 
          + "&maxDate=" + maxDateEnc;
      
      log("URL: " + priceUrl);
      
      function getOilPrice() {
          request(priceUrl, function (err, state, body){
              if (body) {
                  var response = JSON.parse(body);
                  var currency = response.Currency;
                  var price = response.CurrentPrice;
                  var currency = response.Currency;
                  var curdate = new Date();
                  var tstamp = curdate.getTime();
                  setState('EXTERN.prices.oil.url',       priceUrl);               // {type: 'string'}
                  setState('EXTERN.prices.oil.raw',       body);                   // {type: 'string'}
                  setState('EXTERN.prices.oil.price',     price);                  // {type: 'number'}
                  setState('EXTERN.prices.oil.currency',  currency);               // {type: 'string'}
                  setState('EXTERN.prices.oil.name',      response.ProductName);   // {type: 'string'}
                  setState('EXTERN.prices.oil.unit',      response.ChartUnit);     // {type: 'string'}
                  setState('EXTERN.prices.oil.change',    response.ChangePercent); // {type: 'number'}
                  setState('EXTERN.prices.oil.timestamp', tstamp);                 // {type: 'number'}
                  log("Current oil price fetched: " + price + " " + currency);
                  
              } else {
                  log('Request failed: ' + err, 'error');
                  log('Request URL: ' + priceUrl);
              }
          });
      }
      
      //getOilPrice();
      
      schedule('{"time":{"start":"00:00","end":"23:59","mode":"hours","interval":6},"period":{"days":1}}', function () {                        
        getOilPrice();
      });
      

      Die Werte werden dann im Objektbaum unter javascript.0.EXTERN abgelegt. Das Skript läuft alle 6 Stunden. Den price-Datenpunkt dann noch als history-Wert aufnehmen und man kann sein eigenes Chart recht einfach zusammenbastlen...

      posted in ioBroker Allgemein
      the78mole
      the78mole
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
    The ioBroker Community 2014-2023
    logo