Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • 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

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. Json für SourceAnalytics

NEWS

  • Monatsrückblick Januar/Februar 2026 ist online!
    BluefoxB
    Bluefox
    16
    1
    347

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

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

Json für SourceAnalytics

Geplant Angeheftet Gesperrt Verschoben JavaScript
83 Beiträge 7 Kommentatoren 10.0k Aufrufe 9 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • N Nordischerjung

    @crunchip Hast du bei der Einstellung am DP Kosten berechnen aktiviert?

    292d442d-a28e-4a2d-b4fb-c22ee7208c3b-grafik.png

    crunchipC Abwesend
    crunchipC Abwesend
    crunchip
    Forum Testing Most Active
    schrieb am zuletzt editiert von crunchip
    #74

    @nordischerjung ne, das hat ich nicht, weil ich keine Kosten berechnen wollte(macht ja auch keinen Sinn in dem Fall). Das erklärt aber den eine fehlenden DP, die anderen zwei, waren die noch nicht beschriebenen.

    @liv-in-sky sagte in Json für SourceAnalytics:

    bitte im script auskommentieren

    mach ich dann

    das kommt davon wenn man schnell schnell und nicht bei der Sache, zwischen Tür und Angel

    EDIT
    @liv-in-sky jetzt hab ich aber ein widget Problem, siehe Datenpunkte/Geräte https://forum.iobroker.net/post/878898
    BKW ist zwar jetzt mit drin, mir fehlen jetzt aber die wifi-wz(Gas und Wasser, sind ja m³)
    und die Preise fehlen jetzt aber auch bei den Verbrauchern

    hab ich da jetzt was falsch verstanden im script?
    hab die 4 Zeile Auskommentiert

                               //"Gestern Kosten":getState(id4.replace("delivered.01_currentDay","earnings.01_previousDay")).val.toFixed(2),
                               //"Heute Kosten": getState(id4.replace("delivered.01_currentDay","earnings.01_currentDay")).val.toFixed(2),
                               //"Monats Kosten":getState(id4.replace("delivered.01_currentDay","earnings.03_currentMonth")).val.toFixed(2),
                               //"Jahres Kosten": getState(id4.replace("delivered.01_currentDay","earnings.05_currentYear")).val.toFixed(2),
    

    8bd9c19e-1ae2-42f9-8246-e8e3d45ac60e-image.png

    umgestiegen von Proxmox auf Unraid

    liv-in-skyL 1 Antwort Letzte Antwort
    0
    • crunchipC crunchip

      @nordischerjung ne, das hat ich nicht, weil ich keine Kosten berechnen wollte(macht ja auch keinen Sinn in dem Fall). Das erklärt aber den eine fehlenden DP, die anderen zwei, waren die noch nicht beschriebenen.

      @liv-in-sky sagte in Json für SourceAnalytics:

      bitte im script auskommentieren

      mach ich dann

      das kommt davon wenn man schnell schnell und nicht bei der Sache, zwischen Tür und Angel

      EDIT
      @liv-in-sky jetzt hab ich aber ein widget Problem, siehe Datenpunkte/Geräte https://forum.iobroker.net/post/878898
      BKW ist zwar jetzt mit drin, mir fehlen jetzt aber die wifi-wz(Gas und Wasser, sind ja m³)
      und die Preise fehlen jetzt aber auch bei den Verbrauchern

      hab ich da jetzt was falsch verstanden im script?
      hab die 4 Zeile Auskommentiert

                                 //"Gestern Kosten":getState(id4.replace("delivered.01_currentDay","earnings.01_previousDay")).val.toFixed(2),
                                 //"Heute Kosten": getState(id4.replace("delivered.01_currentDay","earnings.01_currentDay")).val.toFixed(2),
                                 //"Monats Kosten":getState(id4.replace("delivered.01_currentDay","earnings.03_currentMonth")).val.toFixed(2),
                                 //"Jahres Kosten": getState(id4.replace("delivered.01_currentDay","earnings.05_currentYear")).val.toFixed(2),
      

      8bd9c19e-1ae2-42f9-8246-e8e3d45ac60e-image.png

      liv-in-skyL Offline
      liv-in-skyL Offline
      liv-in-sky
      schrieb am zuletzt editiert von
      #75

      @crunchip

      das json hat letztlich immer die gleiche anzahl an "spalten" - daher kannst du nicht einfach auskommentieren, was du nicht willst - du musst getState.. z.b einfach ein " " einsetzen - also ein leerzeichen, damit alle eintrage im json die selbe anzahl hat

                                 "Gestern Kosten": " " ,//getState(id4.replace("delivered.01_currentDay","earnings.01_previousDay")).val.toFixed(2),
                                 "Heute Kosten": " ",//getState(id4.replace("delivered.01_currentDay","earnings.01_currentDay")).val.toFixed(2),
                            
      usw

      nach einem gelösten Thread wäre es sinnvoll dies in der Überschrift des ersten Posts einzutragen [gelöst]-... Bitte benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat. Forum-Tools: PicPick https://picpick.app/en/download/ und ScreenToGif https://www.screentogif.com/downloads.html

      crunchipC 1 Antwort Letzte Antwort
      1
      • liv-in-skyL liv-in-sky

        @crunchip

        das json hat letztlich immer die gleiche anzahl an "spalten" - daher kannst du nicht einfach auskommentieren, was du nicht willst - du musst getState.. z.b einfach ein " " einsetzen - also ein leerzeichen, damit alle eintrage im json die selbe anzahl hat

                                   "Gestern Kosten": " " ,//getState(id4.replace("delivered.01_currentDay","earnings.01_previousDay")).val.toFixed(2),
                                   "Heute Kosten": " ",//getState(id4.replace("delivered.01_currentDay","earnings.01_currentDay")).val.toFixed(2),
                              
        usw
        crunchipC Abwesend
        crunchipC Abwesend
        crunchip
        Forum Testing Most Active
        schrieb am zuletzt editiert von
        #76

        @liv-in-sky ok, das hab ich jetzt, passt, danke dir:+1:
        jetzt hab ich nur noch das Problem mit den 2 fehlenden Geräten(m³) was hab ich denn da wieder falsch verstanden:thinking_face:

        umgestiegen von Proxmox auf Unraid

        liv-in-skyL 1 Antwort Letzte Antwort
        0
        • crunchipC crunchip

          @liv-in-sky ok, das hab ich jetzt, passt, danke dir:+1:
          jetzt hab ich nur noch das Problem mit den 2 fehlenden Geräten(m³) was hab ich denn da wieder falsch verstanden:thinking_face:

          liv-in-skyL Offline
          liv-in-skyL Offline
          liv-in-sky
          schrieb am zuletzt editiert von
          #77

          @crunchip eigentlich nix - aber es wurde mir geschrieben, ich solle die gas sachen rausfiltern - irgendwo hier im forum

          aber kein thema - das musst du ändern bzw einfügen(auskommentieren)

          Image 188.png

          nach einem gelösten Thread wäre es sinnvoll dies in der Überschrift des ersten Posts einzutragen [gelöst]-... Bitte benutzt das Voting rechts unten im Beitrag wenn er euch geholfen hat. Forum-Tools: PicPick https://picpick.app/en/download/ und ScreenToGif https://www.screentogif.com/downloads.html

          crunchipC 1 Antwort Letzte Antwort
          1
          • liv-in-skyL liv-in-sky

            @crunchip eigentlich nix - aber es wurde mir geschrieben, ich solle die gas sachen rausfiltern - irgendwo hier im forum

            aber kein thema - das musst du ändern bzw einfügen(auskommentieren)

            Image 188.png

            crunchipC Abwesend
            crunchipC Abwesend
            crunchip
            Forum Testing Most Active
            schrieb am zuletzt editiert von
            #78

            @liv-in-sky ich danke dir für die rasche Hilfe, passt nun alles:ok_hand:

            umgestiegen von Proxmox auf Unraid

            H 1 Antwort Letzte Antwort
            1
            • crunchipC crunchip

              @liv-in-sky ich danke dir für die rasche Hilfe, passt nun alles:ok_hand:

              H Online
              H Online
              hm_krause
              schrieb am zuletzt editiert von
              #79

              Hallo,
              das Script lief bei mr bis letzte Woche problemlos.

              let myArrSourcA=[];
              let myBlacklist=[];
              // Beispiel Blacklist: ['sourceanalytix.0.sonoff__0__SonoffPow3__ENERGY_Total','sourceanalytix.0.sonoff__3__Nous1__ENERGY_Total']
              let dataPunkt='0_userdata.0.StromJson.StromJson';
              let theSchedule=' * * * * *';
              
              async function calcJson(){
              myArrSourcA=[]; 
              
              $('sourceanalytix.0.*.currentYear.delivered.01_currentDay').each( function( id4, i){
                   let idy = id4.split('.'); 
                   if ( !myBlacklist.toString().includes(idy[2])){
                      let theName=getObject(idy[0]+'.'+idy[1]+'.'+idy[2]).common.name;   //idy[2].split('__');
                     
                   if(theName == undefined)  theName="no Name" ; 
                        myArrSourcA.push({
                                         "Name": theName,
                                         "Gestern":getState(id4.replace("01_currentDay","01_previousDay")).val.toFixed(2),
                                         "Heute": getState(id4).val,
                                         "Monat":getState(id4.replace("01_currentDay","03_currentMonth")).val.toFixed(2),
                                         "Jahr": getState(id4.replace("01_currentDay","05_currentYear")).val.toFixed(2),
                                         "Gestern Kosten":getState(id4.replace("delivered.01_currentDay","earnings.01_previousDay")).val.toFixed(2),
                                         "Heute Kosten": getState(id4.replace("delivered.01_currentDay","earnings.01_currentDay")).val.toFixed(2),
                                         "Monats Kosten":getState(id4.replace("delivered.01_currentDay","earnings.03_currentMonth")).val.toFixed(2),
                                         "Jahres Kosten": getState(id4.replace("delivered.01_currentDay","earnings.05_currentYear")).val.toFixed(2),
                                         "Richtung": "<span style=color:green>delivered"
                                         
                                         
                                     })
                         } // ende unit abfrage
                   }); 
              
              $('sourceanalytix.0.*.currentYear.consumed.01_currentDay').each( function( id4, i){ 
                  let idy = id4.split('.'); 
                  if (getObject(id4).common.unit=="kWh" && !myBlacklist.toString().includes(idy[2])){
                   
              
                   let theName=getObject(idy[0]+'.'+idy[1]+'.'+idy[2]).common.name;   //idy[2].split('__');
                   if(theName == undefined)  theName="no Name" ; 
                   //log( getObject(idy[0]+'.'+idy[1]+'.'+idy[2]).common.name )
              
                   
                                     myArrSourcA.push({
                                         "Name": theName,
                                         "Gestern":getState(id4.replace("01_currentDay","01_previousDay")).val.toFixed(2),
                                         "Heute": getState(id4).val,
                                         "Monat":getState(id4.replace("01_currentDay","03_currentMonth")).val.toFixed(2),
                                         "Jahr": getState(id4.replace("01_currentDay","05_currentYear")).val.toFixed(2),
                                         "Gestern Kosten":getState(id4.replace("consumed.01_currentDay","costs.01_previousDay")).val.toFixed(2),
                                         "Heute Kosten": getState(id4.replace("consumed.01_currentDay","costs.01_currentDay")).val.toFixed(2),
                                         "Monats Kosten":getState(id4.replace("consumed.01_currentDay","costs.03_currentMonth")).val.toFixed(2),
                                         "Jahres Kosten": getState(id4.replace("consumed.01_currentDay","costs.05_currentYear")).val.toFixed(2),
                                         "Richtung": "<span style=color:red>consumed"
                                         
                                         
                                     })
                                     } // ende unit abfrage
                                   });  
              
              
              //log(JSON.stringify(myArrSourcA)) 
              return myArrSourcA;
              }
              
              async function writeDatapoint(){
              
              if (!(await existsStateAsync(dataPunkt))) {
                     await createStateAsync(dataPunkt, "",{type: "string", name: "JSON SourcAnalytics", role: "value", read: true, write: true, } ); } 
              // log(JSON.stringify(await calcJson())) 
              
              setState(dataPunkt,JSON.stringify(await calcJson()));
                     }
              
              writeDatapoint();
              schedule(theSchedule,  function () { writeDatapoint();
               });
              
              
              

              Aber jetzt:

              javascript.0	14:47:06.775	error	
              
              Error: TypeError: Cannot read properties of null (reading 'common')
              
              javascript.0	14:47:06.775	error	
              
                  at script.js.Energie.Tab-Energie:36:23
              
              javascript.0	14:47:06.775	error	
              
                  at result.each (/opt/iobroker/node_modules/iobroker.javascript/build/lib/sandbox.js:947:29)
              
              javascript.0	14:47:06.775	error	
              
                  at calcJson (script.js.Energie.Tab-Energie:34:60)
              
              javascript.0	14:47:06.775	error	
              
                  at writeDatapoint (script.js.Energie.Tab-Energie:72:41)
              

              Was muss ichtun um das wieder gerade zu biegen?

              1 Antwort Letzte Antwort
              0
              • crunchipC Abwesend
                crunchipC Abwesend
                crunchip
                Forum Testing Most Active
                schrieb am zuletzt editiert von crunchip
                #80

                @hm_krause probier es mal mit diesem

                let myArrSourcA = [];
                let myBlacklist = [];
                let dataPunkt = '0_userdata.0.StromJson.StromJson';
                let theSchedule = ' * * * * *';
                
                function getValFixed(id, digits = 2) {
                    if (!existsState(id)) return (0).toFixed(digits);
                    const s = getState(id);
                    if (s.val === null || s.val === undefined) return (0).toFixed(digits);
                    const n = Number(s.val);
                    return isNaN(n) ? (0).toFixed(digits) : n.toFixed(digits);
                }
                
                function getValRaw(id) {
                    if (!existsState(id)) return 0;
                    const s = getState(id);
                    return (s.val === null || s.val === undefined) ? 0 : s.val;
                }
                
                async function addEntry(id4, direction, costPrefix, unitCheck = null) {
                    const idy = id4.split('.');
                    const rootId = `${idy[0]}.${idy[1]}.${idy[2]}`;
                
                    if (myBlacklist.includes(idy[2])) return;
                
                    // State-Objekt prüfen
                    if (!existsObject(id4)) return;
                    const stateObj = getObject(id4);
                    if (!stateObj.common || (unitCheck && stateObj.common.unit !== unitCheck)) {
                        return;
                    }
                
                    // Root-Objekt prüfen
                    if (!await existsObjectAsync(rootId)) {
                        log(`Root-Objekt fehlt: ${rootId}`, 'warn');
                        return;
                    }
                    const rootObj = getObject(rootId);
                    if (!rootObj.common) {
                        log(`Root-Objekt ohne common: ${rootId}`, 'warn');
                        return;
                    }
                
                    const theName = rootObj.common.name || 'no Name';
                
                    const replaceBase = `${direction}.01_currentDay`;
                    myArrSourcA.push({
                        "Name": theName,
                        "Gestern": getValFixed(id4.replace("01_currentDay", "01_previousDay")),
                        "Heute": getValRaw(id4),
                        "Monat": getValFixed(id4.replace("01_currentDay", "03_currentMonth")),
                        "Jahr": getValFixed(id4.replace("01_currentDay", "05_currentYear")),
                        "Gestern Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_previousDay`)),
                        "Heute Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_currentDay`)),
                        "Monats Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.03_currentMonth`)),
                        "Jahres Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.05_currentYear`)),
                        "Richtung": `<span style='color:${direction === "delivered" ? "green" : "red"}'>${direction}</span>`
                    });
                }
                
                async function calcJson() {
                    myArrSourcA = [];
                
                    await $('sourceanalytix.0.*.currentYear.delivered.01_currentDay').eachAsync(async (id4) => {
                        await addEntry(id4, 'delivered', 'earnings');
                    });
                
                    await $('sourceanalytix.0.*.currentYear.consumed.01_currentDay').eachAsync(async (id4) => {
                        await addEntry(id4, 'consumed', 'costs', 'kWh');
                    });
                
                    return myArrSourcA;
                }
                
                async function writeDatapoint() {
                    if (!(await existsStateAsync(dataPunkt))) {
                        await createStateAsync(dataPunkt, "", {
                            type: "string",
                            name: "JSON SourcAnalytics",
                            role: "value",
                            read: true,
                            write: true
                        });
                    }
                
                    setState(dataPunkt, JSON.stringify(await calcJson()), true);
                }
                
                writeDatapoint();
                schedule(theSchedule, writeDatapoint);
                
                

                umgestiegen von Proxmox auf Unraid

                H 1 Antwort Letzte Antwort
                0
                • crunchipC crunchip

                  @hm_krause probier es mal mit diesem

                  let myArrSourcA = [];
                  let myBlacklist = [];
                  let dataPunkt = '0_userdata.0.StromJson.StromJson';
                  let theSchedule = ' * * * * *';
                  
                  function getValFixed(id, digits = 2) {
                      if (!existsState(id)) return (0).toFixed(digits);
                      const s = getState(id);
                      if (s.val === null || s.val === undefined) return (0).toFixed(digits);
                      const n = Number(s.val);
                      return isNaN(n) ? (0).toFixed(digits) : n.toFixed(digits);
                  }
                  
                  function getValRaw(id) {
                      if (!existsState(id)) return 0;
                      const s = getState(id);
                      return (s.val === null || s.val === undefined) ? 0 : s.val;
                  }
                  
                  async function addEntry(id4, direction, costPrefix, unitCheck = null) {
                      const idy = id4.split('.');
                      const rootId = `${idy[0]}.${idy[1]}.${idy[2]}`;
                  
                      if (myBlacklist.includes(idy[2])) return;
                  
                      // State-Objekt prüfen
                      if (!existsObject(id4)) return;
                      const stateObj = getObject(id4);
                      if (!stateObj.common || (unitCheck && stateObj.common.unit !== unitCheck)) {
                          return;
                      }
                  
                      // Root-Objekt prüfen
                      if (!await existsObjectAsync(rootId)) {
                          log(`Root-Objekt fehlt: ${rootId}`, 'warn');
                          return;
                      }
                      const rootObj = getObject(rootId);
                      if (!rootObj.common) {
                          log(`Root-Objekt ohne common: ${rootId}`, 'warn');
                          return;
                      }
                  
                      const theName = rootObj.common.name || 'no Name';
                  
                      const replaceBase = `${direction}.01_currentDay`;
                      myArrSourcA.push({
                          "Name": theName,
                          "Gestern": getValFixed(id4.replace("01_currentDay", "01_previousDay")),
                          "Heute": getValRaw(id4),
                          "Monat": getValFixed(id4.replace("01_currentDay", "03_currentMonth")),
                          "Jahr": getValFixed(id4.replace("01_currentDay", "05_currentYear")),
                          "Gestern Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_previousDay`)),
                          "Heute Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_currentDay`)),
                          "Monats Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.03_currentMonth`)),
                          "Jahres Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.05_currentYear`)),
                          "Richtung": `<span style='color:${direction === "delivered" ? "green" : "red"}'>${direction}</span>`
                      });
                  }
                  
                  async function calcJson() {
                      myArrSourcA = [];
                  
                      await $('sourceanalytix.0.*.currentYear.delivered.01_currentDay').eachAsync(async (id4) => {
                          await addEntry(id4, 'delivered', 'earnings');
                      });
                  
                      await $('sourceanalytix.0.*.currentYear.consumed.01_currentDay').eachAsync(async (id4) => {
                          await addEntry(id4, 'consumed', 'costs', 'kWh');
                      });
                  
                      return myArrSourcA;
                  }
                  
                  async function writeDatapoint() {
                      if (!(await existsStateAsync(dataPunkt))) {
                          await createStateAsync(dataPunkt, "", {
                              type: "string",
                              name: "JSON SourcAnalytics",
                              role: "value",
                              read: true,
                              write: true
                          });
                      }
                  
                      setState(dataPunkt, JSON.stringify(await calcJson()), true);
                  }
                  
                  writeDatapoint();
                  schedule(theSchedule, writeDatapoint);
                  
                  
                  H Online
                  H Online
                  hm_krause
                  schrieb am zuletzt editiert von
                  #81

                  @crunchip
                  ...bringt noch:

                  javascript.0	18:14:17.814	error	
                  
                  Error: TypeError: $(...).eachAsync is not a function
                  
                  javascript.0	18:14:17.814	error	
                  
                      at calcJson (script.js.Energie.Skript_1:65:71)
                  
                  javascript.0	18:14:17.814	error	
                  
                      at writeDatapoint (script.js.Energie.Skript_1:87:46)
                  
                  crunchipC 1 Antwort Letzte Antwort
                  0
                  • H hm_krause

                    @crunchip
                    ...bringt noch:

                    javascript.0	18:14:17.814	error	
                    
                    Error: TypeError: $(...).eachAsync is not a function
                    
                    javascript.0	18:14:17.814	error	
                    
                        at calcJson (script.js.Energie.Skript_1:65:71)
                    
                    javascript.0	18:14:17.814	error	
                    
                        at writeDatapoint (script.js.Energie.Skript_1:87:46)
                    
                    crunchipC Abwesend
                    crunchipC Abwesend
                    crunchip
                    Forum Testing Most Active
                    schrieb am zuletzt editiert von crunchip
                    #82

                    @hm_krause sagte in Json für SourceAnalytics:

                    bringt noch:

                    let myArrSourcA = [];
                    let myBlacklist = [];
                    let dataPunkt = '0_userdata.0.StromJson.StromJson';
                    let theSchedule = ' * * * * *';
                    
                    function getValFixed(id, digits = 2) {
                        if (!existsState(id)) return '0.00';
                        const s = getState(id);
                        if (s.val === null || s.val === undefined) return '0.00';
                        const n = Number(s.val);
                        return isNaN(n) ? '0.00' : n.toFixed(digits);
                    }
                    
                    function getValRaw(id) {
                        if (!existsState(id)) return 0;
                        const s = getState(id);
                        return (s.val === null || s.val === undefined) ? 0 : Number(s.val);
                    }
                    
                    function addEntry(id4, direction, costPrefix, unitCheck = null) {
                        const idy = id4.split('.');
                        const rootId = `${idy[0]}.${idy[1]}.${idy[2]}`;
                    
                        if (myBlacklist.includes(idy[2])) return;
                    
                        // Alles sync, keine async mehr nötig
                        if (!existsObject(id4)) return;
                        const stateObj = getObject(id4);
                        if (!stateObj?.common || (unitCheck && stateObj.common.unit !== unitCheck)) return;
                    
                        if (!existsObject(rootId)) {
                            log(`Root fehlt: ${rootId}`, 'warn');
                            return;
                        }
                        const rootObj = getObject(rootId);
                        if (!rootObj?.common) {
                            log(`Root ohne common: ${rootId}`, 'warn');
                            return;
                        }
                    
                        const theName = rootObj.common.name || 'no Name';
                        const replaceBase = `${direction}.01_currentDay`;
                    
                        myArrSourcA.push({
                            "Name": theName,
                            "Gestern": getValFixed(id4.replace("01_currentDay", "01_previousDay")),
                            "Heute": getValRaw(id4),
                            "Monat": getValFixed(id4.replace("01_currentDay", "03_currentMonth")),
                            "Jahr": getValFixed(id4.replace("01_currentDay", "05_currentYear")),
                            "Gestern Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_previousDay`)),
                            "Heute Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_currentDay`)),
                            "Monats Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.03_currentMonth`)),
                            "Jahres Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.05_currentYear`)),
                            "Richtung": `<span style='color:${direction === "delivered" ? "green" : "red"}'>${direction}</span>`
                        });
                    }
                    
                    async function calcJson() {
                        myArrSourcA = [];
                    
                        // Normale .each() - sync und blitzschnell!
                        $('sourceanalytix.0.*.currentYear.delivered.01_currentDay').each(function (id4) {
                            addEntry(id4, 'delivered', 'earnings');
                        });
                    
                        $('sourceanalytix.0.*.currentYear.consumed.01_currentDay').each(function (id4) {
                            addEntry(id4, 'consumed', 'costs', 'kWh');
                        });
                    
                        return myArrSourcA;
                    }
                    
                    async function writeDatapoint() {
                        if (!(await existsStateAsync(dataPunkt))) {
                            await createStateAsync(dataPunkt, "", {
                                type: "string", name: "JSON SourcAnalytics", role: "value", read: true, write: true
                            });
                        }
                        setState(dataPunkt, JSON.stringify(await calcJson()), true);
                    }
                    
                    writeDatapoint();
                    schedule(theSchedule, writeDatapoint);
                    
                    

                    umgestiegen von Proxmox auf Unraid

                    H 1 Antwort Letzte Antwort
                    1
                    • crunchipC crunchip

                      @hm_krause sagte in Json für SourceAnalytics:

                      bringt noch:

                      let myArrSourcA = [];
                      let myBlacklist = [];
                      let dataPunkt = '0_userdata.0.StromJson.StromJson';
                      let theSchedule = ' * * * * *';
                      
                      function getValFixed(id, digits = 2) {
                          if (!existsState(id)) return '0.00';
                          const s = getState(id);
                          if (s.val === null || s.val === undefined) return '0.00';
                          const n = Number(s.val);
                          return isNaN(n) ? '0.00' : n.toFixed(digits);
                      }
                      
                      function getValRaw(id) {
                          if (!existsState(id)) return 0;
                          const s = getState(id);
                          return (s.val === null || s.val === undefined) ? 0 : Number(s.val);
                      }
                      
                      function addEntry(id4, direction, costPrefix, unitCheck = null) {
                          const idy = id4.split('.');
                          const rootId = `${idy[0]}.${idy[1]}.${idy[2]}`;
                      
                          if (myBlacklist.includes(idy[2])) return;
                      
                          // Alles sync, keine async mehr nötig
                          if (!existsObject(id4)) return;
                          const stateObj = getObject(id4);
                          if (!stateObj?.common || (unitCheck && stateObj.common.unit !== unitCheck)) return;
                      
                          if (!existsObject(rootId)) {
                              log(`Root fehlt: ${rootId}`, 'warn');
                              return;
                          }
                          const rootObj = getObject(rootId);
                          if (!rootObj?.common) {
                              log(`Root ohne common: ${rootId}`, 'warn');
                              return;
                          }
                      
                          const theName = rootObj.common.name || 'no Name';
                          const replaceBase = `${direction}.01_currentDay`;
                      
                          myArrSourcA.push({
                              "Name": theName,
                              "Gestern": getValFixed(id4.replace("01_currentDay", "01_previousDay")),
                              "Heute": getValRaw(id4),
                              "Monat": getValFixed(id4.replace("01_currentDay", "03_currentMonth")),
                              "Jahr": getValFixed(id4.replace("01_currentDay", "05_currentYear")),
                              "Gestern Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_previousDay`)),
                              "Heute Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.01_currentDay`)),
                              "Monats Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.03_currentMonth`)),
                              "Jahres Kosten": getValFixed(id4.replace(replaceBase, `${costPrefix}.05_currentYear`)),
                              "Richtung": `<span style='color:${direction === "delivered" ? "green" : "red"}'>${direction}</span>`
                          });
                      }
                      
                      async function calcJson() {
                          myArrSourcA = [];
                      
                          // Normale .each() - sync und blitzschnell!
                          $('sourceanalytix.0.*.currentYear.delivered.01_currentDay').each(function (id4) {
                              addEntry(id4, 'delivered', 'earnings');
                          });
                      
                          $('sourceanalytix.0.*.currentYear.consumed.01_currentDay').each(function (id4) {
                              addEntry(id4, 'consumed', 'costs', 'kWh');
                          });
                      
                          return myArrSourcA;
                      }
                      
                      async function writeDatapoint() {
                          if (!(await existsStateAsync(dataPunkt))) {
                              await createStateAsync(dataPunkt, "", {
                                  type: "string", name: "JSON SourcAnalytics", role: "value", read: true, write: true
                              });
                          }
                          setState(dataPunkt, JSON.stringify(await calcJson()), true);
                      }
                      
                      writeDatapoint();
                      schedule(theSchedule, writeDatapoint);
                      
                      
                      H Online
                      H Online
                      hm_krause
                      schrieb am zuletzt editiert von
                      #83

                      @crunchip
                      Passt,
                      vielen Dank...

                      1 Antwort Letzte Antwort
                      0
                      Antworten
                      • In einem neuen Thema antworten
                      Anmelden zum Antworten
                      • Älteste zuerst
                      • Neuste zuerst
                      • Meiste Stimmen


                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      519

                      Online

                      32.7k

                      Benutzer

                      82.5k

                      Themen

                      1.3m

                      Beiträge
                      Community
                      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
                      ioBroker Community 2014-2025
                      logo
                      • Anmelden

                      • Du hast noch kein Konto? Registrieren

                      • Anmelden oder registrieren, um zu suchen
                      • Erster Beitrag
                        Letzter Beitrag
                      0
                      • Home
                      • Aktuell
                      • Tags
                      • Ungelesen 0
                      • Kategorien
                      • Unreplied
                      • Beliebt
                      • GitHub
                      • Docu
                      • Hilfe