Loading... 效果如下图所示:  ### 安装 在集成搜索holiday,安装该组件。该组件可以进行中国节日倒计时  安装本地日历,方便进行自定义日历。   ### 配置 如果需要多个纪念日倒计时,需要创建多个卡片,如果只在一个卡片中创建,只会显示最近的纪念日。   示例代码: ``` ### {% if now().hour >= 6 and now().hour < 9 -%} 早上好, {%- elif now().hour >= 9 and now().hour < 12 -%} 上午好, {%- elif now().hour >= 12 and now().hour < 13 -%} 中午好, {%- elif now().hour >= 13 and now().hour < 18 -%} 下午好, {%- elif now().hour >= 18 and now().hour < 23 -%} 晚上好, {%- else -%} 夜深了,请注意休息哦! {%- endif %} {{user}} {% set stop_time = as_timestamp(state_attr("calendar.zhong_guo", "start_time")) - as_timestamp(now()) %} {% set days = (stop_time // (60 * 60 * 24)) %} {% set hours = (stop_time// (60 * 60)) - days * 24 %} {% set minutes = (stop_time // 60) - (days * 24 * 60) %} {% set days = ((stop_time // (60 * 60 * 24))) %} {% set minutes = (minutes) - (hours * 60) %} {% macro phrase(value, name) %} {%- set value = value | int %} {{-'{}{}'.format(value,name) if value | int > 0 else''}} {%- endmacro %} {% set text = [ phrase(days,'天'), phrase(hours,'小时'), phrase(minutes,'分钟') ] | select('!=','') | list | join('') %} ### 距离{{state_attr("calendar.zhong_guo", "message")}}还有:{{text}} ``` 如果需要进行自定义纪念日,建议单独创建一个本地日历。   示例代码: ``` ### {% if now().hour >= 6 and now().hour < 9 -%} 早上好, {%- elif now().hour >= 9 and now().hour < 12 -%} 上午好, {%- elif now().hour >= 12 and now().hour < 13 -%} 中午好, {%- elif now().hour >= 13 and now().hour < 18 -%} 下午好, {%- elif now().hour >= 18 and now().hour < 23 -%} 晚上好, {%- else -%} 夜深了,请注意休息哦! {%- endif %} 焰火之舞 ! {% set stop_time = as_timestamp(state_attr("calendar.sheng_ri", "start_time")) - as_timestamp(now()) %} {% set days = (stop_time // (60 * 60 * 24)) %} {% set hours = (stop_time// (60 * 60)) - days * 24 %} {% set minutes = (stop_time // 60) - (days * 24 * 60) %} {% set days = ((stop_time // (60 * 60 * 24))) %} {% set minutes = (minutes) - (hours * 60) %} {% macro phrase(value, name) %} {%- set value = value | int %} {{-'{}{}'.format(value,name) if value | int > 0 else''}} {%- endmacro %} {% set text = [ phrase(days,'天') ] | select('!=','') | list | join('') %} ### 距离{{state_attr("calendar.sheng_ri", "message")}}还有:{{text}} ``` ### 备注 如果需要进行多个纪念日同时提醒,需要单独创建多个日历,如果只在一个日历中创建多个纪念日,只会提醒最近的一个。  最后修改:2024 年 02 月 29 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