Skip to content

Instantly share code, notes, and snippets.

@JBoye
Last active March 10, 2022 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JBoye/0fa525123053e5df6a35758e01ec747f to your computer and use it in GitHub Desktop.
Save JBoye/0fa525123053e5df6a35758e01ec747f to your computer and use it in GitHub Desktop.
template:
- sensor:
- name: Under gennemsnit
state: >
{% set start_time = now().hour %}
{% set prices = (state_attr("sensor.elpris", "today") + state_attr("sensor.elpris", "tomorrow"))[start_time:] %}
{% set index = prices.index(prices | select('lt', prices | average) | first) %}
{{today_at("00:00") + timedelta(hours = index + start_time)}}
type: custom:html-template-card
ignore_line_breaks: true
content: >
{% set value = states("sensor.billigste_time") | as_datetime %} <div
style="display:flex;
flex-direction:column;align-items:center;padding:20px;text-align:center">
Start strømslugere{{" om" if value > now() }}:
{% if value > now() -%}
<h1>{{'%02d' % ((value - now()).total_seconds() / 60 / 60) | round(0, 'floor')}}:{{'%02d' % ((value - now()).total_seconds() / 60 % 60) | round(0, 'floor')}}</h1>
{%- else -%}
<h1>NU</h1>
{%- endif %}
</div>
template:
- sensor:
- name: Billigste time
state: >
{% set start_time = now().hour %}
{% set prices = (state_attr("sensor.elpris", "today") + state_attr("sensor.elpris", "tomorrow"))[start_time:] %}
{% set index = prices.index(prices | min) %}
{{today_at("00:00") + timedelta(hours = index + start_time)}}
template:
- sensor:
- name: Billigste time
state: >
{% set start_time = now().hour %}
{% set prices = (state_attr("sensor.elpris", "today") + state_attr("sensor.elpris", "tomorrow"))[start_time:] %}
{% set index = prices.index(prices | min) %}
{{"I morgen " if index + start_time >= 24}}kl {{((today_at("00:00") + timedelta(hours = index + start_time))).strftime('%H:%M') }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment