Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. [Gelöst] SetState funktioniert nicht

NEWS

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    3.1k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    1.1k

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    25
    1
    2.4k

[Gelöst] SetState funktioniert nicht

Scheduled Pinned Locked Moved JavaScript
2 Posts 2 Posters 279 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wizzardking
    wrote on last edited by wizzardking
    #1

    Edit: Das Skript funktioniert auf einmal korrekt.

    Hallo zusammen

    Ich bin relativ neu mit JS unterwegs, daher bitte nicht böse sein, wenn die Antwort offensichtlich ist.

    Ich habe ein Skript geschrieben, welches per API ein paar Daten abruft und diese in Objekte schreiben soll.
    Soweit scheint das auch zu funktionieren und in den Logs sehe ich, dass die Werte "lastDownloads[0]" bis *lastDownloads[4]" korrekt gefüllt sind. Die Objekte erhalten aber keine neuen Werte und ich erhalte auch keine Fehlermeldung.

    Die Datenpunkte vom Typ state existieren ebenfalls.

    Hat hier jemand eine Idee, wo das Problem liegen könnte?

    const axios = require('axios');
    
    const sonarrIP = '192.168.1.214:8093'; // IP und Port
    const apiKey = 'XYZ'; // API Key
    
    const options = {
      url: `http://${sonarrIP}/api/v3/history`,
      headers: {
        'X-Api-Key': apiKey
      }
    };
    
    axios(options)
      .then(response => {
        const records = response.data.records;
        const lastDownloads = [];
    
        for (let i = 0; i < records.length && i < 5; i++) {
          lastDownloads.push(records[i].sourceTitle);
        }
    
        //console.log(lastDownloads);
        console.log(lastDownloads[0]);
    	console.log(lastDownloads[1]);
    	console.log(lastDownloads[2]);
    	console.log(lastDownloads[3]);
    	console.log(lastDownloads[4]);
    
    
        // Schreibe die letzten 5 Downloads in die gewünschten Datenpunkte
    	setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.1', lastDownloads[0]);
        setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.2', lastDownloads[1]);
        setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.3', lastDownloads[2]);
        setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.4', lastDownloads[3]);
        setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.5', lastDownloads[4]);
      })
    
    M 1 Reply Last reply
    0
    • W wizzardking

      Edit: Das Skript funktioniert auf einmal korrekt.

      Hallo zusammen

      Ich bin relativ neu mit JS unterwegs, daher bitte nicht böse sein, wenn die Antwort offensichtlich ist.

      Ich habe ein Skript geschrieben, welches per API ein paar Daten abruft und diese in Objekte schreiben soll.
      Soweit scheint das auch zu funktionieren und in den Logs sehe ich, dass die Werte "lastDownloads[0]" bis *lastDownloads[4]" korrekt gefüllt sind. Die Objekte erhalten aber keine neuen Werte und ich erhalte auch keine Fehlermeldung.

      Die Datenpunkte vom Typ state existieren ebenfalls.

      Hat hier jemand eine Idee, wo das Problem liegen könnte?

      const axios = require('axios');
      
      const sonarrIP = '192.168.1.214:8093'; // IP und Port
      const apiKey = 'XYZ'; // API Key
      
      const options = {
        url: `http://${sonarrIP}/api/v3/history`,
        headers: {
          'X-Api-Key': apiKey
        }
      };
      
      axios(options)
        .then(response => {
          const records = response.data.records;
          const lastDownloads = [];
      
          for (let i = 0; i < records.length && i < 5; i++) {
            lastDownloads.push(records[i].sourceTitle);
          }
      
          //console.log(lastDownloads);
          console.log(lastDownloads[0]);
      	console.log(lastDownloads[1]);
      	console.log(lastDownloads[2]);
      	console.log(lastDownloads[3]);
      	console.log(lastDownloads[4]);
      
      
          // Schreibe die letzten 5 Downloads in die gewünschten Datenpunkte
      	setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.1', lastDownloads[0]);
          setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.2', lastDownloads[1]);
          setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.3', lastDownloads[2]);
          setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.4', lastDownloads[3]);
          setState('0_userdata.0.Media.Sonarr.Letzte_Downloads.5', lastDownloads[4]);
        })
      
      M Offline
      M Offline
      Moebi
      wrote on last edited by
      #2

      Auch wenn es bereits auf gelöst steht.
      So mancher kennt den Stolperstein nicht.😉

      Screenshot_2023-03-07-09-42-20-472_com.whatsapp.jpg

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      Support us

      ioBroker
      Community Adapters
      Donate

      222

      Online

      32.7k

      Users

      82.3k

      Topics

      1.3m

      Posts
      Community
      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
      ioBroker Community 2014-2025
      logo
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Home
      • Recent
      • Tags
      • Unread 0
      • Categories
      • Unreplied
      • Popular
      • GitHub
      • Docu
      • Hilfe