Solar Panel API Project is my new coding project. Here's the tech behind it:

  • Ruby 2.7.0
  • Postgresql 12
  • SolarEdge API
  • OpenWeather API (for weather)
  • API (for sun position data)
There's two things executing in this project:
This is the code that runs in a loop and checks for data, putting it into the postgres database. Due to a quirk of the SolarEdge API, data for a given time (15 minute increments) sometimes isn't actually there for a good 5-10 minutes. So this script, on 15 minute intervals (:00, :15, :30, and :45) gathers weather and sun position data. THEN 10 minutes after THAT it queries the SolarEdge API for solar generation data in watts. Once that's gathered it's all put into the database under the timestamp of the solar data (:00, :15, :30, :45). Then it creates a .png file chart (using the 'gruff' gem) of power generation over the last 24 hours. Finally all that is bundled up and posted to a Twitter account - @JdbSolar.

Also every week (Sunday at 19:00) a weekly report to Twitter is run with a weekly chart.

This script also has other commands to export as csv and run a weekly report.

This is a lightweight Sinatra app that hosts two endpoints: / and /export. / serves up a simple index.html that shows the last year of data (or as much as it can if it's been running less than a year) and a link to export all data as a csv. /export does just what you'd think - exports all data as a csv.

What's Next
  • Do some code refactoring
  • Add unit tests for my /lib/ classes
  • Add in some new data fields for the weather
    • Weather id? It's an id for the current condition from Open Weather
    • snowfall in the last hour (mm)
    • snowfall in the last 3 hours (mm)
    • rain in the last hour (mm)
    • rain in the last 3 hours (mm)
  • Data SCIENCE
    • Use statistical analysis to figure out what fields have the most significant impact on power generation
Update: Added weather condition id, snow in the last hour, and rain in the last hour. Didn't add in teh last 3 hours because for some reason the openweather api was showing snow in the last hour but NOT in the last 3 hours and I didn't want to potentially pollute my data with a bunch of zeros.

No comments:

Post a Comment