SOLVED: Template error ?syntax

Hi all,

I need to ask for your help again. I cannot figure out why this will not evaluate correctly. I’m assuming this may be a syntax issue but I can’t spot it. Please help my sanity.

{% set action_response = {"calendar.david_work":{"events":[{"start":"2026-01-21T16:00:00+00:00","end":"2026-01-21T23:45:00+00:00","summary":"4-Mid"},{"start":"2026-01-23T16:00:00+00:00","end":"2026-01-23T23:45:00+00:00","summary":"4-Mid"}]}} %}
{% set test = action_response["calendar.david_work"]["events"][0].start | as_datetime %}
{% set shift_start_hour = test.strftime('%H')|int %}

{% if shift_start_hour > 05 %}
Test
{% else %}
Error
{% endif %}

Instead of returning Test, I am instead getting the following error:

TemplateSyntaxError: expected token ‘end of statement block’, got ‘integer’

How can I get this if statement to work? Many thanks for any help you can provide.

{"calendar.david_work":{"events":[{"start":"2026-01-21T16:00:00+00:00","end":"2026-01-21T23:45:00+00:00","summary":"4-Mid"},{"start":"2026-01-23T16:00:00+00:00","end":"2026-01-23T23:45:00+00:00","summary":"4-Mid"}]}} 

I don’t understand why you are using curly brackets here. I would have these all regular parenthesis…

Also I would be plugging this in piece by piece into the developer panel to see what works.
Open your Home Assistant instance and show your template developer tools.

1 Like

Leading zeroes for integers aren’t permitted in Python, so I assume they’re also not permitted in Jinja templates:

{% if shift_start_hour > 5 %}
1 Like

You ask a great question. I’m not sure either and will change them.

I have been using the Template tab in the Developer tools section but appreciate you flagging it up in case I hadn’t been.

EDIT:

Oh, correction, I didn’t realise which part of the code you were commenting on. This is raw output copied from the “Calendar: Get Events” action and I believe is structured as JSON, so not my choice!

1 Like

This. It was this. Thank you, just couldn’t see it!