<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Monitoring electricity consumption]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I've set up an electricity monitoring node, which basically counts pulses from my power meter (see <a href="https://www.mysensors.org/build/pulse_power" rel="nofollow ugc">https://www.mysensors.org/build/pulse_power</a>) and it's working fine. But, it sends electricity consumption as kwh. What I'd like to do is to summarise this as watts each hour, so that you can see the consumption for each hour. I could calculate this in the sensor, but I was wondering if you could do something within mycontroller. So, for example each hour, find the total kwh used, and plot that. That way you can more easily see which periods of the day use more power than others.</p>
<p dir="auto">Is this the sort of thing you can do within <a href="http://MyController.org" rel="nofollow ugc">MyController.org</a>?</p>
]]></description><link>http://forum.mycontroller.org/topic/85/monitoring-electricity-consumption</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 07:24:48 GMT</lastBuildDate><atom:link href="http://forum.mycontroller.org/topic/85.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Dec 2016 10:28:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Monitoring electricity consumption on Wed, 25 Jan 2017 02:19:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rjad" aria-label="Profile: rjad">@<bdi>rjad</bdi></a></p>
<blockquote>
<p dir="auto">Ok,I tested this but couldn't get it to work. Presumably I didn't follow the instructions properly.</p>
</blockquote>
<p dir="auto">When you do changes on HTML additional headers, you have to reload the browser. I hope you did this.</p>
<blockquote>
<p dir="auto">With some work it could be better, so for example, I lose the hover information, I had trouble getting two of these plots on one dashboard with different bins.</p>
</blockquote>
<p dir="auto">For hover information, I do nit get any clue. As I never worked directly with the D3 chart.<br />
For the multiple of charts on same dashboard issue, you might have chart id issue.<br />
Maybe because of this one,</p>
<pre><code> &lt;canvas id="simpled3" style="display: none;"&gt;&lt;/canvas&gt;
</code></pre>
]]></description><link>http://forum.mycontroller.org/post/592</link><guid isPermaLink="true">http://forum.mycontroller.org/post/592</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Wed, 25 Jan 2017 02:19:59 GMT</pubDate></item><item><title><![CDATA[Reply to Monitoring electricity consumption on Tue, 24 Jan 2017 10:44:06 GMT]]></title><description><![CDATA[<p dir="auto">Ok,I tested this but couldn't get it to work. Presumably I didn't follow the instructions properly. To try to understand it better, and to amuse myself, I wrote a script to do what I want, more or less. I use a javascript script to grab the data that I want:</p>
<pre><code class="language-javascript">// so you can optionally pass the bindings
// {'binHours': 12, 'nBins': 12} 
// but if you don't doesn't matter.

var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);

with(myImports) {

var sVar = mcApi.uidTag().getByUid("kwh_uid").getSensorVariable(); 
var powerUsed = [];
var endTimes = [];

// check for some possible bindings:
if( typeof binHours === 'undefined' || !binHours ) {
  var binHours = 1
}

if( typeof nBins === 'undefined' || !nBins ) {
  var nBins = 5;
}
var binDuration = 1000*60*60*binHours;  //  hours in milliseconds

var endTime =  Date.now();
var startTime;

for(var i=0; i&lt; nBins; i++ ) {
  startTime = endTime - binDuration;
  minMaxData = mcApi.metric().getSensorVariableMetricDouble(sVar, startTime, endTime); 
  powerUsed[i] = minMaxData.maximum - minMaxData.minimum;
  endTimes[i] = endTime.toString();
  endTime = startTime;
  }
}
</code></pre>
<p dir="auto">And a template using d3.js:</p>
<pre><code class="language-html">
&lt;link rel=stylesheet type="text/css" href="myd3.css"&gt;
&lt;div id="wrapper" style="text-align: center"&gt;    
  &lt;canvas id="simpled3" style="display: none;"&gt;&lt;/canvas&gt;
  &lt;div style="font-size:11px" id="viz"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script&gt;

var margin = {
    top: 15,
    right: 20,
    bottom: 30,
    left: 30
};
var width = 900- margin.left - margin.right;
var height = 360 - margin.top - margin.bottom;

// we get the data from the script

var x = d3.time.scale().range([0, width]);
var y = d3.scale.linear().range([height, 0]);

var xAxis = d3.svg.axis().scale(x)
    .orient("bottom").ticks(5);

var yAxis = d3.svg.axis().scale(y)
    .orient("left").ticks(5);

var valueline = d3.svg.line()
     .interpolate("step-before")   
    .x(function (d) {
      return x(d.date);
    })
    .y(function (d) {
      return y(d.watts);
    });
    
var svg = d3.select("#viz")
    .append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
   .attr("style", "outline: thin solid black;")
    .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

// Get the data
// should look like an array
// with each element date: milliseconds, watts: double
//

var data = [];
// get the values from the hash
// being careful of the indices which 
// turn out to be character strings
var hashIndex;

&lt;#list endTimes?keys as k&gt;
 hashIndex = +${k};
 data[hashIndex] = {date: new Date(+${endTimes[k]}),
                    watts: +${powerUsed[k]}}
&lt;/#list&gt;

// Scale the range of the data
x.domain(d3.extent(data, function (d) {
    return d.date;
    }));
y.domain([0, d3.max(data, function (d) {
    return d.watts;
    })]);

svg.append("path") // Add the valueline path.
.attr("d", valueline(data));

svg.append("g") // Add the X Axis
.attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    .call(xAxis);

svg.append("g") // Add the Y Axis
.attr("class", "y axis")
    .call(yAxis);
&lt;/script&gt;
</code></pre>
<p dir="auto">Some settings are in the custom css file. You can then create a plot, specifying the size in hours of each bin (1 hour by default), and the number of bins to plot. It looks like:</p>
<p dir="auto"><img src="http://i.imgur.com/2tl4MPv.png" alt="electricity cosumption" class=" img-fluid img-markdown" /></p>
<p dir="auto">So you can see when we get up in the mornings and when we cook tea in the evenings <img src="http://forum.mycontroller.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f609.png?v=49d1c908e56" class="not-responsive emoji emoji-android emoji--wink" style="height:23px;width:auto;vertical-align:middle" title=";-)" alt="😉" /></p>
<p dir="auto">With some work it could be better, so for example, I lose the hover information, and I had trouble getting two of these plots on one dashboard with different bins. But I'm not too worried, since at the moment my main concern is why the sensor keeps dropping out. When I work out my hardware issues I might try to do better with the software.</p>
<p dir="auto">Thanks<br />
Robert</p>
]]></description><link>http://forum.mycontroller.org/post/584</link><guid isPermaLink="true">http://forum.mycontroller.org/post/584</guid><dc:creator><![CDATA[rjad]]></dc:creator><pubDate>Tue, 24 Jan 2017 10:44:06 GMT</pubDate></item><item><title><![CDATA[Reply to Monitoring electricity consumption on Tue, 07 Feb 2017 11:55:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rjad" aria-label="Profile: rjad">@<bdi>rjad</bdi></a> Following setup will fulfil your requirement,</p>
<h5>Steps:</h5>
<ul>
<li>Added <code>ng-controller</code> script to get data from MyController. Add this script on <code>Utilities &gt;&gt; HTML additional headers &gt;&gt; AngularJS custom controllers</code>. All the following script.</li>
</ul>
<pre><code>myControllerModule.controller('McCustomGraph', function($scope, $interval, mchelper, $filter, MetricsFactory, TypesFactory, CommonServices){
    $scope.cs = CommonServices;
    $scope.updateChart = function(chData){
      chData.showError = false;
      chData.showLoading = true;
      MetricsFactory.getMetricsData(
      {"variableId":chData.variableId, "withMinMax":chData.withMinMax, "start": new Date().getTime() - (chData.lastNseconds*1000), "bucketDuration": chData.bucketDuration}, function(resource){
        if(resource.length &gt; 0){
          var customGraph = {};
          customGraph.chartOptions = {
              chart: {
                  type: 'lineChart',
                  noErrorCheck: true,
                  height: 225,
                  margin : {
                      top: 5,
                      right: 20,
                      bottom: 60,
                      left: 65
                  },
                  color: ["#2ca02c","#1f77b4", "#ff7f0e"],
                  noData:"No data available.",
                  x: function(d){return d[0];},
                  y: function(d){return d[1];},
                  useVoronoi: false,
                  clipEdge: false,
                  useInteractiveGuideline: true,
                  xAxis: {
                      showMaxMin: false,
                      tickFormat: function(d) {
                          return d3.time.format('hh:mm a')(new Date(d))
                      },
                      //axisLabel: 'Timestamp',
                      rotateLabels: -20
                  },
                  yAxis: {
                      tickFormat: function(d){
                          return d3.format(',.2f')(d);
                      },
                      axisLabelDistance: -10,
                      //axisLabel: ''
                  },
              },
                title: {
                  enable: false,
                  text: 'Title'
              }
          };

          customGraph.chartTimeFormat = mchelper.cfg.dateFormat;
          customGraph.chartOptions.chart.xAxis.tickFormat = function(d) {return $filter('date')(d, customGraph.chartTimeFormat, mchelper.cfg.timezone)};
          
          
           customGraph.chartData = resource[0].chartData;
          //Update display time format
          customGraph.chartTimeFormat = resource[0].timeFormat;
          customGraph.chartOptions.chart.type = resource[0].chartType;
          customGraph.chartOptions.chart.interpolate = resource[0].chartInterpolate;

          if(resource[0].dataType === 'Double'){
            customGraph.chartOptions.chart.yAxis.tickFormat = function(d){return d3.format('.02f')(d) + ' ' + resource[0].unit};
          }else if(resource[0].dataType === 'Binary' || resource[0].dataType === 'Counter'){
            customGraph.chartOptions.chart.yAxis.tickFormat = function(d){return d3.format('.0f')(d)};
          }
          customGraph.chartOptions.title.text = resource[0].variableType;
          customGraph.resourceName = resource[0].resourceName;
          customGraph.internalId = resource[0].internalId;
          chData.showLoading = false;
          chData.customGraph = customGraph;
        }else{
            chData.showError = true;
        }
      });
    }
  });
