-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatetime_functions.yaml
51 lines (46 loc) · 1.99 KB
/
datetime_functions.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
binary_sensor:
# Next Alarm templates #
- platform: template
sensors:
trav_alarm_trigger_5min:
value_template: >-
{% set alarm_time = as_timestamp(states('sensor.travis_7_pro_next_alarm'),0) %}
{% set time_now = as_timestamp(now() | default(0)) %}
{% if alarm_time != 0 %}
{{ time_now >= alarm_time - 900 }}
{% else %}
unavailable
{% endif %}
sensor:
- platform: time_date
display_options:
- "date"
template:
- sensor:
- name: Days Remaining in Month
unique_id: days_remaining_in_month
state: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set next = this.month + 1 if this.month + 1 <= 12 else 1 %}
{% set last = this.replace(year=this.year + 1, month=1, day=1) if now().month == 12 else this.replace(month=next, day=1) %}
{{ (last.date() - this.date()).days - 1 }}
- name: Days Passed in Month
unique_id: days_passed_in_month
state: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set next = this.month + 1 if this.month + 1 <= 12 else 1 %}
{% set first = this.replace(day=1) %}
{{ (this.date() - first.date()).days }}
- name: Days Remaining in Year
unique_id: days_remaining_in_year
state: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set next = this.year + 1 %}
{% set last = this.replace(year=next, month=1, day=1) %}
{{ (last.date() - this.date()).days }}
- name: Days Passed in Year
unique_id: days_passed_in_year
state: >
{% set this = now().replace(hour=0).replace(minute=0).replace(second=0).replace(microsecond=0) %}
{% set first = this.replace(month=1, day=1) %}
{{ (this.date() - first.date()).days }}