Template condition comparing current time vs. state

I have a small automation where I’m trying to stop music playing five minutes before a calendar invite but for some reason my template’s not evaluating as true even when the two values I’m evaluating are (apparently) identical.

The first half of my statement is {{as_timestamp(state_attr('calendar.my_calendar', 'start_time')) | timestamp_custom('%Y-%m-%d %H:%M')}}, which in the Developer tab I can see evaluate to something like 2020-10-14 16:50.

The second half is {{(as_timestamp(now()) + (5*60)) | timestamp_custom('%Y-%m-%d %H:%M')}} which returns an identically formatted result. I put those two together like this

{{as_timestamp(state_attr('calendar.my_calendar', 'start_time')) | timestamp_custom('%Y-%m-%d %H:%M') == (as_timestamp(now()) + (6*60)) | timestamp_custom('%Y-%m-%d %H:%M')}}
{{(as_timestamp(now()) + (5*60)) | timestamp_custom('%Y-%m-%d %H:%M')}}

I noticed that my automation wasn’t firing and assumed it was the condition (it fires without) so I put all three of the template lines above into the developer tab and refreshed the page right on the minute where things should’ve lined up. I saw the two standalone statements print the same exact value, but the comparison was still evaluating false.

Any clues where I’m going wrong? I have a hunch that even though I’m formatting the timestamp the evaluation is still evaluating down to the second which is unlikely to happen as I’m triggering the automation once a minute with a time pattern. If I’m on the right track, how would I remove the granularity to only compare minutes?

Can you post the automation that uses this Template Condition? Just the trigger and condition is sufficient.

Of course! See below:

- id: '1602703058898'
  alias: Office Speaker - Pause for Meetings
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /1
  condition:
  - condition: state
    entity_id: media_player.office_speaker
    state: playing
  - condition: state
    entity_id: person.me
    state: home
  - condition: state
    entity_id: calendar.my_calendar
    state: 'false'
    attribute: all_day
  - condition: template
    value_template: '{{as_timestamp(state_attr(''calendar.my_calendar'',
      ''start_time'')) | timestamp_custom(''%Y-%m-%d %H:%M'') == (as_timestamp(now())
      + (5*60)) | timestamp_custom(''%Y-%m-%d %H:%M'')}}'

And the state for the calendar in question looks like this

message: 
all_day: false
start_time: 2020-10-15 07:00:00
end_time: 2020-10-15 08:00:00
location: 
description: 
offset_reached: false
friendly_name: [email protected]

You do realize of course that my first question is: Are you sure it’s that specific condition that prevents executing the action and not one of the three other ones?

Well I feel dumb. I’d tried taking out just the template condition and could’ve sworn it worked but I retested and was apparently wrong. Turns out it was the state condition below, and the difference was having quotes or not on the state itself ('false' vs false). Thanks for helping me think through / troubleshoot this!

Didn’t work

  - condition: state
    entity_id: calendar.my_calendar
    state: 'false'
    attribute: all_day

Worked

  - condition: state
    entity_id: calendar.my_calendar
    state: false # no quotes
    attribute: all_day

It’s a similar situation with on and off. With quotes they are string values (and typically represent the states of binary_sensors, switches, and other entities). Without quotes they represent the names of existing variables that are boolean true and false, respectively.