</code></pre>
<ul>
<li>Create custom HTML template to display our chart. Create it on <code>Utilities &gt;&gt; Templates &gt;&gt; Add template</code></li>
</ul>
<pre><code>&lt;div ng-app="myController" ng-controller="McCustomGraph" ng-init="chData={'variableId': ${item.variableId}, 'withMinMax':${(item.withMinMax?c)!"false"}, 'lastNseconds':'${(item.lastNseconds?c)!"86400"}', 'bucketDuration':'${(item.bucketDuration)!"1h"}', 'showLoading':true};updateChart(chData);"&gt;
  &lt;!-- Loading icon disaplay --&gt;
  &lt;div ng-if="chData.showLoading"&gt;
    &lt;div ng-include src="'partials/common-html/loading-sm.html'"&gt;&lt;/div&gt;
  &lt;/div&gt;

  &lt;div ng-if="chData.showError"&gt;
    &lt;div ng-include src="'partials/common-html/error-sm.html'"&gt;&lt;/div&gt;
  &lt;/div&gt;

  &lt;div ng-if="!(chData.showLoading || chData.showError)"&gt;
    &lt;span class="mc-pointer" ng-bind-html="chData.customGraph.resourceName | mcResourceRepresentation" ui-sref="sensorsDetail({id: chData.customGraph.internalId})"&gt;&lt;/span&gt;
    &lt;nvd3 id="asg-{{chData.variableId}}" options='chData.customGraph.chartOptions' data="chData.customGraph.chartData"&gt;&lt;/nvd3&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>
<ul>
<li>
<p dir="auto">Create dummy script to support bindings on template. When we use bindings, we can reuse the same script for multiple sensorVariables<br />
<img src="/uploads/files/1482765690488-upload-cca1cae6-5ba3-41ca-a562-94ccfa887001" alt="0_1482765689323_upload-cca1cae6-5ba3-41ca-a562-94ccfa887001" class=" img-fluid img-markdown" /></p>
</li>
<li>
<p dir="auto">Now get <code>SensorVariable</code> id from Sensors page. <code>Resources &gt;&gt; Sensors &gt;&gt; Click on view details</code>,<br />
<img src="/uploads/files/1482765836776-upload-d79d7e6b-d0f6-4bc6-b6b6-0366b8968b09" alt="0_1482765833386_upload-d79d7e6b-d0f6-4bc6-b6b6-0366b8968b09" class=" img-fluid img-markdown" /><br />
Now click on edit of <code>sensor variable</code><br />
<img src="/uploads/files/1482765894649-upload-5797ae73-a6ee-4dec-b810-928013f4c2d3" alt="0_1482765892413_upload-5797ae73-a6ee-4dec-b810-928013f4c2d3" class=" img-fluid img-markdown" /></p>
</li>
</ul>
<p dir="auto">On the URL you can see sensor variable id, This is id is <strong>important</strong> note it for your target <code>sensor variable</code><br />
<img src="/uploads/files/1482765976080-upload-1240a386-2016-4a96-b144-d2444df9fc73" alt="0_1482765974523_upload-1240a386-2016-4a96-b144-d2444df9fc73" class=" img-fluid img-markdown" /></p>
<ul>
<li>Now it is time to display your custom graph,<br />
<img src="/uploads/files/1482766978298-upload-4003d37e-d81e-42e8-ae67-fae17b66977d" alt="0_1482766977224_upload-4003d37e-d81e-42e8-ae67-fae17b66977d" class=" img-fluid img-markdown" /></li>
</ul>
<p dir="auto">Bindings:</p>
<pre><code>{"item":{'variableId': 99, 'withMinMax':false, 'lastNseconds':86400, 'bucketDuration':'1h'}}
</code></pre>
<p dir="auto"><strong>Note:</strong> Script binding details,</p>
<ul>
<li><code>variableId</code> - This is your target sensor variable id</li>
<li><code>lastNseconds</code> - value as integer (Example:  <code>"lastNseconds":86400</code> and this is default value)</li>
<li><code>withMinMax</code> - default, <code>false</code></li>
<li><code>bucketDuration</code> - This is the value to group data. Supports for, <code>raw</code>, <code>1mn</code> - minute, <code>1h</code> - hour, <code>1d</code>- day, <code>1m</code> - month</li>
<li>Example: <code>1h</code> - 1 hour, <code>6h</code> - 6 hours, <code>5mn</code> - 5 minutes, <code>7d</code> - 7 days</li>
</ul>
<ul>
<li>Now all set ready, you can see the chart as follows <img src="http://forum.mycontroller.org/assets/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=49d1c908e56" class="not-responsive emoji emoji-android emoji--smile" style="height:23px;width:auto;vertical-align:middle" title=":smile:" alt="😄" /></li>
</ul>
<p dir="auto"><img src="/uploads/files/1482765380667-upload-d660650c-7176-4ded-a0a8-6fb7e23bbb9c" alt="0_1482765379147_upload-d660650c-7176-4ded-a0a8-6fb7e23bbb9c" class=" img-fluid img-markdown" /></p>
]]></description><link>http://forum.mycontroller.org/post/440</link><guid isPermaLink="true">http://forum.mycontroller.org/post/440</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Tue, 07 Feb 2017 11:55:18 GMT</pubDate></item><item><title><![CDATA[Reply to Monitoring electricity consumption on Sun, 25 Dec 2016 05:06:39 GMT]]></title><description><![CDATA[<p dir="auto">Thanks jkandasa,<br />
I'd be happy to get any tips on using bucketDuration, so let me know how you go. No rush though obviously.</p>
]]></description><link>http://forum.mycontroller.org/post/435</link><guid isPermaLink="true">http://forum.mycontroller.org/post/435</guid><dc:creator><![CDATA[rjad]]></dc:creator><pubDate>Sun, 25 Dec 2016 05:06:39 GMT</pubDate></item><item><title><![CDATA[Reply to Monitoring electricity consumption on Sun, 11 Dec 2016 14:01:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rjad" aria-label="Profile: rjad">@<bdi>rjad</bdi></a> In graph there is no direct way for this. however we can get metrics by <code>bucketDuration</code>, I will check this in custom widget and update you soon.</p>
<p dir="auto">Sorry for the late response, I was out off action last few days. Thanks!</p>
]]></description><link>http://forum.mycontroller.org/post/392</link><guid isPermaLink="true">http://forum.mycontroller.org/post/392</guid><dc:creator><![CDATA[jkandasa]]></dc:creator><pubDate>Sun, 11 Dec 2016 14:01:17 GMT</pubDate></item></channel></rss>