Need Help Trying To Get Template Value Of Sunset for TTS

I am trying to get today’s sunset time to use in a TTS script to my Alexa device. If I use this code:

      sun_nextsunset:
        device_class: timestamp
        friendly_name: 'Next Sunset'
        value_template: >
          {{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_local }}

I get the value of “February 8, 2022 5:21 PM”, I’m trying to get just the “5:21 PM” part. When I try this code I get an “Unknown” result:

sun_nextsunsettime:
        device_class: timestamp
        friendly_name: 'Next Sunset Time'
        value_template: >
          {{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%I:%M %p') }}

I’m not sure if it’s typo, a formatting error, or me just not knowing what I’m doing. A nudge in the right direction would be appreciated.

The template looks good to me.

Your indentation is a bit weird though. Should be:

      sun_nextsunsettime:
        device_class: timestamp
        friendly_name: 'Next Sunset Time'
        value_template: >
          {{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%I:%M %p') }}

Thanks for showing me how to use the developers tool for checking templates, that’s pretty helpful.

I fixed the indentation and copied it into the template tool and it returned the correct value, however in Home Assistant it still has the value of ‘Unknown’.

Since this template is working is there a way I can take 'February 8, 2022 5:21 PM" and strip out the Month Name, Day and year?

sun_nextsunset:
        device_class: timestamp
        friendly_name: 'Sunset Today'
        value_template: >
          {{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_local }}