Skip to content

Mail Summary Message

Chris edited this page Nov 8, 2021 · 5 revisions

Text Summary Examples

The text summary shown on the custom card is not built into the integration. This is to allow the user to customize it based on their needs and the delivery services they have set up.

The following examples illustrate how to create a sensor with summary text describing the state of your deliveries that can be used in your Lovelace cards or in notifications. Add to the sensor: portion of the configuartion.yaml.

Option 1

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

Option 2

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