“Alexa, what’s my energy usage?” Or how to get real-time data out of your smart meter and onto the cloud

Let’s get a simple service up to bring your real-time smart meter data up to Amazon AWS. There are a couple of things you will need: 1) Rainforest Automation Eagle 100/200 device, 2) an Amazon AWS account, and 3) an Amazon Echo so we can have a little fun. You’ll want to be familiar with creating Lambda functions and also be able to create simple Amazon Alexa Skills to be able to digest the information here.

We’ll want to set up the Eagle with Rainforest Cloud through their Relay API. An AWS Lambda function will do direct external API call to your Relay API account. For fun, we’ll create an Alexa Skill so you can know how much your smart meter is measuring your usage, just by asking!

Installing an Eagle

The Rainforest Automation Eagle 100/200 is a ZigBee Smart Energy Profile 1.1 gateway device. It creates a radio connection on the 2.4GHz band to your smart meter, at one of 11 channels within that band . I live in the Pacific Gas and Electric service territory, under a residential contract, so I can have a pge.com online MyAccount access various utility services, including access to set-up my smart meter with ZigBee Smart Energy devices. That service is called Stream My Data.

What’s ZigBee Smart Energy Profile 1.1?

Eons ago (well, maybe five years ago in wireless technology timescales), ZigBee Smart Energy Profile (ZSEP) was the “big” thing for electric utilities — enable a direct connection with your smart meter and do all sorts of things. The California utilities equipped and enabled the ZSEP for all their residential smart meters. For PG&E, that’s a full 5.1 million meters with this capability. Unfortunately, the private industry never ran with it and so these meters have a neat capability that’s sitting there, waiting for someone to come along and make great use of them.

How do you use ZSEP?

To access your meter’s ZSEP capability, you need to get some hardware. Currently there are just a handful of devices vendors out there selling devices over retail channels. Rainforest Automation’s Eagle gateway is one of them. You can get one at the Amazon online shop for about a hundred dollars; the current device is the Eagle 200. I have an Eagle 100 so that’s what I’m going to base the description on.

The Eagle is a little box with a ZigBee 2.4 GHz radio and ZSEP functionality running on its embedded processor. It also has an Ethernet port to send data on to the Rainforest Cloud service. Here is the high level view of what you’ll need to do.

  1. “Provision” your smart meter to accept the Eagle connection
  2. Set up your Eagle’s Rainforest Cloud with your credentials and device information
  3. Prepare some serverless Lambda functions to access your Rainforest Cloud account by using a RESTful API.

Provisioning will be different for each electric utilities’ smart grid system configuration so my description is based on PG&E’s processes. Setting up the Rainforest Cloud is common to all users of their service and pretty simple.

Provisioning your Smart Meter

The smart meter’s radio needs to know your Rainforest Eagle device’s MAC address and Install Code (IC) values. When those two pieces of information are registered onto the smart meter micro-controller, that specific Rainforest Eagle becomes whitelisted for a secure wireless connection. I did that by accessing PG&E’s online portal after logging on to MyAccount, following the link on the dashboard to Stream My Data.

You’ll want to follow your utilities’ procedure here. But once your Eagle is connected to the smart meter, the data is there over the Rainforest Relay API to be polled and retrieved into an AWS functionality.

Setting up Rainforest Cloud

Please refer to the Rainforest Relay API for directions:

https://rainforestautomation.com/wp-content/uploads/2015/07/EAGLE_REST_API-1.1.pdf

You can try using Postman to directly access the URL for the RainforestCloud Relay API, using the following header and HTTP method:

POST https://rainforestcloud.com:9445/cgi-bin/post_manager

Host: server.rainforestautomation.com
Accept: */*
Content-Type: text/xml
Content-Length: 80
Cloud-Id: [your_cloudId]
Password: [your_password]
User: [your_username]
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

And a REQUEST BODY:

<Command>
<Name>get_instantaneous_demand</Name>
 <MacId>[your_Eagle_MAC_Address]</MacId>
 <Format>JSON</Format>
</Command>

A successful POST will generate a response of the following:

<InstantaneousDemand>
<DeviceMacId>[your_Eagle_MAC_Address]</DeviceMacId>
<MeterMacId>[your_Smart_Meter_MAC_Address]</MeterMacId>
<TimeStamp>0x22225dc0</TimeStamp>
<Demand>0x000700</Demand>
<Multiplier>0x00000001</Multiplier>
<Divisor>0x000003e8</Divisor>
<DigitsRight>0x03</DigitsRight>
<DigitsLeft>0x0f</DigitsLeft>
<SuppressLeadingZero>Y</SuppressLeadingZero>
</InstantaneousDemand>

The <demand>[value]</demand> tag is where the real-time kilowatt value of electricity resides. The Multiplier and Divisors are applied on the value to give the true measured value. The DigitsRight and DigitsLeft indicate how many digits there are from the decimal point (1792 * 1 /1000 KW) = 1.792KW. The timestamp gives the Unix UTC timestamp of the electricity reading (e.g. Friday 23rd February 2018 05:49:41 AM).

Getting the demand data into Amazon Web Services

Having your smart meter data available on AWS opens up a whole world of possibilities. We could do streaming data analysis, store the usage for later batch analysis, etc., etc. Here, we’ll enable the read to happen from a serverless Lambda function, which doubles as the Intent in our Amazon Alexa Skill.

Alexa Skill and Intent

Create an Alexa Skill on the Alexa Skill Developer Console.

  1. Name your skill (in this example, it is getUsage, the name of the Intent)
  2. Take a note of the Skill ID (this will be your Skill App Id)
  3. Decide on the invocation (in this example, it is “Open my Usage”

External Lambda call to RainforestCloud Relay API

An HTTPS method POST to URL “rainforestcloud.com:9445/cgi-bin/post_manager”, at port 9445, with a specific header and request body generates a response from the API in XML of above. We want to enable an AWS Lambda function to do that HTTPS Post upon a trigger from an Alexa Skill. The javascript code below is that Intent, getUsage, for use in the Skill.

That’s it for now :)