There is probably a simple solution to this, but I am having troubles. I have a template sensor to check Google calendar events, and it will return “Today”, “Tomorrow”, or the week day of the event. I want to add another function, so if the date is greater than a week past today’s date, it will display the event date. I can either make the weekday -or- the event date display, but when I enable both, it only displays the weekday, and wont display the date instead if greater than 7 days. Any ideas?
- platform: template
sensors:
test_day2_new:
friendly_name: Test Day 2 New
value_template: >
{% set pickupday = strptime(states.calendar['test2'].attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%A") %}
{% set pickupday2 = strptime(states.calendar['test2'].attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%b %d, %Y") %}
{% if as_timestamp(states.calendar.test2.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 == 0.0 %}
- TODAY -
{% elif as_timestamp(states.calendar.test2.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 == 1.0 %}
TOMORROW
{% elif as_timestamp(states.calendar.test2.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 >= 2.0 %}
{{ pickupday }}
{% elif as_timestamp(states.calendar.test2.attributes.start_time) / 86400 - as_timestamp(as_timestamp(now()) | timestamp_custom("%Y-%m-%d 00:00:00",true)) / 86400 >= 7.0 %}
{{ pickupday2 }}
{% else %}
Unknown
{% endif %}