In a recent post, I wrote about using Bidgely to track your realtime electrical usage, using a little gadget that reads minute-by-minute data from your utility’s smart meter. I even made a video showing how to install the Bidgely Rainforest Eagle device and use Bidgely’s (very pretty) web dashboard.
Using the native Bidgely hardware and dashboard is all well and good, but this website is do it yourself home automation. Most of us are creating our own home automation systems with Raspberry Pi, crazy sensors, control hardware, etc. We generally aren’t satisfied using someone else’s interface and systems, no matter how slick they are. We want to get at the data.
For Bidgely, the data can help you do a lot of things, when properly mashed up with your existing home automation system. You could turn off non-essential lights or appliances if your electrical usage got too high, for example. Or you could correlate electrical usage with movement in your home and data from something like a Nest thermostat to see what activities cause you to use the most power. If you cook in the kitchen and raise your home’s temperature, is it causing the AC to kick on and waste a ton of power? With data from Bidgely, these kinds of things are trackable.
Tragically, Bidgely hasn’t yet released a public API to help you get at your usage data. Happily, though, I’ve gone ahead and built one for them.
In your Bidgely web dashboard, all the lovely graphs you see are drawing data from somewhere. And that somewhere is an undocumented internal API which Bidgely uses to feed data to the various interfaces and controls.
Here is some Python code which allows you to get at data from your own Bidgely account:
''' Created on Mar 11, 2014 Diy-Ha.com ''' import mechanize import json #Your unique credentials. To find your user_id, go to your Bidgely Dashboard and use your browser to View Source. Then search for 'uuid'. The sequence of numbers and letters separated by dashes is your user_id user_id = 'ENTER YOUR USERID HERE' username = "ENTER YOUR BIDGELY LOGIN" password = 'ENTER YOUR PASSWORD' #Create a new Mechanize browser br = mechanize.Browser() #Set up the browser to handle redirects, and to use an actual user agent header br.set_handle_redirect(True) br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:22.214.171.124) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] #Open the Bigely login page br.open("https://www.bidgely.com/user/login") #Select the first form on the page. This is the sign in form. br.select_form(nr=0) #Select the username and password controls, and enter the username and password control = br.find_control(type="text") control.value = username control2 = br.find_control(type="password") control2.value = password #Submit the form br.submit() #Open the URL to your own data stream. r = br.open("https://api.bidgely.com/streams/users/%s/homes/1/gws/1/fastPoll" % user_id) #Get the response, and use regex to parse out the current usage number html = r.read() usage = json.loads(html) for r in usage: current_usage = usage[r]['value'] print "Current Usage is %s watts" % current_usage
Basically, the code creates a virtual browser, using the Python mechanize module. It then uses this browser to sign into Bidgely (via your own login credentials), and to access the ondocumented Bidgely API. The API returns JSON, which the script parses to get out current electric usage, measured in watts.
For here, you can do whatever you want with this number. Personally, I run this script on a Raspberry PI, and feed the usage data into a MySQL database for other parts of my home automation system to use. Mostly recently, I used the data and an Arduino Tre to create a realtime, ambient electrical use meter. But that’s for another post.
Feel free to use the code above in your own home automation system. Remember, though, to play nice with Bidgely’s systems. Introduce appropriate delays into your code so that you’re not spamming their servers (I ping the API at most once every minute, since this is how often they update their data from your smart meter).
Have fun with your realtime electric data!