Solar Array and home energy dashboard.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

164 lines
3.1 KiB

  1. Highcharts.setOptions({
  2. time: {
  3. timezone: 'America/Los_Angeles',
  4. },
  5. lang: {
  6. thousandsSep: ',',
  7. },
  8. });
  9. socket.onopen = function() {
  10. // connected
  11. }
  12. var msgNumbs = {
  13. p: "#production",
  14. ng: "#netgrid",
  15. c: "#consumption",
  16. };
  17. function netgridcolor(v) {
  18. if (v <= 0)
  19. return "#00ff00";
  20. else
  21. return "#ff0000";
  22. }
  23. function afterSetExtremes(e) {
  24. // hack to deal w/ HighStocks being stupid
  25. if (Date.now() - solarchart.sd_lastwindata < 500) {
  26. // Make sure we trigger again, and that the user doesn't
  27. // have to wait too long
  28. solarchart.sd_lastwindata = Date.now() - 500;
  29. return;
  30. }
  31. solarchart.showLoading('Loading data from server...');
  32. console.log(e)
  33. socket.send('win ' + Math.round(e.min).toString() + ' ' + Math.round(e.max).toString());
  34. }
  35. socket.onmessage = function(m) {
  36. var msg = m.data.split(" ");
  37. if (msg[0] in msgNumbs) {
  38. // simple update values
  39. var num = parseFloat(msg[1]);
  40. var targ = $(msgNumbs[msg[0]]);
  41. targ.text(num.toString());
  42. // update color for ng
  43. if (msg[0] == "ng") {
  44. $(".gridpower").css('background', netgridcolor(num));
  45. }
  46. } else if (msg[0] == 'o') {
  47. // received overview data
  48. var data = JSON.parse(msg[1]);
  49. console.log(solarchart);
  50. solarchart.get('consumptionNav').setData(data.consumption, false);
  51. solarchart.get('gridNav').setData(data.grid, false);
  52. solarchart.get('productionNav').setData(data.production, false);
  53. solarchart.redraw();
  54. } else if (msg[0] == 'windata') {
  55. var data = JSON.parse(msg[1]);
  56. console.log(data);
  57. solarchart.sd_lastwindata = Date.now();
  58. solarchart.get('consumption').setData(data.consumption, false);
  59. solarchart.get('grid').setData(data.grid, false);
  60. solarchart.get('production').setData(data.production, false);
  61. solarchart.redraw();
  62. solarchart.hideLoading()
  63. }
  64. }
  65. var solarchart = Highcharts.stockChart('solarchart', {
  66. chart: {
  67. zoomType: 'x'
  68. },
  69. title: {
  70. text: 'Panel Production'
  71. },
  72. legend: {
  73. enabled: true,
  74. },
  75. subtitle: {
  76. text: document.ontouchstart === undefined ?
  77. 'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
  78. },
  79. navigator: {
  80. adaptToUpdatedData: false, // XXX - keep?
  81. series: [
  82. {
  83. type: 'bar',
  84. name: 'consumptionNav',
  85. id: 'consumptionNav',
  86. showInNavigator: true,
  87. data: [],
  88. },
  89. {
  90. type: 'bar',
  91. name: 'gridNav',
  92. id: 'gridNav',
  93. showInNavigator: true,
  94. data: [],
  95. },
  96. {
  97. type: 'bar',
  98. name: 'productionNav',
  99. id: 'productionNav',
  100. showInNavigator: true,
  101. data: [],
  102. },
  103. ]
  104. },
  105. xAxis: {
  106. events: {
  107. afterSetExtremes: afterSetExtremes,
  108. },
  109. type: "datetime",
  110. title: {
  111. enabled: false,
  112. },
  113. ordinal: false,
  114. },
  115. yAxis: {
  116. title: {
  117. text: 'W',
  118. }
  119. },
  120. tooltip: {
  121. split: true,
  122. valueSuffix: ' W',
  123. },
  124. plotOptions: {
  125. area: {
  126. //stacking: 'normal',
  127. lineColor: '#666666',
  128. fillOpacity: .25,
  129. lineWidth: 1,
  130. marker: {
  131. lineWidth: 1,
  132. lineColor: '#666666'
  133. }
  134. }
  135. },
  136. series: [
  137. {
  138. name: 'consumption',
  139. id: 'consumption',
  140. type: 'line',
  141. data: [ ],
  142. },
  143. {
  144. name: 'grid',
  145. id: 'grid',
  146. type: 'line',
  147. data: [ ],
  148. },
  149. {
  150. name: 'production',
  151. id: 'production',
  152. type: 'line',
  153. data: [ ],
  154. },
  155. ]
  156. });