Hi, i’m trying to create a template that will serve as a reminder to change our clocks when daylight savings ends in november. I only want the template to show when we are within 11 days (or whatever time period i decide) of it ending.
This year day light ends on nov 3, so i used the below code however it does not seem to work. The template continues to be visible at all times. Any suggestions?
TYIA
type: vertical-stack
cards:
type: custom:mushroom-template-card
primary: “”
secondary: >-
Daylight Savings is over in {{ (strptime(‘11/03/2024’, ‘%m/%d/%Y’,
today_at()) | as_local - today_at()).days }} days … don’t forget to
change your clock {{user}}!
icon: “”
multiline_secondary: true
visibility:
Thanks for coming here and asking a question.
Would you be so kind as to adjusting the format of your code so that we can read it properly & check the YAML spacing, etc. It is very hard for us to tell what is what when the text formatter jumbles everything like that.
Use the </> button or this:
Here is an example of how to fix it from the site FAQ Page. How to help us help you - or How to ask a good question.
The visibility section is under the vertical stack with the current indentation, but vertical stack have no option for visibility.
It looks like the mushroom-template-card do not have such one option either.
You might have to use a conditional card, but I do not think you can use a value_template there, so your value_template might have to be put in a sensor template, which can then be referenced in the conditional card.
You can set up a Template sensor that uses the days_until_dst function so you have an entity that can work with a Conditional Card or card visibility in other cards.
Example using Markdown Card with visibility
type: markdown
content: >-
{%- from 'easy_time.jinja' import days_until_dst,next_dst_phrase -%}
{%- set phrase = next_dst_phrase() -%}
{% set gain = phrase is search('gain') %}
Daylight Saving is {{'over' if gain else 'starting'}} in {{ days_until_dst() }} days.
The clocks will need to {{'fall back' if gain else 'spring forward'-}}
... don't forget to change them, {{user}}!
title: "Notice: Upcoming Time Change"
visibility:
- condition: numeric_state
entity: sensor.days_until_time_change
below: 4
I see no reason why you can not make a template with your original value template and then use a state condition in visibility section instead of a numeric condition.
Whereas if I put your code in a template sensor helper, then have visibility based on that, it does work. Therefore I would call it a bug. However the bug may just be that nothing is telling you condition: template is not supported - having the code there (working as expected or not) and refreshing the screen causes many many uncaught exceptions in the browser:
Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'layout')
at 39594.n2cd3-JQQQQ.js:7:20348
at o.ct (88859.6pkgdkycQT4.js:2:80055)
at o.update (88859.6pkgdkycQT4.js:2:80200)
at o._$AS (app.90wKv9r7Ny0.js:2:159969)
at N (app.90wKv9r7Ny0.js:2:163273)
at R._$AI (app.90wKv9r7Ny0.js:2:164546)
at I.v (app.90wKv9r7Ny0.js:2:164014)
at R.g (app.90wKv9r7Ny0.js:2:165227)
at R._$AI (app.90wKv9r7Ny0.js:2:164686)
at B (app.90wKv9r7Ny0.js:2:168048)
So the workaround is just to use visibility based on a binary sensor that contains your template. I’d probably alternatively do the binary sensor differently though, because having this trigger once a minute for every day of the year feels weird.
Actually, you can: Define an input_boolean helper sensor (Input boolean - Home Assistant) that indicates if the card should be visible and use that as a condition for the conditional card. Next create an automation that sets and resets the boolean helper, using your statement as a condition. trigger the automation dayly using a time_pattern
You can also just use easy_time, create a template entity and build reminders off that. It will never require configuration changes either because it searches for the daylight savings time change.
{% from 'easy_time.jinja' import days_until_dst %}
{{ days_until_dst() }}
It counts down to 0. So if you want to trigger 7 days ahead of time, you’d use a trigger on the template sensor.
triggers:
- trigger: time
at: "10:00"
conditions:
- condition: state
entity_id: sensor.<your_daylight_savings_countdown>
state: '7'
actions:
...
That doesn’t work for this year in the states. Scratch that, it does. I thought it was the 10th for some reason.
However it won’t work for every country
The macro provided by easy_time searches for the DST regardless what country you’re in. It will always work, down to the minute/second that DST occurs.
I remember having to make it work that way because someone in a random country had DST change at 1:05 am, it was really odd. Anyways, it’s a pretty light weight macro and it should just work.