Skip to content

Add a kWh counter #2

Description

@sander

It seems that the kWh field in powerinfo() contains the measurement over the last 8 seconds. It would be nice if plugwisejs uses this information to also offer a method to get the total usage since a certain moment.

In this case, the library should keep track of an accumulated kWh value, make sure measurement intervals have enough overlap to not miss any data and account for that overlap. (If I’m not mistaken – I still don’t fully understand the Plugwise protocol.)

The API could enable code like this:

var plugwise = require('plugwisejs').init({ serialport: '/dev/tty.usbserial-A80060FG' });
var circle = plugwise('000D6F0000AF7512');
var stopAt = 5.0; // kWh
circle.startAccumulating(); // set the accumulated value to 0 kWh, starts the loop
var interval = setInterval(function() {
  circle.getEnergy(function(kWh) {
    console.log('Energy since start:', kWh, 'kWh');
    if (kWh > stopAt) {
      circle.stopAccumulating();
      clearInterval(interval);
    }
  });
}, 1000);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions