Skip to content

Instantly share code, notes, and snippets.

@rschildmeijer
Created August 19, 2022 11:38
Show Gist options
  • Save rschildmeijer/a098c45e202216ae465d4ebc4704e476 to your computer and use it in GitHub Desktop.
Save rschildmeijer/a098c45e202216ae465d4ebc4704e476 to your computer and use it in GitHub Desktop.
spot_prices.py
#ex output: [0.02, 0.019, ..., 0.025]
# index = 0, 0.02 = hour 0-1
# index = 1, 0.019 = hour 1-2
# index = 23, 0.025 = hour 23-24
def todays_spot_prices():
return hass.states.get("sensor.nordpool_kwh_se4_sek_3_05_025").as_dict()['attributes']['today']
def get_active_hours(spots):
enumerated_hours = sorted(enumerate(spots), key=lambda entry: entry[1])[0:HOURS_TO_RUN]
hours = [entry[0] for entry in enumerated_hours]
return hours
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment