Git Product home page Git Product logo

discovergy-client's Introduction

Discovergy API client (PHP)

If you own a smart energy meter from Discovergy, this simple PHP client might a good starting point. The REST API provided by Discovergy provides endpoints to retrieve metadata about your smart meter, but -- more interesting -- also for your energy consumption and energy production.

This client concentrates on the measurements (energy consumption/production), but other endpoints can easily be added.

Why PHP?

Although Discovergy offers Java sources for demonstrating their API, I decided to provide a simple PHP script. I favor Java over PHP in nearly all situations, however, the main purpose of using the Discovergy API is more likely to be on a small hardware like a Raspberry Pi Nano (or IoT device) than on a fully-fledged web server with a JVM. Secondly, you can easily integrate the PHP script on your own low-cost website or private webserver.

Usage

API access

Accessing the API is (unfortunately!) possible only using your login credentials you get for the Discovergy web portal.

Create a file named credentials next to the PHP files. Line one needs to contain your username, line two your password. That's it.

Warning !
Having said this, make sure that none can access this file (set chmod to 400). You might also want to have a look into oauth1ClientBuilder.php and change the credential file location by altering CREDENTIALS_FILE value

Retrieving your energy consumption / production

The script is called by running main.php.

php main.php 

At the time of writing, only the first smart meter is considered:

$meters = $client->getMeters(); 

Using getReadings allows you to retrieve the energy values within a certain range given as UNIX timestamp in milliseconds (see below). Note that the API is limited to 200 values (if I remember correctly) per call. So if you want to get more values, you either need to repeat the call for the following time range. Or consider to use Discovergy's export function in the portal. I haven't tried that out so far but I assume that the data will be returned as CSV.

Units

  • Timestamps are interpreted by Discovergy in microseconds after 1.1.1970 and time zone is UTC
  • The energy consumption/production unit is given in mW (Milli Watt). So a value of 50600 means 50,6 Watts.
  • The method getReadings has a default argument $resolution='three_minutes'. If you need more precise values, pass 'raw' as argument (see the API docs for further values).
  • A negative Watt measurement means 'energy produced', otherwise it's consumed (taken from the power grid)
  • By default all responses are output in JSON

Example output

The output shown below refers to the energy consumption from Oct.25th 2020 at about 17:12h local time, when it was pretty cloudy ;-)

Image of energy diagram

$energyProduced = $client->getReadings($meterId, $fieldPower, 1603551620000, 1603552320000, 'raw');

... results in ...

[
  {
    "time": 1603551635519,
    "values": {
      "power": 92600
    }
  },
  {
    "time": 1603551679530,
    "values": {
      "power": 91700
    }
  },
  {
    "time": 1603551718706,
    "values": {
      "power": 109000
    }
  },
  {
    "time": 1603551803565,
    "values": {
      "power": 143600
    }
  },
  {
    "time": 1603551846699,
    "values": {
      "power": 146900
    }
  },
  {
    "time": 1603551875508,
    "values": {
      "power": 141800
    }
  },
  {
    "time": 1603551926697,
    "values": {
      "power": 140800
    }
  },
  {
    "time": 1603551958710,
    "values": {
      "power": 136200
    }
  },
  {
    "time": 1603551997897,
    "values": {
      "power": 127200
    }
  },
  {
    "time": 1603552045906,
    "values": {
      "power": 84700
    }
  },
  {
    "time": 1603552084297,
    "values": {
      "power": 55000
    }
  },
  {
    "time": 1603552129113,
    "values": {
      "power": 24800
    }
  },
  {
    "time": 1603552163510,
    "values": {
      "power": 37900
    }
  },
  {
    "time": 1603552209918,
    "values": {
      "power": 50600
    }
  },
  {
    "time": 1603552249095,
    "values": {
      "power": 13700
    }
  },
  {
    "time": 1603552285098,
    "values": {
      "power": -1400
    }
  },
  {
    "time": 1603552315495,
    "values": {
      "power": 8400
    }
  }
]

Contact

Pull requests and improvements are welcome anytime. See my homepage (https://GeorgStach.de) for contact options.

discovergy-client's People

Contributors

geooorg avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

stephanhuewe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.