View difference between Paste ID: 6EtURgTR and sHQV4LeM
SHOW: | | - or go back to the newest paste.
1
dst:
2
  friendly_name: Daylight Savings Times
3
  unique_id: f2a8791bf12449c4a67d149c609c21c4
4-
  value_template: >
4+
5-
    {%- set ns = namespace(previous = 2, spring=none, fall=none) %}
5+
  value_template: >-
6-
    {%- set today = strptime(states('sensor.date'), '%Y-%m-%d').astimezone().replace(hour=ns.previous) %}
6+
    {%- set ns = namespace(spring = none, fall = none) %}
7-
    {%- for i in range(365) %}
7+
    {%- set today = strptime(states('sensor.date'), '%Y-%m-%d') %}
8-
      {%- set day = (today + timedelta(days=i)).astimezone() %}
8+
    {%- for i in range(365) if (today + timedelta(days = i)).timetuple().tm_mon in [3, 10] and (today + timedelta(days = i)) | as_timestamp | timestamp_custom("%w") | int == 0 %}
9-
      {%- if ns.previous - day.hour == -1 %}
9+
      {%- set day = (today + timedelta(days = i)).astimezone() %}
10-
        {%- set ns.spring = today + timedelta(days=i) | timestamp_local %}
10+
      {%- if day.timetuple().tm_mon == 3 %}
11-
      {%- elif ns.previous - day.hour == 1 %}
11+
        {%- set ns.spring = day.replace(hour = 2) %}
12-
        {%- set ns.fall = today + timedelta(days=i) | timestamp_local %}
12+
      {%- else %}
13
        {%- set ns.fall = day.replace(hour = 3) %}
14-
      {%- set ns.previous = day.hour %}
14+
15
    {%- endfor %}
16
    {{ [ns.spring, ns.fall] | min }}
17
  attribute_templates:
18-
    is_dst_active: >
18+
    next_spring: >-
19-
      {{ now().timetuple().tm_isdst > 0 }}
19+
      {%- set ns = namespace(spring = none) %}
20-
    dst_change_tomorrow: >
20+
      {%- set today = strptime(states('sensor.date'), '%Y-%m-%d') %}
21-
      {% set dt = now() + timedelta(days=1) %}
21+
      {%- for i in range(365) if (today + timedelta(days = i)).timetuple().tm_mon == 3 and (today + timedelta(days = i)) | as_timestamp | timestamp_custom("%w") | int == 0 %}
22-
      {{ now().astimezone().tzinfo != dt.astimezone().tzinfo }}
22+
        {%- set ns.spring = (today + timedelta(days = i)).astimezone().replace(hour = 2) %}
23-
    next: >
23+
24-
      {%- set ns = namespace(previous = 2, spring=none, fall=none) %}
24+
      {{ ns.spring }}
25-
      {%- set today = strptime(states('sensor.date'), '%Y-%m-%d').astimezone().replace(hour=ns.previous) %}
25+
    next_fall: >-
26-
      {%- for i in range(365) %}
26+
      {%- set ns = namespace(fall = none) %}
27-
        {%- set day = (today + timedelta(days=i)).astimezone() %}
27+
      {%- set today = strptime(states('sensor.date'), '%Y-%m-%d') %}
28-
        {%- if ns.previous - day.hour == -1 %}
28+
      {%- for i in range(365) if (today + timedelta(days = i)).timetuple().tm_mon == 10 and (today + timedelta(days = i)) | as_timestamp | timestamp_custom("%w") | int == 0 %}
29-
          {%- set ns.spring = today + timedelta(days=i) %}
29+
        {%- set ns.fall = (today + timedelta(days = i)).astimezone().replace(hour = 3) %}
30-
        {%- elif ns.previous - day.hour == 1 %}
30+
31-
          {%- set ns.fall = today + timedelta(days=i) %}
31+
      {{ ns.fall }}
32-
        {%- endif %}
32+
    is_dst: >-
33-
        {%- set ns.previous = day.hour %}
33+
      {{ now().timetuple().tm_isdst == 1 }}
34
    dst_change_tomorrow: >-
35-
      {%- set next = [ns.spring, ns.fall] | min %}
35+
      {{ now().astimezone().tzinfo != (now() + timedelta(days = 1)).astimezone().tzinfo }}
36-
      {%- set phrase = 'lose an hour' if next == ns.spring else 'gain an hour' %}
36+
    days_to_event: "{{ ((strptime(states('sensor.dst'), '%Y-%m-%d') | as_timestamp - strptime(states('sensor.date'), '%Y-%m-%d') | as_timestamp) / 86400) | int }}"
37-
      {"spring": "{{ns.spring}}", "fall": "{{ns.fall}}", "event": "{{next}}", "days_to_event":{{(next-today).days}}, "phrase": "{{phrase}}"}
37+
    phrase: "{{ 'lose' if states('sensor.dst') == state_attr('sensor.dst', 'next_spring') else 'gain' }} an hour"