MMM-EMonitor.js
Module.register ("MMM-EMonitor", {
//default module config.
defaults: {
// Insert defaults here
interval: 900000, // Every 15 mins
security_key: null,
animationSpeed: 1000
},
getStyles: function() {
return ["MMM-EMonitor.css"];
},
// Define the start sequence
start: function() {
Log.log("Starting module: " + this.name);
this.loaded = false;
this.xml = null;
this.url = 'https://api.emonitor.us/location/getCurrentData?security_key=';
setInterval(this.getCurrentData(), this.config_interval);
},
getCurrentData: function() {
var self = this;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
self.xml = self.parseXML(this.responseText);
self.loaded = true;
self.updateDom(self.config.animationSpeed);
}
};
xhttp.open("GET", this.url+this.config.security_key, true);
xhttp.send();
},
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);
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;
},
parseXML: function(xmlStr){
return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml");
}
});
Your config.js should have:
{
module: 'MMM-EMonitor',
position: 'top_left',
config: {
security_key: 'XXXXXXXXXXXXXXX' //your security key
}
}
This just displays everything in a large table. You may want to modify the for loop to not display data when the wattage is 0, that should get rid of a bunch of rows.