Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Json für SourceAnalytics

    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

    Json für SourceAnalytics

    This topic has been deleted. Only users with topic management privileges can see it.
    • N
      Nordischerjung @liv-in-sky last edited by

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

      evtl problem:

      • die namen der devices funtionieren hier bei meinen sonoff geräten - mit zb. hm-rpc müßte die namensgebung wahrscheinlich nochmal gecheckt werden

      Moin, mit den Namen habe ich auch Probleme.

      7a7a7a89-a9e4-4174-bccf-069a857d01ea-grafik.png

      das ist im Adapter

      b028247d-a100-43f1-af61-d72b130ba7c4-grafik.png

      liv-in-sky 3 Replies Last reply Reply Quote 0
      • liv-in-sky
        liv-in-sky @Nordischerjung last edited by

        @nordischerjung das dachte ich mit schon - ich kuck mal

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

          @nordischerjung

          bitte mal das hier testen

          
          
          let myArrSourcA=[];
          
          async function calcJson(){
          
          $('sourceanalytix.0.*.currentYear.consumed.01_currentDay').each( function( id4, i){  
          
               let idy = id4.split('.');
               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+" kWh",
                                     "Heute": getState(id4).val+" kWh",
                                     "Monat":getState(id4.replace("01_currentDay","03_currentMonth")).val+" kWh",
                                     "Jahr": getState(id4.replace("01_currentDay","05_currentYear")).val+" kWh",
                                     "Gestern Kosten":getState(id4.replace("consumed.01_currentDay","costs.01_previousDay")).val+" €",
                                     "Heute Kosten": getState(id4.replace("consumed.01_currentDay","costs.01_currentDay")).val+" €",
                                     "Monats Kosten":getState(id4.replace("consumed.01_currentDay","costs.03_currentMonth")).val+" €",
                                     "Jahres Kosten": getState(id4.replace("consumed.01_currentDay","costs.05_currentYear")).val+" €"
                                     
                                     
                                 })
                               });  
          
          //log(JSON.stringify(myArrSourcA)) 
          return myArrSourcA;
          }
          
          async function writeDatapoint(){
          
          if (!(await existsStateAsync('0_userdata.0.StromJson.StromJson'))) {
                 await createStateAsync('0_userdata.0.StromJson.StromJson', "",{type: "string", name: "JSON SourcAnalytics", role: "value", read: true, write: true, } ); } 
          // log(JSON.stringify(await calcJson()))   
          setState('0_userdata.0.StromJson.StromJson',JSON.stringify(await calcJson()));
                 }
          
          writeDatapoint();
          
                 
          
          

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

            @liv-in-sky Jetzt so

            f00b7283-5416-4ca7-a312-c0e898ccabb6-grafik.png

            liv-in-sky 1 Reply Last reply Reply Quote 0
            • crunchip
              crunchip Forum Testing Most Active @liv-in-sky last edited by

              @liv-in-sky kann man nicht "common name" abrufen anstatt der ID?

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

                @crunchip

                Image 179.png

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

                  @nordischerjung ich glaube, ich habe was gesehen - ich mach nochmal

                  1 Reply Last reply Reply Quote 0
                  • crunchip
                    crunchip Forum Testing Most Active @liv-in-sky last edited by

                    @liv-in-sky ah ok, hatte ich nicht weiter geguckt, bin grad aufn Sprung

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

                      @crunchip kein problem - die zusammenstellung der id ist wohl falsch um den common.name zu bekommen

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

                        @nordischerjung

                        bin verwirrt - sollte eigentlich so funktionieren - bei mir tut es das

                        kannst du mal bitte den inhalt des datenpunktes posten 0_userdata.0.StromJson.StromJson

                        siehe chat !

                        N metaxa 2 Replies Last reply Reply Quote 0
                        • N
                          Nordischerjung @liv-in-sky last edited by

                          @liv-in-sky So schnell nochmal Probiert, Sorry war mein Fehler. Funktioniert doch. Und dabei sehe ich, das Schlafzimmer wohl bei mir falsch geschrieben ist 😀

                          058934a0-18a1-447b-a947-55abf653ad87-grafik.png

                          Ich habe das schon geändert, habe 2 getrennte Widges einmal für Verbrauch und einmal Kosten. Das Ganze auch noch gleich gerundet, da der Adapter zB 0,002343524515 € ausspuckt

                          liv-in-sky 2 Replies Last reply Reply Quote 0
                          • liv-in-sky
                            liv-in-sky @Nordischerjung last edited by

                            @nordischerjung

                            dann paßt ja alles (hab schon an meinen coderfähigkeiten gezweifelt 🙂 )- brauchst du noch einen trigger - wir könnten einen schedule alle 10 min einfügen ?

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

                              @nordischerjung sagte in Json für SourceAnalytics:

                              Schlafzimmer wohl bei mir falsch geschrieben ist

                              solange du da drin nix falsches machst 🙂

                              1 Reply Last reply Reply Quote 1
                              • N
                                Nordischerjung @liv-in-sky last edited by

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

                                @nordischerjung

                                dann paßt ja alles (hab schon an meinen coderfähigkeiten gezweifelt 🙂 )- brauchst du noch einen trigger - wir könnten einen schedule alle 10 min einfügen ?

                                Ne, hab ich schon gemacht. Vielen Dank für dein Code.

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

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

                                  bin verwirrt - sollte eigentlich so funktionieren - bei mir tut es das

                                  Servus!
                                  Auf der Heimfahrt durchs ital. Kanaltal (Beifahrer 🙂 !) stieß ich hte auf den Thread. Darf ich dich dazu um Hilfe bitten?
                                  Via JS habe ich eine JSON aus SA nicht zusammengebracht. Mühsam habe ich mir ein Blockly zusammengeschustert.


                                  6c283e51-b32b-4cad-8d26-e51235035c83-image.png
                                  c241f8d4-d8eb-4d77-872a-a273ce615c23-image.png

                                  Ja, arbeitet und sieht dann so in VIS aus:
                                  e56cc641-3622-4072-aa83-2a0311620470-image.png

                                  Nur wie ich jetzt dein Script einsetze, ich komm nicht weiter
                                  5c56cafa-dc02-4fe4-9ba7-3d60626d3dc0-image.png
                                  ece3a55a-0313-4f0c-aea6-245ede08429a-image.png
                                  Den DP habe ich sicherheitshalber selbst angelegt

                                  {
                                    "common": {
                                      "name": "StromJson",
                                      "desc": "Manuell erzeugt",
                                      "role": "state",
                                      "type": "json",
                                      "read": true,
                                      "write": true
                                    },
                                    "type": "state",
                                    "native": {},
                                    "from": "system.adapter.admin.0",
                                    "user": "system.user.admin",
                                    "ts": 1666641854346,
                                    "_id": "0_userdata.0.SromJson.StromJson",
                                    "acl": {
                                      "object": 1636,
                                      "state": 1636,
                                      "owner": "system.user.admin",
                                      "ownerGroup": "system.group.administrator"
                                    }
                                  }
                                  

                                  Da tut sich aber nix.
                                  Bitte um deinen kurzen Support!
                                  LG, mxa

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

                                    @metaxa

                                    der datenpunkt muss vom type zeichenkette sein - aber das script macht das schon - enfach deinen dp löschen oder den type ändern

                                    das script schreibt auch den dp und daher habe ich in diesem script den schedule hinzugefügt - alle 5 minuten - kannst du natürlich anpassen, wie du möchtest. das script in ein neues javascript kopieren und starten (dein blockly script stoppen!) - beim ersten mal werden die daten sofort geschrieben und dann alle 5 min.

                                    
                                    
                                    let myArrSourcA=[];
                                    
                                    async function calcJson(){
                                    
                                    $('sourceanalytix.0.*.currentYear.consumed.01_currentDay').each( function( id4, i){  
                                    
                                         let idy = id4.split('.');
                                         let helper=idy[2].split('__');
                                         let helper2=helper[helper.length-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+" kWh",
                                                               "Heute": getState(id4).val+" kWh",
                                                               "Monat":getState(id4.replace("01_currentDay","03_currentMonth")).val+" kWh",
                                                               "Jahr": getState(id4.replace("01_currentDay","05_currentYear")).val+" kWh",
                                                               "Gestern Kosten":getState(id4.replace("consumed.01_currentDay","costs.01_previousDay")).val+" €",
                                                               "Heute Kosten": getState(id4.replace("consumed.01_currentDay","costs.01_currentDay")).val+" €",
                                                               "Monats Kosten":getState(id4.replace("consumed.01_currentDay","costs.03_currentMonth")).val+" €",
                                                               "Jahres Kosten": getState(id4.replace("consumed.01_currentDay","costs.05_currentYear")).val+" €"
                                                               
                                                               
                                                           })
                                                         });  
                                    
                                    //log(JSON.stringify(myArrSourcA)) 
                                    return myArrSourcA;
                                    }
                                    
                                    async function writeDatapoint(){
                                    
                                    if (!(await existsStateAsync('0_userdata.0.StromJson.StromJson'))) {
                                           await createStateAsync('0_userdata.0.StromJson.StromJson', "",{type: "string", name: "JSON SourcAnalytics", role: "value", read: true, write: true, } ); } 
                                    // log(JSON.stringify(await calcJson()))   
                                    setState('0_userdata.0.StromJson.StromJson',JSON.stringify(await calcJson()));
                                           }
                                    
                                    writeDatapoint();
                                    schedule('*/5 * * * *',  function () { writeDatapoint();
                                     });
                                    
                                    
                                    
                                    

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

                                      @liv-in-sky Ganz lieben Dank!
                                      Funktioniert auf Anhieb, nur irgendwie stimmt der Name nicht. Sobald ich oben auf Sortieren klicke, wird ein Datenzeile vermehrfacht angezeigt. Auch ds mit dem Runden müsste ich mir nochmals irgendwo raussaugen.
                                      89b0b720-cc4c-4fd0-b469-56dc27e6cf18-image.png

                                      dp (in Tags wird der Beitrag zu lange, deswegen als att)


                                      0_userdata.0.VIS.JSON.JSON_Strom.txt

                                      SA

                                      1bbb5a77-dc25-4d76-98b4-0248bd242fd6-image.png

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

                                        @metaxa schau ich mir an - das runden füge ich ein

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

                                          @metaxa das sotieren über widget funtioniert bei mir auch nicht - ist mir nicht aufgefallen - mal schauen, was das wieder ist 🙂

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

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

                                            @metaxa das sotieren über widget funtioniert bei mir auch nicht - ist mir nicht aufgefallen - mal schauen, was das wieder ist 🙂

                                            Erstmal Danke für Dein Script!!! Läuft soweit bestens.
                                            Schön wäre es noch wenn die Zahlen im deutschen Format übernommen würden, also 1.500,30 und nicht 1,500.30.
                                            Vielleicht klappt dann auch die Sortierung.
                                            Das "Namen" Feld wird richtig sortiert, nur die "Zahlen" Felder machen Probleme.

                                            Grüße

                                            liv-in-sky metaxa 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            767
                                            Online

                                            31.8k
                                            Users

                                            80.0k
                                            Topics

                                            1.3m
                                            Posts

                                            6
                                            78
                                            4366
                                            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