模板日期时间
template 日期时间平台允许您使用 lambdas 创建具有模板化值的日期时间。
datetime: # Example Date - platform: template id: my_datetime_date type: date name: Pick a Date optimistic: yes initial_value: "2024-01-30" restore_value: true
# Example Time - platform: template id: my_datetime_time type: time name: Pick a Time optimistic: yes initial_value: "12:34:56" restore_value: true
# Example DateTime - platform: template id: my_datetime type: datetime name: Pick a DateTime optimistic: yes initial_value: "2024-12-31 12:34:56" restore_value: true-
type (必填, enum): 日期时间的类型。可以是
date或time之一。 -
lambda (可选, lambda): 每个更新间隔评估一次以获取日期时间当前值的 Lambda。
-
set_action (可选, Action): 当远程 (如 Home Assistant 的前端)请求设置 日期时间值时应执行的操作。新值可通过 lambda 中的
x变量访问。 -
update_interval (可选, Time): 通过执行
lambda更新日期时间的间隔。 默认为60s。 -
optimistic (可选, boolean): 是否以乐观模式运行——在此模式下, 发送到模板日期时间的任何命令将立即更新报告的状态。 不能与
lambda一起使用。默认为false。 -
restore_value (可选, boolean): 将状态保存并加载到 RTC/Flash。 不能与
lambda一起使用。默认为false。 -
initial_value (可选, string): 如果在设置时未使用
restore_value恢复状态,则要设置的状态值。可以是以下之一:-
对于
type: date:- 格式为
%Y-%m-%d的字符串,例如:"2023-12-04"。 - 包含
year、month、day的对象。
- 格式为
-
initial_value: year: 2023 month: 12 day: 4-
对于
type: time:- 格式为
%H:%M:%S的字符串,例如:"12:34:56"。 - 包含
hour、minute、second的对象。
- 格式为
initial_value: hour: 12 minute: 34 second: 56-
对于
type: datetime:- 格式为
%Y-%m-%d %H:%M:%S的字符串,例如:"2023-12-04 12:34:56"。 - 包含
year、month、day、hour、minute、second的对象。
- 格式为
initial_value: year: 2023 month: 12 day: 4 hour: 12 minute: 34 second: 56- 还包括 Datetime 的所有其他选项。