Rainforest Eagle to Emoncms

I was originally introduced to emoncms with my openevse. I already had a rainforest eagle collecting data from my home energy use, but didn’t know how to get the data up to the emoncms cloud to log.

Luckily, someone wrote a python module (GitHub - rainforestautomation/Eagle-Http-API: Libraries for accessing Rainforest Automation's Eagle hardware) to interface with the rainforest-eagle API. UNfortunately, I don’t know how to write a script to save my life.

I paid a fellow on guru dot com to write my python script and now I have data from my rainforest-eagle monitor writing up to the emoncms cloud.

The necessary links are provided above and here is the script:

#!/usr/bin/python
import getopt
import sys
from eagle_http import *
import urllib

usage = r'''
NAME
    rainforest_emon.py - Get data from rainforest and post it to emoncms.org

SYNOPSIS
    rainforest_emon.py [OPTIONS]

OPTIONS
    --verbose
        Print verbose information.
    --rf-user
        Rainforest username
    --rf-pass
        Rainforest password
    --rf-clid
        Rainforest cloud id
    --emon-key
        emoncms.org api key

'''

verbose    = 0
rainforest = {}
emonkey    = ''

def parseargs():
        global verbose
        global rainforest
        global emonkey

        try:
                opts, configfiles = getopt.gnu_getopt(sys.argv[1:], 'hv', ['help', 'verbose', 'rf-user=', 'rf-pass=', 'rf-clid=', 'emon-key='])
        except getopt.GetoptError as err:
                print str(err)
                print usage
                sys.exit(1)
        for o, a in opts:
                if o in ('-h', '--help'):
                        print(usage)
                        sys.exit(0)
                elif o in ('-v', '--verbose'):
                        verbose = verbose + 1
                elif o in ('--rf-user', '--rf-pass', '--rf-clid'):
                        rainforest[o[5:]] = a
                elif o == '--emon-key':
                        emonkey = a
                else:
                        print 'Invalid option: %s' % (o)
                        sys.exit(1)

if __name__ == '__main__':

        parseargs()

        if not all (p in rainforest for p in ('user', 'pass', 'clid')) or emonkey == '':
                print usage
                sys.exit(1)

        if verbose > 0:
                print 'Retrieving values from rainforest'

        eagle = eagle_http(rainforest['user'], rainforest['pass'], rainforest['clid'])
        eagle.get_instantaneous_demand()

        demand      = int(eagle.InstantaneousDemand.Demand, 0)
        if demand & 0x10000:
                demand = -((demand ^ 0xffffffff) + 1)
        multiplier  = int(eagle.InstantaneousDemand.Multiplier, 0)
        divisor     = int(eagle.InstantaneousDemand.Divisor, 0)
        timestamp   = int(eagle.InstantaneousDemand.TimeStamp, 0)
        calc_demand = (0.0 + demand) * multiplier / divisor

        if verbose > 0:
                print 'Demand: %d' % (demand)
                print 'Multiplier: %d' % (multiplier)
                print 'Divisor: %d' % (divisor)
                print 'Timestamp: %d' % (timestamp)
                print 'Calc_demand: %f\n' % (calc_demand)

        f = urllib.urlopen('https://emoncms.org/input/post.json?node=RainforestEagle&csv="Calculated Demand":%f,"Raw TimeStamp":%d,"Raw Demand":%d,"Raw Multiplier":%d,"Raw Divisor":%d&apikey=%s' % (calc_demand, timestamp, demand, multiplier, divisor, emonkey))

        if verbose > 0:
                print f.geturl(), '\n'

        if f.getcode() == 200:
                if verbose > 0:
                        print f.read()
                exit(0)
        else:
                print "%s returned code %s:" % (f.geturl(), f.getcode())
                print f.read()
                exit(1)
1 Like

Nice, I’ve not heard of Rainforest Eagle (cool name!)

Is this the unit?

https://rainforestautomation.com/rfa-z114-eagle-200/

That is the one. Its had its ups and downs, I purchased it a couple of years ago, but its been pretty stable since they moved to cloud based storage about a year or so ago.

I have the same device but an older version purchased in June 2016. Mine is the RFA-Z109.

I set it up with the Node-RED flow Rainforest Eagle Smart Meter API by Mike Thompson. As Bobby said it has its up & downs. The Rainforest Eagle data is stored on an emonPi.

Node-Red…not sure where I’ve been that I hadn’t found out about Node-Red until your post.

What a powerful tool. I already put up an MQTT server with a Smartthings bridge and realized I can pull ALL KINDS of data in, manipulate it and push it up to emoncms.

I’ve been node-red’ing for the last two days…

1 Like

That’s almost exactly what I do also! (I don’t have smartThings). I grab the local weather, my ecobee thermostat, and my Rainforest Eagle and others with Node-RED. Have fun!

Hello Bobby… what did you use to send Smartthings data to the MQTT Broker? I am looking for something to send to a Broker when something is switched on/off in my Smartthings, to read it in my Emoncms. Thanks.