• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Trying to write my own Module...

Scheduled Pinned Locked Moved Development
31 Posts 5 Posters 19.1k Views 5 Watching
Loading More Posts
  • 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.
  • M Offline
    mochman Module Developer
    last edited by Dec 26, 2016, 3:12 PM

    Looks like you need to modify your other if/then statement. The one you’ve modified checks both the name and watts to see if they are !=0. Since the name always !=0, it’s displayed.

    1 Reply Last reply Reply Quote 0
    • N Offline
      nbrenn
      last edited by Dec 28, 2016, 1:43 PM

      It looks like the values are not updating. (The wattage values didn’t change at all overnight).

      Should the line:

      setInterval(this.getCurrentData(), this.config_interval);
      

      be changed to:

      setInterval(this.getCurrentData(), this.interval);
      

      Are we calling the interval variable in the config incorrectly?

      Thanks!

      S 1 Reply Last reply Dec 28, 2016, 1:44 PM Reply Quote 0
      • S Offline
        strawberry 3.141 Project Sponsor Module Developer @nbrenn
        last edited by strawberry 3.141 Dec 28, 2016, 1:44 PM Dec 28, 2016, 1:44 PM

        @nbrenn this.config.interval

        Please create a github issue if you need help, so I can keep track

        1 Reply Last reply Reply Quote 2
        • N Offline
          nbrenn
          last edited by nbrenn Dec 28, 2016, 4:54 PM Dec 28, 2016, 4:51 PM

          For posterity, I modified the if statement as follows, to remove the row items that have a 0 for wattage:

          if (channels[i].children[n].textContent != 0) {
               element.innterHTML = channels[i].children[n].textContent;
               row.appendChild(element);
               table.appendChild(row);
          }
          else {
               table.removeChild(row);
          }
          
          1 Reply Last reply Reply Quote 1
          • M Offline
            mochman Module Developer
            last edited by Dec 28, 2016, 5:01 PM

            Glad it all worked out for you!

            1 Reply Last reply Reply Quote 0
            • N Offline
              nbrenn
              last edited by Dec 28, 2016, 10:50 PM

              I’m working on getting historical data (my API has a function getHistoricalData). The XML looks like the following:

              <Time Time="2016-11-03 00:00:00">
              <channel channel="194882" name="Main Power Main Panel">
              <kWh>0.319</kWh>
              </channel>
              <channel channel="194885" name="Outlet 1">
              <kWh>0.000</kWh>
              </channel>
              <channel channel="194886" name="Solar Panel 1">
              <kWh>-5.737</kWh>
              </channel>
              <channel channel="194887" name="Solar Panel 2">
              <kWh>-4.877</kWh>
              </channel>
              

              The difference between this XML output, and the XML output from my getCurrentData call, is that name is not it’s own element. With the old function, <name> was in brackets. Now, it is name = ....

              Would be getDom be the same as it was for getCurrentData, or is it different since it’s name= and not it’s own <name> ... </name>

              1 Reply Last reply Reply Quote 0
              • M Offline
                mochman Module Developer
                last edited by Dec 30, 2016, 1:22 AM

                You’re going to have to modify the code to get that info. Take a look here for info on how it’s done.

                N 2 Replies Last reply Dec 31, 2016, 4:56 PM Reply Quote 0
                • N Offline
                  nbrenn @mochman
                  last edited by Dec 31, 2016, 4:56 PM

                  @mochman Thanks for sharing the link to the w3 schools page! I managed to get it working by following the example on the website. Glad I learned something in the process! Happy New Year!

                  1 Reply Last reply Reply Quote 0
                  • N Offline
                    nbrenn @mochman
                    last edited by nbrenn Jan 13, 2017, 7:28 PM Jan 13, 2017, 7:12 PM

                    @mochman ->

                    How would I go about formatting my table? I would like to have each column have it’s own title, like “Load” and “kWh”. Is it also possible to put them into a tabulated table?

                    My getDOM currently looks like the following:

                    getDom: function(){
                            var wrapper = document.createElement("div");
                            if(!this.loaded) {
                                    wrapper.innerHTML = "Loading...";
                                    return wrapper;
                            }
                            if(this.xml !== null){
                    	 var table = document.createElement("table");
                             table.classList.add("xsmall", "table");
                             var channels = this.xml.getElementsByTagName("channel");
                             for(var i = 0; i < channels.length; i++){
                    	   var row = document.createElement("tr");
                               for(var n = 0; n < channels[i].children.length; n++){
                    		name = channels[i].getAttribute('name');
                    		if(channels[i].children[n].tagName === "kWh"){
                                    var element = document.createElement("td");
                    		element.classList.add(channels[i].children[n].tagName);
                    		if (channels[i].children[n].textContent != 0){
                    			element.innerHTML = name + channels[i].children[n].textContent;
                    			row.appendChild(element);
                    			table.appendChild(row);
                    			}
                    		}
                    		
                    		
                               
                    	   
                               }
                             }
                             wrapper.appendChild(table);
                            } else {
                                    console.log("Returned no Data");
                                    wrapper.innerHTML = "NO DATA";
                            }
                            return wrapper;
                       },
                    
                       parseXML: function(xmlStr){
                            return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml");
                       }
                    

                    0_1484333787480_screenshot.png

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      mochman Module Developer
                      last edited by Jan 13, 2017, 7:29 PM

                      You should just need to put

                      var row = document.createElement("tr");
                      var header = document.createElement("th");
                      var header2 = document.createElement("th");
                      header.innerHTML = "Load";
                      row.appendChild(header);
                      header2.innerHTML = "KWh";
                      row.appendChild(header2);
                      table.appendChild(row);
                      

                      before

                      var channels = this.xml.getElementsByTagName("channel");
                      

                      You can add a title by modifying your config.js file to add a header.
                      The documentation for that is here.

                      nbrennN 2 Replies Last reply Jan 13, 2017, 7:29 PM Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 3 / 4
                      • First post
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy