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:
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.
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.
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}
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
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.
@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 Let me know if you have any questions
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 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
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.
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.
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?