I agree that example is difficult to read but, frankly, it’s like someone was purposely trying to win an obfuscation competition.
Most of that mess appears to be due to how the Automation Editor stores YAML. Beyond that, there are some design choices the author made that seem to unnecessarily complicate the template. For example, why make a macro if the template only calls it once (and so case-specific that it’s not likely to be re-usable elsewhere)?
I believe this does the exact same thing and is considerably more legible:
value_template: >
{% set ns = namespace(exists = false) %}
{% for s in states.sensor | selectattr('attributes.linkquality', 'defined') %}
{% if "Ikea" not in s.name and "linkquality" in s.name and
(s.attributes.linkquality < 15 or
now().timestamp() - s.last_updated.timestamp() > 12*60*60) -%}
{% set ns.exists = true %}
{% endif %}
{% endfor %}
{{ ns.exists }}
Personally, I would have preferred if automations employed python from the very start but with simplifications. To understand what I mean, compare how you call a service using python_script to the recently introduced pyscript.
python_script:
hass.services.call('light', 'turn_on', {'entity_id': 'light.kitchen', 'color_name': 'blue', 'transition': 2, 'brightness': 125}, False)
pyscript
light.turn_on(entity_id='light.kitchen', color_name='blue', transition=2, brightness=125)
However, I believe it’s far too late to re-engineer how existing automations work. There are alternatives available: appdaemon, python_script, and pyscript.