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
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?
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 booleantrue and false, respectively.