I have a sensor that someone else created for trash / recycling pickup, and I am also using for water delivery. I want to add a little bit more granularity to it, so it displays: today, tomorrow, next week, > 1 week. The dates come from a Google calendar (named Recycling). I can’t seem to figure out the proper formulas, and any insight would be appreciated! Typical code is below:
- platform: template
sensors:
recycling_pickup_day:
friendly_name: Recycling Pickup Day
value_template: >
{% set pickupday = strptime(states.calendar.recycling.attributes.start_time, "%Y-%m-%d %H:%M:%S").strftime("%A") %}
{% if pickupday == now().strftime("%A") %}
- TODAY -
{% elif pickupday == (as_timestamp(now())+ (86400)) | timestamp_custom("%A",true) %}
TOMORROW
{% elif pickupday >= (as_timestamp(now())+ (86401)) | timestamp_custom("%A",true) and pickupday <= (as_timestamp(now())+ (604800)) | timestamp_custom("%A",true) %}
{{ pickupday }}
{% elif pickupday >= (as_timestamp(now())+ (604801)) | timestamp_custom("%A",true) and pickupday <= (as_timestamp(now())+ (1209600)) | timestamp_custom("%A",true) %}
Next Week
{% else %}
> 1 Week
{% endif %}