2019-02-21 17:49:55 +00:00
###############################################################################
# @author : Jeffrey Stone
# @date : 02/19/2019
# @package : USPS
# @description : Notifies us of mails and packages.
# Package modified from https://github.com/skalavala/smarthome/blob/master/packages/usps.yaml
###############################################################################
homeassistant :
customize :
sensor.usps_mail :
friendly_name : USPS Mail
icon : mdi:mailbox
sensor.usps_packages :
friendly_name : USPS Packages
icon : mdi:package-variant
sensor :
- platform : mqtt
name : 'USPS Mail'
state_topic : 'house/usps/mails'
value_template : "{{ value }}"
- platform : mqtt
name : USPS Packages
state_topic : 'house/usps/packages'
value_template : "{{ value }}"
2020-05-18 01:33:12 +00:00
- 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 -%}
No
{%- else -%}
{{states("sensor.mail_usps_mail")|int}}
{%- endif -%}
{{' ' }}
{%- if states("sensor.mail_usps_mail")|int <= 1 -%}
piece of mail
{%- 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.{{' '}}
2020-05-28 19:03:34 +00:00
{%- if states("sensor.mail_fedex_delivering_2")|int == 0 -%}
2020-05-18 01:33:12 +00:00
No
{%- else -%}
2020-05-28 19:03:34 +00:00
{{states("sensor.mail_fedex_delivering_@")|int}}
2020-05-18 01:33:12 +00:00
{%- endif -%}
{{' ' }}
2020-05-28 19:03:34 +00:00
{%- if states("sensor.mail_fedex_delivering_2")|int == 1 -%}
2020-05-18 01:33:12 +00:00
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()}}
2019-02-21 17:49:55 +00:00
camera :
- platform : generic
name : USPS Mail Pictures
still_image_url : !secret usps_camera_url
2020-05-18 01:33:12 +00:00
- platform : local_file
file_path : /config/images/mail_today.gif
name : mail_usps
2019-11-09 15:23:56 +00:00
automation :
2021-05-24 15:55:52 +00:00
- id : update_usps_camera_path
alias : "Update USPS Mail Camera"
trigger :
- platform : state
entity_id : sensor.mail_usps_mail
action :
- service : local_file.update_file_path
data_template :
entity_id : camera.mail_usps
file_path : >
{% if state_attr('sensor.mail_usps_mail','image') == None %}
/config/custom_components/mail_and_packages/mail_none.gif
{% else %}
/config/www/mail_and_packages/{{ state_attr('sensor.mail_usps_mail','image') }}
{% endif %}
2019-02-21 17:49:55 +00:00
# Notify USPS mails via TTS, and iOS notification with attachment
###############################################################################
- id : notify_usps_mail
alias : Notify USPS Mail
initial_state : true
trigger :
2019-11-14 01:55:04 +00:00
- platform : state
entity_id : sensor.usps_mail
2019-02-21 17:49:55 +00:00
condition :
- condition : template
value_template : '{{ states.sensor.usps_mail.state | int > 0 }}'
2019-11-14 01:55:04 +00:00
- condition : template
value_template : '{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}'
2019-02-21 17:49:55 +00:00
action :
2021-05-24 15:55:52 +00:00
- service : script.status_annc
2020-12-03 03:55:11 +00:00
data :
who : '{{ states.sensor.room_audio.state }}'
2021-05-24 15:55:52 +00:00
call_interuption : 1
speech_message : >-
2020-03-18 02:47:55 +00:00
{%- if states.sensor.usps_mail.state | int == 1 -%}
{{ [
"USPS is delivering" ,
"The postal service will be leaving" ,
"The nice lady in the mail truck is bringing us " ,
"I have scanned the incoming mail, eliminated the junk, and determined there is"
] | random }}
{{ states.sensor.usps_mail.state }} piece of mail today.
2019-02-21 17:49:55 +00:00
{%- else -%}
2020-03-18 02:47:55 +00:00
{{ [
"USPS is delivering" ,
"The postal service will be leaving" ,
"The nice lady in the mail truck is bringing us " ,
"I have scanned the incoming mail, eliminated the junk, and determined there are"
] | random }}
{{ states.sensor.usps_mail.state }} pieces of mail today.
2019-02-21 17:49:55 +00:00
{%- endif -%}
2019-07-14 01:38:53 +00:00
- service : script.text_notify
2019-02-21 17:49:55 +00:00
data_template :
2019-07-14 01:38:53 +00:00
who : "jeff"
title : "USPS Delivering Today"
2019-02-21 17:49:55 +00:00
message : "USPS will be delivering {{ states.sensor.usps_mail.state }} piece(s) of mail today."
2019-07-14 01:38:53 +00:00
# data:
# push:
# category: camera
# entity_id: "camera.usps_mail_pictures"
# attachment:
# url: "{{ states.camera.usps_mail_pictures.attributes.entity_picture }}"
# content-type: jpg
2019-11-14 01:53:43 +00:00
- service : script.twitter_notify
data_template :
message : >-
2019-11-14 14:46:14 +00:00
{{ [
2019-11-14 01:53:43 +00:00
"I just let Anchorage House know how much mail the USPS is leaving in the mailbox today. For the code checkout https://github.com/thejeffreystone/usps2mqtt #automation" ,
"One of the things I know is how much mail is being delivered because I am integrated with USPS Informed Delivery using https://github.com/thejeffreystone/usps2mqtt #automation." ,
2019-11-14 13:59:54 +00:00
"There is a letter in the mailbox. Or will be when the USPS gets here. If you want to know how I know checkout https://github.com/thejeffreystone/usps2mqtt #automation." ,
2019-11-14 01:53:43 +00:00
"Neither snow nor rain nor heat nor gloom of night prevents me from letting Anchorage House know what to expect from the USPS thanks to https://github.com/thejeffreystone/usps2mqtt #automation."
2019-11-14 14:46:14 +00:00
] | random }}
2019-02-21 17:49:55 +00:00
# Notify USPS packages via TTS. Usually there are no pictures for packages
###############################################################################
- id : notify_usps_packages
alias : Notify USPS Packages
initial_state : true
trigger :
2019-11-14 01:55:04 +00:00
- platform : state
entity_id : sensor.usps_mail
2019-02-21 17:49:55 +00:00
condition :
- condition : template
2019-11-14 01:55:04 +00:00
value_template : '{{ states.sensor.usps_mail.state | int > 0 }}'
- condition : template
value_template : '{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}'
2019-02-21 17:49:55 +00:00
action :
2021-05-24 15:55:52 +00:00
- service : script.status_annc
2019-02-21 17:49:55 +00:00
data_template :
2020-12-03 03:55:11 +00:00
who : '{{ states.sensor.room_audio.state }}'
2021-05-24 15:55:52 +00:00
call_interuption : 1
speech_message : >
2019-02-21 17:49:55 +00:00
{%- if states.sensor.usps_packages.state | int == 1 -%}
2019-07-11 11:43:49 +00:00
USPS is delivering {{ states.sensor.usps_packages.state }} package today.
2019-02-21 17:49:55 +00:00
{%- else -%}
2019-07-11 11:43:49 +00:00
USPS is delivering {{ states.sensor.usps_packages.state }} packages today.
{%- endif -%}
2019-11-12 19:36:27 +00:00
2020-05-18 01:33:12 +00:00
- alias : "Mail Notif - Mail Delieveries"
trigger :
- platform : time
at : '10:00:00'
#Trigger if mail or packages get updated
# - platform: state
# entity_id: sensor.mail_usps_mail
# - platform: state
# entity_id: sensor.mail_usps_delivering
#send only if mail or packages are more than 0
condition :
- condition : or
conditions :
- condition : template
value_template : "{{ states('sensor.mail_usps_mail') | int > 0 }}"
- condition : template
value_template : "{{ states('sensor.mail_usps_delivering') | int > 0 }}"
action :
- service : script.text_notify
data_template :
who : "jeff"
title : "Delivering Today"
message : "{{ states('sensor.mail_deliveries_message')}}"
2021-05-24 15:55:52 +00:00
- service : script.status_annc
2020-05-18 01:33:12 +00:00
data_template :
2020-12-03 03:55:11 +00:00
who : '{{ states.sensor.room_audio.state }}'
2021-05-24 15:55:52 +00:00
call_interuption : 1
speech_message : >-
2020-05-18 01:33:12 +00:00
{%- if states.sensor.mail_usps_mail.state | int == 1 -%}
{{ [
"USPS is delivering" ,
"The postal service will be leaving" ,
"The nice lady in the mail truck is bringing us " ,
"I have scanned the incoming mail,and there is"
] | random }}
{{ states.sensor.mail_usps_mail.state }} piece of mail today.
{%- else -%}
{{ [
"USPS is delivering" ,
"The postal service will be leaving" ,
"The nice lady in the mail truck is bringing us " ,
"I have scanned the incoming mail, and determined there are"
] | random }}
{{ states.sensor.mail_usps_mail.state }} pieces of mail today.
{%- endif -%}
2020-08-22 03:50:02 +00:00
2020-06-12 20:02:42 +00:00
- alias : "Delivered Package Notification"
initial_state : true
trigger :
- platform : state
entity_id : sensor.mail_fedex_delivered_2
- platform : state
entity_id : sensor.mail_ups_delivered
#send only if mail or packages are more than 0
condition :
- condition : or
conditions :
- condition : template
value_template : "{{ states('sensor.mail_fedex_delivered_2') | int > 0 }}"
- condition : template
value_template : "{{ states('sensor.mail_ups_delivered') | int > 0 }}"
action :
- service : script.text_notify
data_template :
who : "jeff"
title : "Package Delivered"
message : "Fedex/UPS just made a delivery"
2021-05-24 15:55:52 +00:00
- service : script.status_annc
2020-06-12 20:02:42 +00:00
data_template :
2020-12-03 03:55:11 +00:00
who : '{{ states.sensor.room_audio.state }}'
2021-05-24 15:55:52 +00:00
speech_message : >-
2020-06-12 20:02:42 +00:00
A package was just left on the porch.
2020-05-18 01:33:12 +00:00
call_interuption : 1