-
Notifications
You must be signed in to change notification settings - Fork 69
/
usps.yaml
executable file
·282 lines (269 loc) · 11 KB
/
usps.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
###############################################################################
# @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 }}"
- 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.{{' '}}
{%- if states("sensor.mail_fedex_delivering_2")|int == 0 -%}
No
{%- else -%}
{{states("sensor.mail_fedex_delivering_@")|int}}
{%- endif -%}
{{' '}}
{%- if states("sensor.mail_fedex_delivering_2")|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()}}
camera:
- platform: generic
name: USPS Mail Pictures
still_image_url: !secret usps_camera_url
- platform: local_file
file_path: /config/images/mail_today.gif
name: mail_usps
automation:
- 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 %}
# Notify USPS mails via TTS, and iOS notification with attachment
###############################################################################
- id: notify_usps_mail
alias: Notify USPS Mail
initial_state: true
trigger:
- platform: state
entity_id: sensor.usps_mail
condition:
- condition: template
value_template: '{{ states.sensor.usps_mail.state | int > 0 }}'
- condition: template
value_template: '{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}'
action:
- service: script.status_annc
data:
who: '{{ states.sensor.room_audio.state }}'
call_interuption: 1
speech_message: >-
{%- 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.
{%- 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, eliminated the junk, and determined there are"
] | random }}
{{ states.sensor.usps_mail.state }} pieces of mail today.
{%- endif -%}
- service: script.text_notify
data_template:
who: "jeff"
title: "USPS Delivering Today"
message: "USPS will be delivering {{ states.sensor.usps_mail.state }} piece(s) of mail today."
# data:
# push:
# category: camera
# entity_id: "camera.usps_mail_pictures"
# attachment:
# url: "{{ states.camera.usps_mail_pictures.attributes.entity_picture }}"
# content-type: jpg
- service: script.twitter_notify
data_template:
message: >-
{{ [
"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.",
"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.",
"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."
] | random }}
# Notify USPS packages via TTS. Usually there are no pictures for packages
###############################################################################
- id: notify_usps_packages
alias: Notify USPS Packages
initial_state: true
trigger:
- platform: state
entity_id: sensor.usps_mail
condition:
- condition: template
value_template: '{{ states.sensor.usps_mail.state | int > 0 }}'
- condition: template
value_template: '{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}'
action:
- service: script.status_annc
data_template:
who: '{{ states.sensor.room_audio.state }}'
call_interuption: 1
speech_message: >
{%- if states.sensor.usps_packages.state | int == 1 -%}
USPS is delivering {{ states.sensor.usps_packages.state }} package today.
{%- else -%}
USPS is delivering {{ states.sensor.usps_packages.state }} packages today.
{%- endif -%}
- 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')}}"
- service: script.status_annc
data_template:
who: '{{ states.sensor.room_audio.state }}'
call_interuption: 1
speech_message: >-
{%- 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 -%}
- 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"
- service: script.status_annc
data_template:
who: '{{ states.sensor.room_audio.state }}'
speech_message: >-
A package was just left on the porch.
call_interuption: 1