Template Guide: Days away from calendar event

Is there a way I can check for a specific calendar entry for tomorrow? I’m looking for the title ‘Tesco Delivery Due’. So I can be reminded to update the order the day before.

Here is an example Google Calendar allday event offset - #2 by allenporter

Took me a while to get my head round what is going on, but I think I’m there.
So, with an offset of -24h, the automation is triggered every time any event is due tomorrow at the current time. The condition then inspects the event in question for the string in question (in my case ‘Tesco delivery due’), and if present the Action is run.
I’ve set one up to just tell me via TTS but I think i need a binary helper such that a second automation can then tell me at a time when I will be setting alongside my Google Home device.
Thanks Allen.

The Trace tells me it’s triggering but then failing the condition. The Title of the event is “Tesco order due”
and my condition is

"{{ iif('Tesco' in trigger.calendar_event.summary, 'true', 'false') }}"

I’ve also tried it with the full title and that doesn’t work either.

Edit:
Changed the Condition to

{{ 'Tesco' in trigger.calendar_event.summary }}

and it works now.

Awesome glad it’s working. I’m not very strong with templates so sorry for the wrong info.

The extra sensor is useful when you need to use this for a condition that isn’t related to the trigger. E.g. at 9pm tell me if tomorrow is trash day.

can somebody help me with this one?
I tried every possible thing from here but it always gives me the state: unavailable
i want to get the days until the next calendar event
I already have sensor.date

  - sensor:
    - name: Event Day
      state: >
        {% set t = now() %}
        {% set midnight = today_at() %}
        {% set event = as_timestamp(states.calendar.urlaub.attributes.start_time) %}
        {% set delta = event - midnight %}
        {% set values = [ 'Today', 'Tomorrow', 'Day After Tomorrow' ] %}
        {{ values.get(delta.days, 'In %s Days'%delta.days) }}

does mine use as_timestamp?

no but it didnt work either so i tried this

well my original post isn’t grabbing an attribute, it’s grabbing the state. So you’d replace states with state_attr. The calculation uses datetime objects, so your event needs to be a datetime in your local timezone.

im sorry english is not my first language and
I’m not entirely sure I understood what you said.
could you help me with the code please?

check the original post again

omg im stupid haha
Its working now.
You know, sometimes you need somebody to tell you to look at it again :grinning_face_with_smiling_eyes:

well I made updates to the original post to account for the new way calendars work. So, you aren’t stupid, the original code was using the old calendar entity style.

Hey maybe I was to hasty. I noticed that the days don’t get updated at midnight. Only when I restart home assistant. Do you have an idea on why this could be?

you’ll have to use it with a trigger or write an automation that updates the sensor at a specific time using the homeassistant.update_entity service.

Okay thanks it should work now

Hi,
I know this is an old thread but hoping somebody can offer some advice.
I’m trying to use a sensor to show me what color trash can is going out tomorrow. I do this by reading an entry in a local calendar. Using the snippet in this thread I can get it working like this:

{% set midnight = today_at() %}
{% set event = state_attr('calendar.trash_calendar', 'start_time') | as_datetime | as_local %}
{% set color = is_state_attr('calendar.trash_calendar', 'message', "Blue Bin") %}
{% set delta = event - midnight %}
{% if delta.days == 0 and color == True %}
  true
{% elif delta.days == 1 and color == True %}
  true
{% elif delta.days > 1 %}
  false
{% endif %}

This works perfectly and updates my sensor accordingly. However, I have two bins going out this week, Blue and Brown, and my template seems to only show True to the first item in the calendar.
My “Brown Bin” sensor is identical except for swapping “blue” with “brown” in the message.
If I delete the Blue Bin from the calendar, the Brown Bin sensor works. If I then re-add Blue Bin, the Brown will continue to work but Blue will not.

Any advice would be greatly appreciated

maybe this thread will help? multiple sensors

You have to keep separate calendars for each bin. Calendars only show the next event.

1 Like

@petro - The Garbage Collection integration is no longer supported as the maintainer says its functionality is now almost entirely native in HA.

I have a “House” calendar in Google that I want to use for house maintenance reminders, including trash and recycling. I have created all-day events on the correct days for both collections.

I am trying to replicate the template sensor shown below pulling the number of days to the next “Trash” or “Recycling” full day event from the “House” calendar… Your quoted post would imply I need to create a separate calendar for each maintenance task which I definitely do not want to do… Is that the case? Is there some way around it?

I am trying to adapt {% set color = is_state_attr('calendar.house', 'message', "Recycling") %} to make it work in the set event portion of your example but haven’t figured it out.

- sensor:
    - name: "Recycling Day"
      icon: "mdi:recycle"
      state: >
        {% if is_state_attr('sensor.recycling', 'days', 0) %}
          Bring recycling in!
        {% elif is_state_attr('sensor.recycling', 'days', 1) %}
          Put recycling out!
        {% elif state_attr('sensor.recycling', 'days') | int(0) < 5 %}
          This Friday
        {% elif state_attr('sensor.recycling', 'days') | int(0) < 12 %}
          Next Week
        {% elif state_attr('sensor.recycling', 'days') | int(0) < 14 %}
          Week After Next
        {% endif %}