forked from esphome-econet/esphome-econet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
econet_time.yaml
140 lines (140 loc) · 3.94 KB
/
econet_time.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
---
time:
- platform: homeassistant
id: homeassistant_time
on_time_sync:
if:
condition:
time.has_time:
then:
- logger.log:
format: "System clock was synced; synchronizing microcontroller to Home Assistant time"
level: INFO
tag: homeassistant_time_sync
- number.set:
id: irtc_year
value: !lambda return id(homeassistant_time).now().year - 2000;
- number.set:
id: irtc_month
value: !lambda return id(homeassistant_time).now().month;
- number.set:
id: irtc_day
value: !lambda return id(homeassistant_time).now().day_of_month;
- number.set:
id: irtc_hour
value: !lambda return id(homeassistant_time).now().hour;
- number.set:
id: irtc_minute
value: !lambda return id(homeassistant_time).now().minute;
- number.set:
id: irtc_seconds
value: !lambda return id(homeassistant_time).now().second;
else:
- logger.log:
format: "System clock was synced but time is invalid"
level: WARN
tag: homeassistant_time_sync
text_sensor:
- platform: template
name: "Microcontroller Datetime"
id: irtc_time
icon: mdi:calendar-clock
update_interval: ${econet_update_interval}
entity_category: "diagnostic"
disabled_by_default: true
lambda: |-
if (isnan(id(irtc_day).state) || !id(irtc_day).state) {
// Return undefined if values haven't been successfully fetched yet
return {};
}
tm controller_time = {
.tm_sec = (int) id(irtc_seconds).state,
.tm_min = (int) id(irtc_minute).state,
.tm_hour = (int) id(irtc_hour).state,
.tm_mday = (int) id(irtc_day).state,
.tm_mon = (int) id(irtc_month).state - 1, // C++: 0-11, econet: 1-12
.tm_year = (int) id(irtc_year).state + 2000 - 1900 // C++: years since 1900, econet: since 2000
};
char time_string[sizeof("yyyy-mm-ddThh:mm:ss-hhmm")];
std::strftime(time_string, sizeof(time_string), "%FT%T%z", &controller_time);
std::string controller_time_string(time_string);
return controller_time_string;
number:
- platform: econet
name: "IRTC Year"
id: irtc_year
number_datapoint: IRTCYEAR
unit_of_measurement: "y"
step: 1
min_value: 24
max_value: 99
mode: box
entity_category: "config"
icon: mdi:calendar-clock
request_mod: 8
internal: true
- platform: econet
name: "IRTC Month"
id: irtc_month
number_datapoint: IRTCMONT
unit_of_measurement: "m"
step: 1
min_value: 1
max_value: 12
mode: box
entity_category: "config"
icon: mdi:calendar-clock
request_mod: 8
internal: true
- platform: econet
name: "IRTC Day"
id: irtc_day
number_datapoint: IRTCDAYS
unit_of_measurement: "d"
step: 1
min_value: 1
max_value: 31
mode: box
entity_category: "config"
icon: mdi:calendar-clock
request_mod: 8
internal: true
- platform: econet
name: "IRTC Hour"
id: irtc_hour
number_datapoint: IRTCHOUR
unit_of_measurement: "h"
step: 1
min_value: 0
max_value: 23
mode: box
entity_category: "config"
icon: mdi:calendar-clock
request_mod: 8
internal: true
- platform: econet
name: "IRTC Minute"
id: irtc_minute
number_datapoint: IRTCMINS
unit_of_measurement: "min"
step: 1
min_value: 0
max_value: 59
mode: box
entity_category: "config"
icon: mdi:calendar-clock
request_mod: 8
internal: true
- platform: econet
name: "IRTC Seconds"
id: irtc_seconds
number_datapoint: IRTCSECS
unit_of_measurement: "s"
step: 1
min_value: 0
max_value: 59
mode: box
entity_category: "config"
icon: mdi:calendar-clock
request_mod: 8
internal: true