mysmarthome/packages/usps.yaml

98 lines
3.7 KiB
YAML

###############################################################################
# @Author : Mahasri Kalavala
# @Date : 01/27/2018
# @Package : USPS Package - notifies me of mails and packages.
###############################################################################
homeassistant:
customize:
sensor.usps_mail:
friendly_name: USPS Mail
icon: mdi:email-outline
sensor.usps_packages:
friendly_name: USPS Packages
icon: mdi:package-variant
sensor:
- platform: mqtt
name: "USPS Mail"
state_topic: "/usps/mails"
value_template: "{{ value }}"
- platform: mqtt
name: USPS Packages
state_topic: "/usps/packages"
value_template: "{{ value }}"
camera:
- platform: generic
name: USPS Mail Pictures
still_image_url: !secret usps_camera_url
###############################################################################
# _ _ _
# /\ | | | | (_)
# / \ _ _| |_ ___ _ __ ___ __ _| |_ _ ___ _ __ ___
# / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
# / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
# /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
#
###############################################################################
automation:
# Notify USPS mails via TTS, and iOS notification with attachment
###############################################################################
- alias: Notify USPS Mail
initial_state: true
trigger:
- platform: state
entity_id: sensor.usps_mail
condition:
- condition: template
value_template: "{{ states('sensor.usps_mail') != 'unknown' }}"
- condition: template
value_template: "{{ states('sensor.usps_mail') | int > 0 }}"
- condition: template
value_template: "{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}"
action:
- service: script.voice_notify
data_template:
message: >
{%- if states('sensor.usps_mail') | int == 1 -%}
Attention: USPS is delivering {{ states('sensor.usps_mail') }} mail today.
{%- else -%}
Attention: USPS is delivering {{ states('sensor.usps_mail') }} mails today.
{%- endif -%}
- service: notify.ios_devices
data_template:
message: "USPS will be delivering {{ states('sensor.usps_mail') }} mail(s) today."
data:
push:
category: camera
entity_id: "camera.usps_mail_pictures"
attachment:
url: "{{ state_attr('camera.usps_mail_pictures', 'entity_picture') }}"
content-type: jpg
# Notify USPS packages via TTS. Usually there are no pictures for packages
###############################################################################
- alias: Notify USPS Packages
initial_state: true
trigger:
- platform: state
entity_id: sensor.usps_packages
condition:
- condition: template
value_template: "{{ states('sensor.usps_packages') != 'unknown' }}"
- condition: template
value_template: "{{ states('sensor.usps_packages') | int > 0 }}"
- condition: template
value_template: "{{ ((now().hour | int) > 7) and ((now().hour | int) < 16) }}"
action:
- service: script.voice_notify
data_template:
message: >
{%- if states('sensor.usps_packages') | int == 1 -%}
Attention: USPS is delivering {{ states('sensor.usps_packages') }} package today.
{%- else -%}
Attention: USPS is delivering {{ states('sensor.usps_packages') }} packages today.
{%- endif -%}