MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. nbrenn
    3. Posts
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    N Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 10
    • Posts 43
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: Trying to write my own Module...

      @mochman Thanks a lot! I’ll take a look at the documentation and try your suggestion.

      Have a good weekend!

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      @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

      posted in Development
      N
      nbrenn
    • Connecting to a MySQL Server to Retrieve Data

      Hi all,

      I have a MySQL server that is storing temperature sensor data that is being logged every second.

      I was wondering if anyone has any experience or knowledge of a suitable approach to retrieve this data from the MySQL server, process the data, and then provide me with an output?

      Let’s say, for example that I want it to display the average temperature from my sensor from 7am-8am on a particular day. I would like to connect in to the MySQL server, extract the data for that day, process the average, and then output it in some format on my mirror.

      Thanks for any preliminary guidance!

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      @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!

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      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>

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      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);
      }
      
      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      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!

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      I’m trying to display just the names where the watts that are != 0. I want both the values greater than 0 and the values less than 0 (in order to include the negative values from the solar generation).

      I attempted to modify the getDom. It is displaying every names in the .XML and shows the watts value only if it is != 0. But how do I also remove the names that are 0? The output currently looks like the following:

      Power Panel        66
      Outlets            20
      Heat Pump
      Oven   
      East Solar Panel  -70
      West Solar Panel  -50
      
      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++){
                      if(channels[i].children[n].tagName === "name" || channels[i].children[n].tagName === "watts"){
                      var element = document.createElement("td");
                      element.classList.add(channels[i].children[n].tagName);
                      if (channels[i].children[n].textContent != 0){
      			element.innerHTML = 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;
         },
      
      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      This is awesome.

      A few clarifying questions:

      • Is the purpose of the xhttp.open("GET"... line to make the API call to the website? Is this when the connection is made to the XML page?

      • So, you’re going through each "channel" and creating a row in the table for each channel? And then for each channel’s name and wattage, a data object is created?

      • If I didn’t have any .css file, would the data still show up?

      Thanks for the clarifications, and again, thanks for the great support. This community is top-notch!

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      Ahh, that makes sense. I do not have a node_helper.js, and I had the getCurrentData function because I tried to replicate a different module. I will remove these lines of code since they serve no purpose for me at the moment.

      I’ll try to take a look at examples to see how to save the data into the xml variable, so that this.xml can be used.

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      Thanks for the great support.

      I currently have no errors with what you’ve helped provide me with. However, it displays the else condition, and NO DATA.

      Right now, my MMM-EMonitor.js looks like the following:

      Module.register ("MMM-EMonitor", {
          
          //default module config.
          defaults: {
              // Insert defaults here
              interval: 900000 // Every 15 mins
          },
          
          getStyles: function() {
              return ["MMM-EMonitor.css"];
          },
          
          // Define the start sequence
          start: function() {
              Log.log("Starting module: " + this.name);
              
              //this.securitykey = REDACTED;
              this.url = 'https://api.emonitor.us/location/getCurrentData?security_key=REDACTED';
              this.getCurrentData(this);
          },
          
         getCurrentData: function(that) {
             that.sendSocketNotification('GET-CURRENT-DATA', that.url);
             setTimeout(that.getCurrentData, that.config.interval, that);
          },
          
      
         getDom: function(){
       	 var wrapper = document.createElement("div");
      
        	if(this.xml){
         	 var channels = this.xml.getElementsByTagName("channel");
         	 for(var i = 0; i < channels.length; i++){
          	   for(var n = 0; n < channels[i].children.length; n++){
             		if(channels[i].children[n].tagName === "name" || channels[i].children[n].tagName === "watts"){
                	var element = document.createElement("div");
                	element.classList.add(channels[i].children[n].tagName);
                	element.innerHTML = channels[i].children[n].textContent;
                	wrapper.appendChild(element);
              	}
            	}
          	}
        	} else {
          		wrapper.innerHTML = "NO DATA";
        	}
        	return wrapper;
      }
      });
      

      and my css looks like the following:

      .MMM-EMonitor .centered {
          text-align: center;
      }
      

      Like I mentioned, the NO DATA is showing up. The security key is working, and returns the XML which I have in my original post.

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      @strawberry-3.141 Thanks for the snippet! I have a better idea of how to extract the data from the XML with your example.

      If I want to simply output what you have provided in your post, would I need to simply put your snippet into my getDom() function and add the .name to my .css file (similar to how I have the .watts)?

      So I know that’s probably incorrect, but I just tried it and an error returned:
      Cannot read property getElementsByClassName of null. I think that I am having trouble understanding how to create the div object for which to add in the data.

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      @mochman
      Thanks for the response and the examples. Are some of the XML methods in the tutorial you linked to, often used in Mirror modules?

      I wasn’t planning on using a node_helper.js and my code does abruptly end in the middle of the getDOM(). I got stuck when trying to find out how to extract specifics from the XML, like <name> and <watts>.

      Do you know of any other good module examples that would have similar XML structure, where specific objects were extracted from?

      posted in Development
      N
      nbrenn
    • RE: Trying to write my own Module...

      @mochman
      Thanks for the link to the markdown page! My OP is edited accordingly. I do understand that I’m missing necessary code in order to make it function. I’m just not really sure what.

      I would like to print the <name> and <watts> if possible. The XML returned has a lot more data, but for the sake of this post, I cut it down to just include the first three items. I would like to print all three.

      posted in Development
      N
      nbrenn
    • Trying to write my own Module...

      Hi all,

      I am trying to write my own module from scratch and I am a bit of a crossroads of confusion. I have attached my .js code and my .css code is below. I am stuck trying to tie it all together. I have the output from a generic API call to the website I am getting data from, and I have a basic .js and .css file. However, with my lack of javascript experience, I am having trouble getting to the next level.

      The first basic thing I am trying to do is to display the current Watts that is output from the API call (the output of the call is shown below). I have the basic format of the .js file, and a basic format for my .css file. I was wondering if anyone can take a look at my .js file and let me know what else is needed in order to get something basic working (like just displaying the wattage).

      My .css file only contains the following:

      .watts {
      	font-size: 75%;
      	line-height: 65px;
      	display: inline-block;
      }
      

      The non-JSON format when I go to the following website (https://api.emonitor.us/location/getCurrentData?security_key=xxxxx) is as follows:

      <GetCurrentData>
      <Location Location="2744">
      <name>Home</name>
      <address>REDACTED</address>
      <city>REDACTED</city>
      <state>REDACTED</state>
      <country>USA</country>
      <zip>REDACTED</zip>
      <timezone>REDACTED</timezone>
      <data>
      <channelData>
      <channel channel="194882">
      <channelNumber>1 + 2</channelNumber>
      <eMonitorSerial>14881</eMonitorSerial>
      <name>Main Power Main Panel</name>
      <circuitType>Mains</circuitType>
      <phase/>
      <CTSize>150</CTSize>
      <BreakerSize>200</BreakerSize>
      <timestamp>2016-12-22 15:54:00</timestamp>
      <watts>-9</watts>
      </channel>
      <channel channel="194886">
      <channelNumber>5</channelNumber>
      <eMonitorSerial>14881</eMonitorSerial>
      <name>West Solar 1</name>
      <circuitType>Solar Panels</circuitType>
      <phase/>
      <CTSize>20</CTSize>
      <BreakerSize>20</BreakerSize>
      <timestamp>2016-12-22 15:54:00</timestamp>
      <watts>-165</watts>
      </channel>
      <channel channel="194887">
      <channelNumber>6</channelNumber>
      <eMonitorSerial>14881</eMonitorSerial>
      <name>West Solar 2</name>
      <circuitType>Solar Panels</circuitType>
      <phase/>
      <CTSize>20</CTSize>
      <BreakerSize>20</BreakerSize>
      <timestamp>2016-12-22 15:54:00</timestamp>
      <watts>-143</watts>
      </channel>
      <channel channel="194888">
      <channelNumber>7</channelNumber>
      <eMonitorSerial>14881</eMonitorSerial>
      <name>Both Bathroom Outlets</name>
      <circuitType>Outlets/Lighting</circuitType>
      <phase/>
      <CTSize>20</CTSize>
      <BreakerSize>20</BreakerSize>
      <timestamp>2016-12-22 15:54:00</timestamp>
      <watts>0</watts>
      </channel>
      <channel channel="194889">
      <channelNumber>8</channelNumber>
      <eMonitorSerial>14881</eMonitorSerial>
      <name>1st Floor Lights</name>
      <circuitType>Lighting</circuitType>
      <phase/>
      <CTSize>20</CTSize>
      <BreakerSize>15</BreakerSize>
      <timestamp>2016-12-22 15:54:00</timestamp>
      <watts>0</watts>
      </channel>
      </channelData>
      </data>
      </Location>
      <totalRecords>107</totalRecords>
      </GetCurrentData>
      

      Thanks for looking!

      The .js file I have written so far is below:

      Module.register ("MMM-EMonitor", {
          
          //default module config.
          defaults: {
              // Insert defaults here
              interval: 900000 // Every 15 mins
          },
          
          getStyles: function() {
              return ["MMM-Emonitor.css"];
          },
          
          // Define the start sequence
          start: function() {
              Log.info("Starting module: " + this.name);
              
              this.securitykey = REDACTED;
              this.url = 'https://api.emonitor.us/location/getCurrentData?security_key=' + this.SecurityKey
              this.getCurrentData(this);
          },
          
         getCurrentData: function(that) {
             that.sendSocketNotification('GET-CURRENT-DATA', that.url);
             setTimeout(that.getCurrentData, that.config.interval, that);
          },
          
          getDom: function() {
              var wrapper = null;
              
              if (this.loaded) { 
                  wrapper = document.createElement('div');
                      wrapper.className = 'data table';
      
      posted in Development
      N
      nbrenn
    • I have the API Documentation - Not sure next steps

      Hi all,

      The E-Monitor API specification has a listing of the supported API methods (page 3), like authenticate, deauthenticate, getCurrentData and so on.

      I’m not really sure where to go from here, as far as developing a module based on the API specification. Below, I have some of the very basic structure of the module, but I feel like I am out of my league when trying to write my own module.

      Module.resgister (“MMM-Emonitor.js”, {
      },

      getStyles: function() {
      },

      start: function() {
      },

      getDom: function() {
      },

      // And then the EMonitor methods below:
      authenticate: function() {
      }

      deauthenticate: function() {
      }

      getCurrentData: function() {
      }

      //… and so on down the list of the supported API methods

      posted in Requests
      N
      nbrenn
    • RE: Tutorials or Overview for Module Dev?

      Thanks for the responses, guys.

      The E-Monitor API specification has a listing of the supported API methods (page 3), like authenticate, deauthenticate, getCurrentData and so on.

      Aside from Module.register, getStyles, start: function(), and getDom, are these methods listed in the API specification the ones that I will use as functions in my code? For example:

      Module.resgister ("MMM-Emonitor.js", {
      },
      
      getStyles: function() {
      },
      
      start: function() {
      },
      
      getDom: function() {
      },
      
       // And then the EMonitor methods below:
      authenticate: function() { 
      }
      
      deauthenticate: function() {
      }
      
      getCurrentData: function() {
      }
      
      //... and so on down the list of the supported API methods
      
      posted in Development
      N
      nbrenn
    • Tutorials or Overview for Module Dev?

      I am looking to develop a module for my Mirror, for an Energy Monitor (SiteSage E-Monitor), and I have found the API specification that provides all of the information regarding the methods for the API.

      I was wondering if there exists a general overview of how to take the API methods that are outlined in the company’s specification, and turn it into a Module.

      From my high-level understanding, here is what I need to develop:

      • E-MonitorConfig.js
      • E-MonitorStyling.css --> which takes the data from the API call and turns it into the visualization for the magic mirror.

      Is there any general documentation or any high-level guidelines that I may be missing as I embark on this journey?

      posted in Development
      N
      nbrenn
    • RE: MMM-Nest only showing a Blank Black Screen

      I received the error:

      Load script: modules/MMM-Nest//MMM-Nest.js
      Failed to load resource: the server responded with a status of 404 (Not Found)

      What could be causing this error? A port issue? A token issue with the Nest API?

      posted in Troubleshooting
      N
      nbrenn
    • MMM-Nest only showing a Blank Black Screen

      When I entered the access token for the MMM-Nest Module, I am only seeing a blank black screen.

      When I comment out the Nest module, all of my other modules are working fine.

      I have my access token entered correctly, as far as I know. I’m just confused as to why I’d receive a blank black screen, with no other modules showing up either.

      Thanks for any ideas!

      posted in Troubleshooting
      N
      nbrenn
    • 1
    • 2
    • 3
    • 2 / 3