Legacy Template Sensor to long

I have all these template sensors that apparently are being deprecated. Rather than continuing to use YAML directly thought I’d try doing things thru the GUI. In theory have them all moved over and the yaml I entered all commented out or renamed. I have one for a mail integration for sending out messages about mail available or coming today. Not sure I’m doing it right but looks like the GUI has a limit to 255 characters? So here is my code, any examples how to load this and as I’m trying to use the new ways of doing things, thru the GUI:

- platform: template
  sensors:
    mail_deliveries_message:
      friendly_name: "Deliveries Summary"
      value_template: >
        {# Deliveries Sentence #}
          {% macro deliveries_sentence() -%}
                {%- if states("sensor.imap_comcast_net_mail_usps_mail")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.imap_comcast_net_mail_usps_mail")|int}}
                {%- endif -%}
              {{' '}}
                {%- if states("sensor.imap_comcast_net_mail_usps_mail")|int <= 1 -%}
                  pieces of mail
                {%- else -%}
                  pieces of mail
                {%- endif -%}
              {{' '}}will be delivered.{{' '}}
                {%- if states("sensor.imap_comcast_net_mail_usps_delivering")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.imap_comcast_net_mail_usps_delivering")|int}}
                {%- endif -%}
              {{' '}}
                {%- if states("sensor.imap_comcast_net_mail_usps_delivering")|int == 1 -%}
                  USPS package is
                {%- else -%}
                  USPS packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
                {%- if states("sensor.imap_comcast_net_mail_fedex_delivering")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.imap_comcast_net_mail_fedex_delivering")|int}}
                {%- endif -%}
              {{' '}}
                {%- if states("sensor.imap_comcast_net_mail_fedex_delivering")|int == 1 -%}
                  FedEx package is
                {%- else -%}
                  Fedex packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
              {%- if states("sensor.imap_comcast_net_mail_ups_delivering")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.imap_comcast_net_mail_ups_delivering")|int}}
                {%- endif -%}
              {{' '}}
                {%- if states("sensor.imap_comcast_net_mail_ups_delivering")|int == 1 -%}
                  UPS package is
                {%- else -%}
                  UPS packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
              {%- if states("sensor.imap_comcast_net_mail_amazon_packages")|int == 0 -%}
                  No
                {%- else -%}
                  {{states("sensor.imap_comcast_net_mail_amazon_packages")|int}}
                {%- endif -%}
              {{' '}}
                {%- if states("sensor.imap_comcast_net_mail_amazon_packages")|int == 1 -%}
                  Amazon package is
                {%- else -%}
                  Amazon packages are
                {%- endif -%}
              {{' '}}in transit.{{' '}}
          {%- endmacro %}
        {{deliveries_sentence()}}

Why use a macro if it doesn’t do anything macro-like?

A macro is meant to define a process that can be used multiple times. The one you present only gets used once, and contains nearly the same set of if/then statements 5 times.

Instead, use a macro that sets up the logic and process, then call it for each set of inputs:

{%- macro deliveries_sentence(count_ent, type, single_phrase, plural_phrase, end_phrase) -%}
{%- set count = states("sensor.imap_comcast_net_mail_"~count_ent)|int(0) -%}
{{"No" if count == 0 else count }} {{type}}{{ single_phrase if count == 1 else plural_phrase }} {{end_phrase}}.
{%- endmacro -%}

{{ deliveries_sentence("usps_mail","piece"," of mail","s of mail","will be delivered")}}
{{ deliveries_sentence("usps_delivering","USPS package"," is","s are","in transit")}}
{{ deliveries_sentence("fedex_delivering","FedEx package"," is","s are","in transit")}}
{{ deliveries_sentence("ups_delivering","UPS package"," is","s are","in transit")}}
{{ deliveries_sentence("amazon_packages","Amazon package"," is","s are","in transit")}}

This could be done a number of other ways as well, like a for loop that iterates over a list of lists.

All that being said, your original template acts as expected when I set the template sensor up in the UI. There is a 255 character limit for the rendered state value, but I’m pretty sure the field in the UI config flow can handle significantly more than that… though I’ve never tested it’s limits.

Fantastic, thank you so much!!