Template Guide: Days away from calendar event

See below:

The state is 242 days, not 242. When converting to a float it will be zero because the word days is not a number. Parse out the days by replacing it or splitting the string.

Thanks @petro and @123. Parsed out days and added it as unit of measurement instead and everything works as expected.

It is so obvious what the problem was now. Thanks to you experts spending the time and energy helping out noobs like myself.

As suspected (and confirmed by the screenshot), when you said “a value of 242 days” the value literally contained the word “days” (actually " Days"). As explained earlier:

Something to keep in mind should you ever encounter a similar situation.

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