eGauge Energy Monitor (Solar)

I just got into SmartThings and adding solar power generation to my dashboard would be great. My system is monitored by an eGauge system and they do have an API documented at https://www.egauge.net/docs/egauge-xml-api.pdf. I have retrieved data from the eGauge using URI, but I have no idea what to do with it. If any of the developers here would like to take a shot at this or get me started with some sample code, I would really appreciate it. All I really care about is for the live Solar generation value and Grid usage in kW. I ran http://egauge15753.egaug.es/cgi-bin/egauge?noteam and got data back. If you want to see eGauges built-in monitoring just remove the /cgi… part from the hyperlink. I just need help figuring out how to use the data in SmartThings. The data I need comes back as:

-<meter title="Grid">
<energy>1805.1</energy>
<energyWs>6498493728</energyWs>
<power>-3278.7</power>
</meter>
-<meter title="Solar">
<energy>2741.7</energy>
<energyWs>9870259918</energyWs>
<power>3943.6</power>
</meter>

Under Grid, a negative value for power indicates that I am putting energy back on the Grid. That could be used to change the color of the tile, i.e. green if the value is negative, red if the value is positive. Under Solar, power divided by 1,000 will give me a live reading in kW. The tile could be green and showing the solar power if solar energy is being put back on the grid, and the tile could be red and showing the Grid power value if that value is positive; meaning I am using energy from the grid.

Have you checked out the SmartThings Developer Documentation?
http://docs.smartthings.com/en/latest/index.html

Yes I started reading the docs, but I have not wrote a single line of code in 20 years. I don’t expect to learn how to code in Groovy by just reading the docs.

First… um. You might want some security on that URL. Maybe not - dunno, guess there’s nothing bad anyone can do with that.

Second, looks like this would be an external web site integration type app, and the device type you’re creating is a “sensor” - it looks likely that you could base it on some templates around power-monitoring devices.

Third, the data is plain old XML. Groovy should be able to parse XML with ease.

Thanks, but that link is actually a read only proxy and no changes can be made to the eGauge device. I will look for templates.

I wrote a device for my enlighten pv system. Not sure how similar the api is but you can have a look at my code to see if it is a good starting point.

It looks like this

2 Likes

Thank you very much Ron.

No problem. My system has security which is why the code has preferences for dev id and key for access but yours being open should be even easier.

My system returns json for example
{“system_id”:432864,“modules”:30,“size_w”:7500,“current_power”:1829,“energy_today”:1377,“energy_lifetime”:9223891,“summary_date”:“2015-05-18”,“source”:“microinverters”,“status”:“normal”,“operational_at”:1409425500,“last_report_at”:1431972708}

I am not really sure what you will have to do to process the XML instead of the json. Perhaps the methods they have provided will detect and support either.
The docs for the response part are found here.
http://docs.smartthings.com/en/latest/smartapp-developers-guide/calling-web-services-in-smartapps.html

Understood about learning language from docs but I can tell you I have never programmed in groovy either. But I am a current java developer so that helps a great deal. The 20year gap may make things a little more difficult :smile:

If the processing isn’t done for you perhaps you can use this to convert from XML to json

I dont’ know if JSONObject is available in ST ide. You can’t import new packages into the ide, you get what they provide you only.

Perhaps someone else can explain if ST can handle XML results.

Yep. This works in a smartapp:

def rootNode = new XmlSlurper().parseText(
    '''<root>
         <a>one!</a>
         <a>two!</a>
       </root>''' )

 log.debug rootNode.a.size() == 2
 rootNode.a.each { log.debug it.text() }

So instead of JsonSlurper, just use XmlSlurper.

@CarlosS with the @schettj example I was able to figure out that the resp.data element is already an XmlSlurper GPathResult. So I was able to modify my code to work with your system.

I only set power but I think you should be able to take it from here :smile: Let me know if you have any questions

Excellent! Thanks a lot Ron.

Your system has some cool features reporting Car, AC, and Grid. I like that. Mine only monitors the PV itself.

On the other hand many of the values I had in my system yours does not report. Yours reports current power which I coded for you in my example code.

However your “power” reading is a total since last reading in terms of “hours” not really sure what that means :slight_smile: So I am not sure if you can calculate totals I have in my original code. My system reports totals, percentages of overall system potential etc. You will have to calculate them yourself. For example you know what the max power of your system should be so you could hard code the “Production” as power/knownMaxPower. Then my Production and Max Production tiles would start working.

Today and Live Tiles are more difficult because you need to store the data somehow. Since your system doesn’t seem to report power generated totals you may just need to remove these tiles.

The last tile I have is my system ID with the text “Powered by Enphase” which is a terms requirement to use the Enlighten API. You have to label your app with the powered by enphase logo or text. You can remove this tile as well or change the text to eGauge :smile:

Enjoy !

Thanks again. I will play with it tonight. The eGauge monitor can have 12 or 16 current sensors. It only came with sensors for the grid and for the solar panels. I added a sensor for my car charger and another for the AC. I could add more, like one for the oven and one for the dryer. The unit saves all the data in registers and they could be parsed with their API, but I will start small using the example you gave me. If I learn Groovy, I will definitely get fancier with the data.

Cool, enjoy ! I have still not learned groovy :smile: just hacking away.

I just finished hacking away using your code as an example. I am using two tiles to show current solar energy and current grid status in watts. The solar tile is green when solar energy is being generated. When no energy is being generated the tile is black (need to test this tonight). The grid (my power meter) tile shows negative or positive wattage. When the value is negative is means I am putting surplus energy on the grid, so the tile is green. When the value is positive it means I am using energy from the grid, so the tile changes to red. I also changed the preferences section in the code so the URL for the eGauge system is not hard coded and can be customized. Now I need to learn how to poll every X seconds so the tiles refresh automatically.

Polling is already there unfortunately SmartThings polling doesn’t work reliably. I have support tickets open but they don’t seem to be able to fix this issue.

So I used pollster to fix the SmartThings short coming.

You can just add your own schedule code also since that is all pollster is doing. It schedules to be called and then calls your “poll” or “refresh” commands.

Even Pollster stops working occasionally. It’s one of the issues with Smart Things. Devices that “send” data work better, devices that need to be polled can be hit and miss.

I posted the code I used here:

Thanks, just found this and got this working for my solaredge egauge system. Any updates on getting polling to work so i dont have to manually hit refresh?

I am using the Pollster app and poll every 5 minutes.

Thank you for posting, I have implemented this for my eGauge and added the extra tiles for my additional meters.