Skip to content

Instantly share code, notes, and snippets.

@bphermansson
Last active February 16, 2023 17:55
Show Gist options
  • Save bphermansson/8fd6ce21808b01c3f543edf2498959fc to your computer and use it in GitHub Desktop.
Save bphermansson/8fd6ce21808b01c3f543edf2498959fc to your computer and use it in GitHub Desktop.
Code snippet to get number of hours until the electricity is cheap(?).
{% set hour_when = as_timestamp(state_attr('binary_sensor.nordpool_planner_time_when_low_electricity_price', 'starts_at'))|int%}
{% set real_hour = (state_attr('binary_sensor.nordpool_planner_time_when_low_electricity_price', 'starts_at')) %}
Electricity is cheap at: {{ real_hour }}
{% set time_now = as_timestamp(now())|int%}
{% set hour_now = time_now|timestamp_custom('%H') %}
{% set hours_until = -((time_now - hour_when)|int/3600)|int %}
Hours left until cheap electricity: {{ hours_until }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment