StromGedacht Logo
Zurück

API
Leitfaden

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 = grüner Zustand: Normalbetrieb – Du musst nichts weiter tun
  • 2 = gelber Zustand: Verbrauch vorverlegen – Strom jetzt nutzen
  • 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 = green
# 2 = yellow
# 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 = green
# 2 = yellow
# 3 = orange
# 4 = red
#
stromgedachtURL = "https://api.stromgedacht.de/v1/states?zip=70173&from=2023-06-16T00%3A00%3A00%2B02%3A00&to=2023-06-17T23%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 = green
# 2 = yellow
# 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
# 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 = green
# 2 = yellow
# 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 = green
# 2 = yellow
# 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 = green
# 2 = yellow
# 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)
}

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


Nutzungsbedingungen