Debug command_line value_templates?

I’ve got some long value_templates used in command_line sensors and cannot debug them properly. They have date comparisons against values in other command_line sensors, etc. which work perfectly in the ‘Developer Tools’ → template area for validation. Yet at runtime it is returning “unknown” for the value. Here’s a copy of the code, any ideas (I had commented it out until I’ve figured out the issue)…?

value_template: >

{% set errortime = strptime(now().year ~ ’ ’ ~ ’ ‘.join(value.split(’ ‘)[0:3]),’%Y %a %m/%d %I:%M:%S%p’) -%}

{%- set errordestination = ((value | regex_findall(’(.+): Failed to publish’) | first).strip() | regex_findall(’: (\w+)’) | first).strip() -%}

{%- set sensortoretry = ‘sensor.weewx_last_sent_to_’ + errordestination -%}

{%- set sensorretriedtime = strptime(now().year ~ ’ ’ ~ ’ ‘.join(states(sensortoretry).split(’ ‘)[0:3]),’%Y %a %m/%d %I:%M:%S%p’) -%}

{%- if sensorretriedtime > errortime -%}

{{ ‘No errors’ }}

{%- else -%}

{%- set data = value | regex_findall(’(([0-9]+))’) | first | int | as_datetime | as_local -%}

{%- set ts = data.year ~ ’ ’ ~ (value | regex_findall(’(.+)kruse-pi’) | first).strip() -%}

{%- set time = strptime(ts, ‘%Y %b %d %H:%M:%S’, data) | as_local -%}

{{ time.strftime(’%a

Resolved! Numerous reboots, just kept at it endlessly with everything commented out uncommenting one line at a time until I got one line to work, uncommented the next line and worked out all the kinks in that one, etc. No clear way to debug because code that works perfectly in the template editor often fails in a configuration.yaml command_line value_template. The main issues were a tweak to the two different datetime syntax arrangements used in separate calls to strptime() and the second strptime() function call requiring a third argument.