mirror of
https://github.com/esphome/esphome.git
synced 2026-10-01 08:50:22 +00:00
[template][time] Add template time platform (#14838)
Co-authored-by: clydebarrow <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
co-authored by
clydebarrow
parent
b8af6cb005
commit
ea4754e798
@@ -0,0 +1,47 @@
|
||||
esphome:
|
||||
name: template-time-test
|
||||
host:
|
||||
api:
|
||||
logger:
|
||||
|
||||
time:
|
||||
- platform: template
|
||||
id: fixed_time
|
||||
lambda: |-
|
||||
return 1700000000;
|
||||
|
||||
# Derived from another time source, as when offsetting a real clock.
|
||||
- platform: template
|
||||
id: offset_time
|
||||
lambda: |-
|
||||
return id(fixed_time).timestamp_now() + 3600;
|
||||
|
||||
# A lambda that gives no value reports an invalid time.
|
||||
- platform: template
|
||||
id: empty_time
|
||||
lambda: |-
|
||||
return {};
|
||||
|
||||
text_sensor:
|
||||
# Timestamps are exposed as text (rather than a 32-bit float sensor state,
|
||||
# which cannot represent a UNIX epoch exactly) so the exact value can be checked.
|
||||
- platform: template
|
||||
name: "Fixed Timestamp"
|
||||
id: fixed_timestamp
|
||||
update_interval: 100ms
|
||||
lambda: |-
|
||||
return std::to_string(id(fixed_time).now().timestamp);
|
||||
|
||||
- platform: template
|
||||
name: "Offset Timestamp"
|
||||
id: offset_timestamp
|
||||
update_interval: 100ms
|
||||
lambda: |-
|
||||
return std::to_string(id(offset_time).now().timestamp);
|
||||
|
||||
- platform: template
|
||||
name: "Empty Time Valid"
|
||||
id: empty_time_valid
|
||||
update_interval: 100ms
|
||||
lambda: |-
|
||||
return std::string(id(empty_time).now().is_valid() ? "valid" : "invalid");
|
||||
Reference in New Issue
Block a user