Is there a way that I can do this with Home Assistant? I want to create a date countdown based on what is in the agenda. so a day counter until the date/moment in the agenda
It’s nice to have insight into how many days it will take until the holiday starts, for example
I think this service can be used to find the specific ‘holiday date’
Calendar.list_events
Or a date helper can also work I guess?
Input_datetime.test
And an input textbox that contains the output: days until the holiday
I get an error after the change
termplate: {{ (as_timestamp(states.input_datetime.datumtest) - as_timestamp(now())) | timestamp_custom(“%H hours and %M min”) }}
Error: ValueError: Template error: as_timestamp got invalid input ‘<template TemplateState(<state input_datetime.datumtest=2024-01-13; has_date=True, has_time=False, editable=True, year=2024, month=1, day=13, timestamp=1705100400.0, friendly_name=datumtest @ 2023-12-05T08:32:50.142417+01:00>)>’ when rendering template ‘{{ (as_timestamp(states.input_datetime.datumtest) - as_timestamp(now())) | timestamp_custom(“%H hours and %M min”) }}’ but no default was specified
make a input datetime helper with the date and then put this code into a template card: Days {{ (strptime(states('input_datetime.test'), '%Y-%m-%d', today_at()) | as_local - today_at()).days }}
The date/time in the calendar is in a different timezone than your HA instance is setup in.
You have to convert now() to the same timezone as the calendar. The calendar will be in UTC and you are in UTC+1 I guess?
Because timestamps are not meant really meant to calculate durations like that. The %d option of timestamp_custom reflects the numerical day of the date calculated by the timestamp math you performed, i.e. 6.167 days after Jan 1, 1970 at 00:00:00 UTC.
Your timestamp math converts to the datetime string 1970-01-07 04:00:30.162905+00:00. So 7 is correct for %d.
There are a couple custom macros available for calculating relative times and performing other time-related functions: