/enlighten-api-node

Enphase Enlighten System API sample code in NodeJS

Primary LanguageJavaScriptGNU General Public License v2.0GPL-2.0

##NodeJS Enphase Enlighten Systems API Sample

Sample code and library for NodeJS. Uses the Express application framework with Jade templates.

The interactions with the API are handled by an enphase.js library that could be added to your project.

Motivation

To provide an example of how to integrate a NodeJS project with the Enphase Enlighten Systems API and create a simple integration library.

Installation

  1. Set your Enphase API key and Application Id environment variables. You can find these by logging into your Enphase developer account and selecting your application. The App id is the last part of the Authorization URL.

Quick set for the current session in a bash shell (replace with your info):

export ENPHASE_API_KEY='3aaa01a221a6603a71853fc1cc2c3a5b'
export ENPHASE_APP_ID='140961117xxxx'

To set permanently add it to your .profile or similar setup depending on your system and server configuration.

  1. Install NodeJS. Run the following if on a Mac or visit the NodeJS website to install.
brew install node
  1. Clone the repo
git clone https://github.com/path_to_project
  1. Start the node server
node ./bin/www
  1. Visit http://localhost:3000 in your web browser

Example

Assuming you have your environmental variables set up, you first require the enphase library:

var enphase = require('../lib/enphase');

Then query the Enphase Enlighten Systems API by instantiating a new enphase.Request object. The simplest request is for a user's systems:

new enphase.Request({
  api: 'systems',
  userId: user.id,
  success: function(data) {
    res.render('systemsResponse', data);
  },
  error: function(data) {
    res.render('error', data);
  }
});

The most elaborate will have a systemId and query:

new enphase.Request({
  api: 'systems',
  userId: '4d7a45774e6a41320a',
  systemId: 67,
  query: { start_date: '2015-01-01' },
  success: function(data) {
    res.render('response', data);
  },
  error: function(data) {
    res.render('error', data);
  }
});

You can also access the enphase api vars directly from the enphase object:

var enphaseAuthUrl = enphase.auth,
    enphaseApiKey = enphase.key;

Author

Jamie Ruderman for Enphase.

License

GNU General Public License