Tips on writing and debugging template sensors

See for instance an issue I’m having now, where I don’t know how to get information from home assistant to understand what is wrong:

I did an import of my macro in the action / variables section.
All seemed fine until the first event fired and the template sensor died.
The log in home assistant stated:

Logger: homeassistant.helpers.sensor
Bron: helpers/trigger_template_entity.py:208
First occurred: 21:01:47 (12 gebeurtenissen)
Laatst gelogd: 22:15:40

    Error rendering state template for sensor.woonkamer_magic_cube: TemplateSyntaxError: Encountered unknown tag 'is_cube_event'. Jinja was looking for the following tags: 'endmacro'. The innermost block that needs to be closed is 'macro'.
    Error rendering state template for sensor.woonkamer_magic_cube: UndefinedError: 'cube' is undefined
    Error rendering state template for sensor.woonkamer_magic_cube: TypeError: unhashable type: 'list'
    Error rendering state template for sensor.woonkamer_magic_cube: UndefinedError: 'cube_face' is undefined

Note that most of the error lines in de log are old (I know this due to history of what I’ve done, the log entries itself as shown lack a timestamp which is definitely not helping)