Skip to content

Instantly share code, notes, and snippets.

@rpitera
Created June 10, 2020 18:12
Show Gist options
  • Save rpitera/1d550cea874287a0ae4f5fce94e4ba5d to your computer and use it in GitHub Desktop.
Save rpitera/1d550cea874287a0ae4f5fce94e4ba5d to your computer and use it in GitHub Desktop.
Template sensor to create proper deliveries message including Amazon.
# Mail and Package Sensors
- platform: template
sensors:
mail_deliveries_message:
friendly_name: "Deliveries Summary"
entity_id:
- sensor.mail_usps_mail
- sensor.mail_usps_delivering
- sensor.mail_fedex_delivering
- sensor.mail_ups_delivering
value_template: >
{# Deliveries Sentence #}
{% macro deliveries_sentence() -%}
{%- if states("sensor.mail_usps_mail")|int == 0 -%}
No
{%- else -%}
{{states("sensor.mail_usps_mail")|int}}
{%- endif -%}
{{' '}}
{%- if states("sensor.mail_usps_mail")|int <= 1 -%}
mail piece
{%- else -%}
pieces of mail
{%- endif -%}
{{' '}}will be delivered.{{' '}}
{%- if states("sensor.mail_usps_delivering")|int == 0 -%}
No
{%- else -%}
{{states("sensor.mail_usps_delivering")|int}}
{%- endif -%}
{{' '}}
{%- if states("sensor.mail_usps_delivering")|int == 1 -%}
USPS package is
{%- else -%}
USPS packages are
{%- endif -%}
{{' '}}in transit.{{' '}}
{%- if states("sensor.mail_fedex_delivering")|int == 0 -%}
No
{%- else -%}
{{states("sensor.mail_fedex_delivering")|int}}
{%- endif -%}
{{' '}}
{%- if states("sensor.mail_fedex_delivering")|int == 1 -%}
FedEx package is
{%- else -%}
Fedex packages are
{%- endif -%}
{{' '}}in transit.{{' '}}
{%- if states("sensor.mail_ups_delivering")|int == 0 -%}
No
{%- else -%}
{{states("sensor.mail_ups_delivering")|int}}
{%- endif -%}
{{' '}}
{%- if states("sensor.mail_ups_delivering")|int == 1 -%}
UPS package is
{%- else -%}
UPS packages are
{%- endif -%}
{{' '}}in transit.{{' '}}
{%- if states("sensor.mail_amazon_packages")|int == 0 -%}
No
{%- else -%}
{{states("sensor.mail_amazon_packages")|int}}
{%- endif -%}
{{' '}}
{%- if states("sensor.mail_amazon_packages")|int == 1 -%}
Amazon package is
{%- else -%}
Amazon packages are
{%- endif -%}
{{' '}}in transit.{{' '}}
{%- endmacro %}
{{deliveries_sentence()}}
@drguitarum2005
Copy link

Does this go directly in your config? It doesn't seem to be creating the sensor.mail_deliveries_message for me

@rpitera
Copy link
Author

rpitera commented May 27, 2021

I have a split config using include statements, so this goes in my sensors.yaml file and then I include it with a line in my configuration.yaml with the following:

sensor: !include devices/sensors.yaml

If you run a standard configuration, you should put this under your sensor: section

@drguitarum2005
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment