StromGedacht Logo
Zurück

API
Leitfaden

Update der Status –– Version 2.0 –– 06. November 2023

In Version 2.0 wurde der gelbe Status (state = 2) entfernt und Supergrün (state = -1) eingeführt. Der neue Status tritt unabhängig von orangenen oder roten Phasen auf. Beim Status Supergrün ist das Verbrauchen von Strom besonders netzdienlich. Mehr erfahren

Hier erfährst du Schritt für Schritt, wie du unsere API nutzen kannst.

Hinweis: Für Entwicklung und Dokumentation der StromGedacht-API haben wir das Open-Source-Tool Swagger genutzt.

Die StromGedacht-API bietet drei Abruffunktionen für Netzdaten:

/v1/now: Abruf des StromGedacht-Zustands in der TransnetBW-Regelzone für den gegenwärtigen Zeitpunkt zu einem angegebenen Standort (Postleitzahl)

/v1/states: Abruf der StromGedacht-Zustände in der TransnetBW-Regelzone für einem spezifizierten Zeitraum zu einem angegebenen Standort (Postleitzahl), wobei der Status maximal 4 Tage in die Vergangenheit und maximal 2 Tage in die Zukunft abgefragt werden kann.

/v1/statesRelative: Abruf der StromGedacht-Zustände in der TransnetBW-Regelzone für eine spezifizierte Anzahl von Stunden in der Zukunft sowie in der Vergangenheit (optional) relativ zum Abfragezeitpunkt. Es kann maximal 4 Tage in die Vergangenheit und maximal 2 Tage in die Zukunft abgefragt werden.

Die StromGedacht-API ist unter https://api.stromgedacht.de aufrufbar.
Dies kann beispielsweise mittels cURL geschehen.

CODE
curl -X 'GET' \
'https://api.stromgedacht.de/v1/now?zip=70173' \
-H 'accept: application/json'

Die Rückgabe sieht dann entsprechend so aus:

{
"state": 1
}

Die Bedeutung der StromGedacht-Zustände ist – wie aus der StromGedacht-App bekannt – wie folgt:

  • -1 = supergrüner Zustand: Verbrauch verlegen, um nachhaltigen Strom zu nutzen und die Netzdienlichkeit zu unterstützen
  • 1 = grüner Zustand: Normalbetrieb – Du musst nichts weiter tun
  • 2 = gelber Zustand: Verbrauch vorverlegen – Strom jetzt nutzen (dieser Zustand wurde entfernt)
  • 3 = oranger Zustand: Verbrauch reduzieren, um Kosten und CO2 zu sparen
  • 4 = roter Zustand: Verbrauch reduzieren, um Strommangel zu verhindern

Hier haben wir einige Code-Beispiele für Python und R für dich erstellt:

CODE
# Be sure to have the requests library installed ('pip install requests')
import requests
import json

# StromGedacht API
#
# Get current state for zip=70173 (Stuttgart)
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
stromgedachtURL = "https://api.stromgedacht.de/v1/now?zip=70173"
response = requests.get(stromgedachtURL, headers = {"accept":"application/json"})
content = json.loads(response.text)
state = content["state"]
print(state)
CODE
# Be sure to have the requests library installed ('pip install requests')
import requests
import json

# StromGedacht API
#
# Get states for zip=70173 (Stuttgart) from 2023-06-16T00:00:00+02:00 to 2023-06-17T23:59:59+02:00
# Please substitute the start and end dates above with valid dates as the API only provides data for up to four days in the past and two days in the future
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
stromgedachtURL = "https://api.stromgedacht.de/v1/states?zip=70173&from=2023-06-26T00%3A00%3A00%2B02%3A00&to=2023-06-28T23%3A59%3A59%2B02%3A00"
response = requests.get(stromgedachtURL, headers = {"accept":"application/json"})
content = json.loads(response.text)
states = content["states"]
print(states)
for entry in states:
   print(entry["from"])
   print(entry["to"])
   print(entry["state"])
CODE
# Be sure to have the requests library installed ('pip install requests')
import requests
import json

# StromGedacht API
#
# Get states for zip=70173 (Stuttgart) for the next 12 hours from now
# Please assign suitable values to hoursInFuture (required) and hoursInPast (optional) as the API only provides data for up to four days in the past and two days in the future
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
stromgedachtURL = "https://api.stromgedacht.de/v1/statesRelative?zip=70173&hoursInFuture=12&hoursInPast=0"
response = requests.get(stromgedachtURL, headers = {"accept":"application/json"})
content = json.loads(response.text)
states = content["states"]
print(states)
for entry in states:
   print(entry["from"])
   print(entry["to"])
   print(entry["state"])
CODE
# Be sure to have the requests library installed ('pip install requests')
import requests
import json

# StromGedacht API
#
# Get data (load in MW, renewableEnergy in MW, residualLoad in MW, superGreenThreshold in MW) for BW indicated by zip=70173 (Stuttgart)
# Please assign suitable values to 'from' (optional) and 'to' (optional) if you need a more specific timeframe.
# If 'from' and 'to' are not used, then the data will be provided for 7 days ago and up to 1 day in the future.
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
stromgedachtURL = "https://api.stromgedacht.de/v1/forecast?zip=70173&from=2023-10-29&to=2023-10-29"
response = requests.get(stromgedachtURL, headers = {"accept":"application/json"})
content = json.loads(response.text)
load = content["load"]
renewableEnergy = content["renewableEnergy"]
residualLoad = content["residualLoad"]
superGreenThreshold = content["superGreenThreshold"]
print("
###########################")
print("Load in BW in MW:
")
print(load)
for entry in load:
   print(entry["dateTime"])
   print(entry["value"])
print("
###########################")
print("Amount of Renewable Energy production in BW in MW:
")
print(renewableEnergy)
for entry in renewableEnergy:
   print(entry["dateTime"])
   print(entry["value"])
print("
###########################")
print("Residual load in BW in MW:
")
print(residualLoad)
for entry in residualLoad:
   print(entry["dateTime"])
   print(entry["value"])
print("
###########################")
print("Threshold for superGreen signal in BW in MW:
")
print(superGreenThreshold)
for entry in superGreenThreshold:
   print(entry["dateTime"])
   print(entry["value"])

Python StromGedacht API Sample Notebook herunterladen.

CODE
# Uncomment the following line if the httr package has not already been installed
# install.packages("httr")

# StromGedacht API
#
# Get current state for zip=70173 (Stuttgart)
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
response <- httr::GET("https://api.stromgedacht.de/v1/now?zip=70173")
content <- (httr::content(response, "parsed"))
print(content$state)
CODE
# Uncomment the following line if the httr package has not already been installed
# install.packages("httr")

# StromGedacht API
#
# Get states for zip=70173 (Stuttgart) from 2023-06-16T00:00:00+02:00 to 2023-06-17T23:59:59+02:00
# Please substitute the start and end dates above with valid dates as the API only provides data for up to four days in the past and two days in the future
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
response <- httr::GET("https://api.stromgedacht.de/v1/states?zip=70173&from=2023-06-16T00%3A00%3A00%2B02%3A00&to=2023-06-17T23%3A59%3A59%2B02%3A00")
content <- (httr::content(response, "parsed"))
print(content$states)
for (i in 1:length(content$states)) {
  print(content$states[[i]]$from)
  print(content$states[[i]]$to)
  print(content$states[[i]]$state)
}
CODE
# Uncomment the following line if the httr package has not already been installed
# install.packages("httr")

# StromGedacht API
#
# Get states for zip=70173 (Stuttgart) for the next 12 hours from now
# Please assign suitable values to hoursInFuture (required) and hoursInPast (optional) as the API only provides data for up to four days in the past and two days in the future
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
response <- httr::GET("https://api.stromgedacht.de/v1/statesRelative?zip=70173&hoursInFuture=12&hoursInPast=0")
content <- (httr::content(response, "parsed"))
print(content$states)
for (i in 1:length(content$states)) {
  print(content$states[[i]]$from)
  print(content$states[[i]]$to)
  print(content$states[[i]]$state)
}
CODE
# Uncomment the following line if the httr package has not already been installed
# install.packages("httr")

# StromGedacht API
#
# Get data (load in MW, renewableEnergy in MW, residualLoad in MW, superGreenThreshold in MW) for BW indicated by zip=70173 (Stuttgart)
# Please assign suitable values to 'from' (optional) and 'to' (optional) if you need a more specific timeframe.
# If 'from' and 'to' are not used, then the data will be provided for 7 days ago and up to 1 day in the future.
#
# Meaning of states (cf. https://www.stromgedacht.de):
# -1 = superGreen
#  1 = green
#  3 = orange
#  4 = red
#
response <- httr::GET("https://api.stromgedacht.de/v1/forecast?zip=70173&from=2023-10-29&to=2023-10-29")
content <- (httr::content(response, "parsed"))
print("###########################")
print("Load in BW in MW:")
print(content$load)
for (i in 1:length(content$load)) {
  print(content$load[[i]]$dateTime)
  print(content$load[[i]]$value)
}
print("###########################")
print("Amount of Renewable Energy production in BW in MW:")
print(content$renewableEnergy)
for (i in 1:length(content$renewableEnergy)) {
  print(content$renewableEnergy[[i]]$dateTime)
  print(content$renewableEnergy[[i]]$value)
}
print("###########################")
print("Residual load in BW in MW:")
print(content$residualLoad)
for (i in 1:length(content$residualLoad)) {
  print(content$residualLoad[[i]]$dateTime)
  print(content$residualLoad[[i]]$value)
}
print("###########################")
print("Threshold for superGreen signal in BW in MW:")
print(content$superGreenThreshold)
for (i in 1:length(content$superGreenThreshold)) {
  print(content$superGreenThreshold[[i]]$dateTime)
  print(content$superGreenThreshold[[i]]$value)
}

Herzlichen Dank, dass du die StromGedacht-API nutzt. Bei Fragen und technischen Problemen kannst du uns unter stromgedacht@transnetbw.de kontaktieren.


Nutzungsbedingungen