-
Notifications
You must be signed in to change notification settings - Fork 0
/
store-a-datetime-example.yaml
49 lines (42 loc) · 1.59 KB
/
store-a-datetime-example.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
esphome:
name: store-a-datetime-example
esp32:
board: esp32dev
framework:
type: arduino
logger:
level: DEBUG
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
web_server:
js_include: "www.js"
js_url: ""
time:
- platform: sntp
id: my_time
button:
- platform: template
name: Check Datetime value
on_press:
then:
- lambda: |-
ESP_LOGI("Button", "You can access the datetime as a string - %s - is: %s", id(my_datetime).get_name().c_str(), id(my_datetime).state.c_str() );
- lambda: |-
ESP_LOGI("Button", "You can also access the datetime values directly - hour: %d", id(my_datetime).state_as_time.hour );
ESP_LOGI("Button", "And do calucaltions with them");
id(my_datetime).state_as_time.recalc_timestamp_utc();
ESP_LOGI("Button", "sntp timestamp: %d picked timestamp: %d", id(my_time).now().timestamp, (id(my_datetime).state_as_time.timestamp - ESPTime::timezone_offset()));
if (id(my_time).now().timestamp > (id(my_datetime).state_as_time.timestamp - ESPTime::timezone_offset())) {
ESP_LOGI("Button", "The selected date/time is smaler than the current local date/time");
} else {
ESP_LOGI("Button", "The selected date/time is bigger than the current local date/time");
}
datetime:
- platform: template
id: my_datetime
name: Pick a Datetime
optimistic: yes
# restore_value: true
# valid formats are '%Y-%m-%d %H:%M:%S' - '%Y-%m-%d %H:%M' - '%H:%M:%S' - '%H:%M'
initial_value: "2024-01-30 12:45:00"