Skip to content

Instantly share code, notes, and snippets.

@adlerweb
Created May 27, 2021 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adlerweb/b6b5fa17f7cbc7adac864ca19165be12 to your computer and use it in GitHub Desktop.
Save adlerweb/b6b5fa17f7cbc7adac864ca19165be12 to your computer and use it in GitHub Desktop.
Fetch predicted renewable energy generation for Germany and find time of day where appliances would theoretically run with lowest environmental impact
import datetime
import urllib.request
import json
weeknr = datetime.date.today().strftime("%V")
year = datetime.date.today().strftime("%Y")
url = "https://energy-charts.info/charts/power/data/de/week_"+year+"_"+weeknr+".json"
data = urllib.request.urlopen(url).read()
data = json.loads(data)
odata = []
max = [0,0]
for section in data:
if 'xAxisValues' in section:
for xv in section['xAxisValues']:
odata.append([datetime.datetime.fromtimestamp(xv/1000)])
if 'name' in section and 'data' in section and len(section['name']) > 0 and 'en' in section['name'][0] and section['name'][0]['en'] == 'Renewable Share forecast':
i = 0
for xv in section['data']:
if xv is not None:
odata[i].append(xv)
if xv > max[1]:
max = [odata[i][0], xv]
i = i + 1
print("Prefered load time: " + max[0].strftime("%Y-%m-%d_%H:%M") + " with " + str(max[1]) + "% Renewables")
@adlerweb
Copy link
Author

This does not take in account load profiles (aka: is there any surplus or not) or CO² (aka: nuclear power)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment