Navigation

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

    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

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

    fxlupo

    @fxlupo

    0
    Reputation
    26
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    fxlupo Follow
    Starter

    Latest posts made by fxlupo

    • RE: VIS von Sigi234

      @olli_m Ich habe TextMate auf dem Mac.. komme damit sehr gut zurecht

      posted in Praktische Anwendungen (Showcase)
      F
      fxlupo
    • RE: MVG München Abfahrtszeiten

      Danke das war es was gefehlt hat. State als String definiert und das Object in JSON.stringify gepackt.

      posted in JavaScript
      F
      fxlupo
    • RE: MVG München Abfahrtszeiten

      Hier das komplette Script

      const mvgApi = require('@lynbarry/mvg-api');
      
      var station = getState('javascript.' + instance + '.MVG.Haltestelle').val
      var bus = '',
          tram = '',
          ubahn = '',
          sbahn = '';
      
          createState('javascript.' + instance + '.MVG.Haltestelle', station, {type: "string", role: 'Haltestelle'});
          createState('javascript.' + instance + '.MVG.Abfahrtszeit', true, {type: "object", role: 'history'});
          createState('javascript.' + instance + '.MVG.SBahn', false, {
          name: 'Anzeige von SBahn',
          desc: 'S-Bahn Abfahrten anzeigen',
          type: 'boolean',
          });
          createState('javascript.' + instance + '.MVG.Tram', false, {
          name: 'Anzeige von Tram',
          desc: 'Tram Abfahrten anzeigen',
          type: 'boolean',
          });
          createState('javascript.' + instance + '.MVG.Bus', false, {
          name: 'Anzeige von Bus',
          desc: 'Bus Abfahrten anzeigen',
          type: 'boolean',
          });
          createState('javascript.' + instance + '.MVG.UBahn', false, {
          name: 'Anzeige von UBahn',
          desc: 'U-Bahn Abfahrten anzeigen',
          type: 'boolean',
          });
      
      function getDeparture() {
          mvgApi.getDepartures(station, [ubahn,sbahn,bus,tram]).then(lines => {
              //  console.log(lines));
                setState('javascript.' + instance + '.MVG.Abfahrtszeit',lines, true);
              });
       }
      
      
          // Update each minute
      schedule("* * * * *", function () {
          if (getState('javascript.' + instance + '.MVG.UBahn').val){ ubahn= 'u'; } 
          if (getState('javascript.' + instance + '.MVG.SBahn').val){ sbahn = 's'; } 
          if (getState('javascript.' + instance + '.MVG.Bus').val){ bus = 'b'; } 
          if (getState('javascript.' + instance + '.MVG.Tram').val){ tram = 't'; } 
          getDeparture();
      });
      
      posted in JavaScript
      F
      fxlupo
    • MVG München Abfahrtszeiten

      Hallo zusammen,

      ich möchte mir die Abfahrtszeiten der Münchner U-Bahn und Tram in meiner Vis anzeigen lassen. Ich habe dazu folgende Api auf Git gefunden. https://github.com/Lynbarry/mvg-api) https://github.com/Lynbarry/mvg-api ... Mit npm installiert und ich bekomme die Daten ins Log. Bis hierher alles fein.

      Da ich die Info aber im Vis haben will, habe ich mir einen State erstellt indem der JSON String gespeicher werden soll. Und hier ist Ende mit meinem JS know how.

      Ich habe das Example wie folgend geändert.

          mvgApi.getDepartures(station, [ubahn,sbahn,bus,tram]).then(lines => {
              //  console.log(lines));
                setState('javascript.' + instance + '.MVG.Abfahrtszeit',lines, true);
              });
      

      Egal ob ich den State als String oder Object definiere ist das höchste der Gefühle, dass ich [object Object] als Wert in den State bekomme.
      Das Log spuckt mir folgendes aus.

      2019-04-18 08:04:00.424 - warn: javascript.0 Wrong type of javascript.0.MVG.Abfahrtszeit: "object". Please fix, while deprecated and will not work in next versions.
      2019-04-18 08:04:00.426 - warn: javascript.0 at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1258:20)
      2019-04-18 08:04:00.426 - warn: javascript.0 at mvgApi.getDepartures.then.lines (script.js.MyScripts.MVG:41:11)
      2019-04-18 08:04:00.426 - warn: javascript.0 at :null:null
      2019-04-18 08:04:00.427 - warn: javascript.0 at process._tickCallback (internal/process/next_tick.js:189:7)
      

      Das der State den falschen Typ hat ist gut zu wissen. Aber ich denke ich habe alle Varianten durch und keine Idee, wie ich zum gewünschten Ergebnis komme.

      Wie muss der JS Aufruf oder der State definiert sein, damit mit das Script den JSON String in den State speichert?

      Danke fürs feedback
      Lupo

      posted in JavaScript
      F
      fxlupo
    Community
    Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
    The ioBroker Community 2014-2023
    logo