Read the statement by Michael Teeuw here.
Trying to write my own Module...
-
- yes the xmlhttprequest is also better known as ajax request
- for each channel a row will be created and for name and watts a column will be created with their specific values
- the data will still be displayed, but without any custom styling
-
I’m trying to display just the
names
where thewatts
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 everynames
in the .XML and shows thewatts
value only if it is != 0. But how do I also remove thenames
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; },
-
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.
-
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!
-
@nbrenn
this.config.interval
-
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); }
-
Glad it all worked out for you!
-
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 thatname
is not it’s own element. With the old function,<name>
was in brackets. Now, it isname = ...
.Would be
getDom
be the same as it was forgetCurrentData
, or is it different since it’sname=
and not it’s own<name> ... </name>
-
You’re going to have to modify the code to get that info. Take a look here for info on how it’s done.
-
@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!