2019-04-17 22:46:06 +00:00
|
|
|
###############################################################################
|
|
|
|
# @author : Mahasri Kalavala
|
|
|
|
# @date : 04/15/2017
|
|
|
|
# @package : Trash & Recycle
|
|
|
|
# @description : Trash & Recycle Pickup Scheduler and Reminder
|
|
|
|
###############################################################################
|
|
|
|
homeassistant:
|
|
|
|
customize:
|
|
|
|
sensor.trash_day:
|
|
|
|
friendly_name: Is it Trash Day today?
|
|
|
|
icon: mdi:delete-variant
|
|
|
|
sensor.recycle_day:
|
|
|
|
friendly_name: Is it Recycle Day today?
|
|
|
|
icon: mdi:recycle
|
|
|
|
sensor.trash_pickup_day:
|
|
|
|
friendly_name: Trash Pickup Day
|
|
|
|
icon: mdi:calendar-today
|
|
|
|
hidden: true
|
|
|
|
sensor.recycle_pickup_day:
|
|
|
|
friendly_name: Recycle Pickup Day
|
|
|
|
icon: mdi:calendar-today
|
|
|
|
hidden: true
|
|
|
|
sensor.recycle_pickup_week:
|
|
|
|
friendly_name: Recycle Pickup Week
|
|
|
|
icon: mdi:calendar-today
|
|
|
|
hidden: true
|
|
|
|
sensor.current_week:
|
|
|
|
friendly_name: Current Week is
|
|
|
|
icon: mdi:calendar-question
|
|
|
|
group.trash_schedule:
|
|
|
|
friendly_name: Trash Schedule
|
|
|
|
icon: mdi:delete-variant
|
|
|
|
group.recycle_schedule:
|
|
|
|
friendly_name: Trash Schedule
|
|
|
|
icon: mdi:recycle
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# UI Elements
|
|
|
|
###############################################################################
|
|
|
|
input_select:
|
|
|
|
trash_pickup_day:
|
|
|
|
name: Current Trash Pickup Day (Evey Week)
|
|
|
|
options:
|
2020-09-30 02:36:02 +00:00
|
|
|
- Monday
|
|
|
|
- Tuesday
|
|
|
|
- Wednesday
|
|
|
|
- Thursday
|
|
|
|
- Friday
|
|
|
|
- Saturday
|
|
|
|
- Sunday
|
|
|
|
- unknown
|
2019-04-17 22:46:06 +00:00
|
|
|
icon: mdi:delete-variant
|
|
|
|
recycle_pickup_day:
|
|
|
|
name: Current Recycle Pickup Day (Every Other Week)
|
|
|
|
options:
|
2020-09-30 02:36:02 +00:00
|
|
|
- Monday
|
|
|
|
- Tuesday
|
|
|
|
- Wednesday
|
|
|
|
- Thursday
|
|
|
|
- Friday
|
|
|
|
- Saturday
|
|
|
|
- Sunday
|
|
|
|
- unknown
|
2019-04-17 22:46:06 +00:00
|
|
|
icon: mdi:recycle
|
|
|
|
recycle_pickup_week:
|
|
|
|
name: Select Recycle Pickup Week based on Current Week above
|
|
|
|
options:
|
2020-09-30 02:36:02 +00:00
|
|
|
- Even Weeks
|
|
|
|
- Odd Weeks
|
|
|
|
- unknown
|
2019-04-17 22:46:06 +00:00
|
|
|
icon: mdi:recycle
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Sensor Definitions
|
|
|
|
###############################################################################
|
|
|
|
sensor:
|
|
|
|
- platform: time_date
|
|
|
|
display_options:
|
|
|
|
- time
|
|
|
|
- date
|
|
|
|
- date_time
|
|
|
|
- time_date
|
|
|
|
- time_utc
|
|
|
|
|
|
|
|
- platform: mqtt
|
|
|
|
state_topic: "/home/trashpickupday"
|
|
|
|
name: "Trash Pickup Day"
|
|
|
|
value_template: "{{ value }}"
|
2020-09-30 02:36:02 +00:00
|
|
|
qos: 1
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: mqtt
|
|
|
|
state_topic: "/home/recyclepickupday"
|
|
|
|
name: "Recycle Pickup Day"
|
|
|
|
value_template: "{{ value }}"
|
|
|
|
qos: 1
|
|
|
|
- platform: mqtt
|
|
|
|
state_topic: "/home/recyclepickupweek"
|
|
|
|
name: "Recycle Pickup Week"
|
|
|
|
value_template: "{{ value }}"
|
|
|
|
qos: 1
|
|
|
|
|
2020-09-30 02:36:02 +00:00
|
|
|
###############################################################################
|
|
|
|
# Sensor to hold info about current week is an odd week or an even week of the year
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: template
|
|
|
|
sensors:
|
|
|
|
current_week:
|
|
|
|
value_template: >-
|
|
|
|
{% set year = states.sensor.date_time.state.split(',')[0].split('-')[0] %}
|
|
|
|
{% set month = states.sensor.date_time.state.split(',')[0].split('-')[1] %}
|
|
|
|
{% set date = states.sensor.date_time.state.split(',')[0].split('-')[2] %}
|
|
|
|
{% set today = strptime(year ~ '-' ~ month ~ '-' ~ date , '%Y-%m-%d') %}
|
|
|
|
{%- if (as_timestamp(today) | timestamp_custom('%U', true) | int ) % 2 == 0 -%}
|
|
|
|
Even Week (Week# {{ as_timestamp(today) | timestamp_custom('%U', true) }})
|
|
|
|
{%- else -%}
|
|
|
|
Odd Week (Week# {{ as_timestamp(today) | timestamp_custom('%U', true) }})
|
|
|
|
{%- endif -%}
|
|
|
|
|
2020-09-30 02:36:02 +00:00
|
|
|
###############################################################################
|
|
|
|
# Trash - Pickup schedule is EVERY week.
|
|
|
|
# Set the day to a day before the actual day leaving time for reminders
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: template
|
|
|
|
sensors:
|
|
|
|
trash_day:
|
|
|
|
value_template: >-
|
|
|
|
{% set year = states.sensor.date_time.state.split(',')[0].split('-')[0] %}
|
|
|
|
{% set month = states.sensor.date_time.state.split(',')[0].split('-')[1] %}
|
|
|
|
{% set date = states.sensor.date_time.state.split(',')[0].split('-')[2] %}
|
|
|
|
{% set today = strptime(year ~ '-' ~ month ~ '-' ~ date , '%Y-%m-%d') %}
|
2022-12-03 16:28:12 +00:00
|
|
|
{%- set pickupDay = states.sensor.trash_pickup_day.state | lower -%}
|
2019-04-17 22:46:06 +00:00
|
|
|
{%- if as_timestamp(today)| timestamp_custom('%A', true) | lower == pickupDay -%}
|
|
|
|
yes
|
|
|
|
{%- else -%}
|
|
|
|
no
|
|
|
|
{%- endif -%}
|
|
|
|
|
2020-09-30 02:36:02 +00:00
|
|
|
###############################################################################
|
|
|
|
# Recycle - Pickup schedule is every other week.
|
|
|
|
# Set the day to a day before the actual day leaving time for reminders
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: template
|
|
|
|
sensors:
|
|
|
|
recycle_day:
|
|
|
|
value_template: >-
|
|
|
|
{% set year = states.sensor.date_time.state.split(',')[0].split('-')[0] %}
|
|
|
|
{% set month = states.sensor.date_time.state.split(',')[0].split('-')[1] %}
|
|
|
|
{% set date = states.sensor.date_time.state.split(',')[0].split('-')[2] %}
|
2022-12-03 16:28:12 +00:00
|
|
|
{% set today = strptime(year ~ '-' ~ month ~ '-' ~ date , '%Y-%m-%d') %}
|
2019-04-17 22:46:06 +00:00
|
|
|
{%- set pickupDay = states.sensor.recycle_pickup_day.state | lower -%}
|
|
|
|
{% if states.input_select.recycle_pickup_week.state | lower == "even weeks" %}
|
|
|
|
{%- set evenWeekPickup = "true" %}
|
|
|
|
{% else %}
|
|
|
|
{%- set evenWeekPickup = "false" %}
|
|
|
|
{% endif %}
|
|
|
|
{%- macro day_of_week(timestamp) -%}
|
|
|
|
{{ as_timestamp(timestamp)| timestamp_custom('%A', true) | lower }}
|
2022-12-03 16:28:12 +00:00
|
|
|
{%- endmacro %}
|
2019-04-17 22:46:06 +00:00
|
|
|
{%- macro week_number_of_year() -%}
|
|
|
|
{{ as_timestamp(today) | timestamp_custom('%U', true) | int }}
|
|
|
|
{%- endmacro %}
|
|
|
|
{%- macro is_it_this_week() -%}
|
|
|
|
{%- if as_timestamp(today) | timestamp_custom('%U', true) | int % 2 == 0 -%}
|
|
|
|
{%- if evenWeekPickup == "true" -%}
|
|
|
|
true
|
|
|
|
{%- else -%}
|
|
|
|
false
|
|
|
|
{%- endif -%}
|
|
|
|
{%- else -%}
|
|
|
|
{%- if evenWeekPickup == "true" -%}
|
|
|
|
false
|
|
|
|
{%- else -%}
|
|
|
|
true
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endmacro -%}
|
|
|
|
{%- macro is_it_today() -%}
|
|
|
|
{%- if is_it_this_week() == "true" -%}
|
|
|
|
{%- if day_of_week(today) | lower == pickupDay -%}
|
|
|
|
yes
|
|
|
|
{%- else -%}
|
|
|
|
no
|
|
|
|
{%- endif -%}
|
|
|
|
{%- else -%}
|
|
|
|
no
|
|
|
|
{%- endif -%}
|
|
|
|
{%- endmacro -%}
|
|
|
|
{{- is_it_today() -}}
|
|
|
|
|
|
|
|
###############################################################################
|
2020-09-30 02:36:02 +00:00
|
|
|
# _ _ _
|
|
|
|
# /\ | | | | (_)
|
|
|
|
# / \ _ _| |_ ___ _ __ ___ __ _| |_ _ ___ _ __ ___
|
2019-04-17 22:46:06 +00:00
|
|
|
# / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
|
|
|
|
# / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
|
2020-09-30 02:36:02 +00:00
|
|
|
# /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
|
|
|
|
#
|
2019-04-17 22:46:06 +00:00
|
|
|
###############################################################################
|
|
|
|
automation:
|
2020-09-30 02:36:02 +00:00
|
|
|
###############################################################################
|
|
|
|
# The schedule can be changed via UI. The updated schedules are saved in MQTT
|
|
|
|
# The input_selects don't maintain state automatically - hence this code
|
|
|
|
# These automations are hidden - no interaction with user is required.
|
|
|
|
# Save & Restore Functionality
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- alias: Trash Pickup Day Changed
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
platform: state
|
|
|
|
entity_id: input_select.trash_pickup_day
|
|
|
|
action:
|
|
|
|
- service: mqtt.publish
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
topic: "/home/trashpickupday"
|
|
|
|
retain: true
|
2020-09-30 02:36:02 +00:00
|
|
|
payload: "{{ states.input_select.trash_pickup_day.state }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
|
|
|
|
- alias: Recycle Pickup Day Changed
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
platform: state
|
|
|
|
entity_id: input_select.recycle_pickup_day
|
|
|
|
action:
|
|
|
|
- service: mqtt.publish
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
topic: "/home/recyclepickupday"
|
|
|
|
retain: true
|
2020-09-30 02:36:02 +00:00
|
|
|
payload: "{{ states.input_select.recycle_pickup_day.state }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
|
|
|
|
- alias: Recycle Pickup Week Changed
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
platform: state
|
|
|
|
entity_id: input_select.recycle_pickup_week
|
|
|
|
action:
|
|
|
|
- service: mqtt.publish
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
topic: "/home/recyclepickupweek"
|
|
|
|
retain: true
|
2020-09-30 02:36:02 +00:00
|
|
|
payload: "{{ states.input_select.recycle_pickup_week.state }}"
|
2019-04-17 22:46:06 +00:00
|
|
|
|
|
|
|
- alias: Restore Trash Recycle Settings on Startup
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
platform: homeassistant
|
|
|
|
event: start
|
|
|
|
action:
|
|
|
|
- delay:
|
2020-09-30 02:36:02 +00:00
|
|
|
minutes: 1
|
2019-04-17 22:46:06 +00:00
|
|
|
- service: input_select.select_option
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_select.trash_pickup_day
|
|
|
|
option: "{{states.sensor.trash_pickup_day.state}}"
|
|
|
|
- service: input_select.select_option
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_select.recycle_pickup_day
|
|
|
|
option: "{{states.sensor.recycle_pickup_day.state}}"
|
|
|
|
- service: input_select.select_option
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_select.recycle_pickup_week
|
|
|
|
option: "{{states.sensor.recycle_pickup_week.state}}"
|
|
|
|
|
2020-09-30 02:36:02 +00:00
|
|
|
###############################################################################
|
|
|
|
# Reminder code - Reminds 5 times every hour starting 4 PM
|
|
|
|
# Conditions: Only notifies when someone is at home
|
|
|
|
###############################################################################
|
2019-04-17 22:46:06 +00:00
|
|
|
- alias: Trash and Recycle Pickup Reminder
|
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
- platform: time
|
2020-09-30 02:36:02 +00:00
|
|
|
at: "16:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: time
|
2020-09-30 02:36:02 +00:00
|
|
|
at: "17:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: time
|
2020-09-30 02:36:02 +00:00
|
|
|
at: "18:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: time
|
2020-09-30 02:36:02 +00:00
|
|
|
at: "19:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: time
|
2020-09-30 02:36:02 +00:00
|
|
|
at: "20:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
- platform: time
|
2020-09-30 02:36:02 +00:00
|
|
|
at: "21:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
condition:
|
|
|
|
condition: and
|
|
|
|
conditions:
|
2020-09-30 02:36:02 +00:00
|
|
|
- condition: template
|
2022-12-04 17:38:48 +00:00
|
|
|
value_template: "{{ states('input_boolean.trash_alerts') == 'on' }}"
|
2022-12-01 01:27:26 +00:00
|
|
|
- condition: template
|
2022-12-03 16:28:12 +00:00
|
|
|
value_template: "{{ states('input_boolean.home_mode_away') == 'off' }}"
|
2020-09-30 02:36:02 +00:00
|
|
|
- condition: or
|
|
|
|
conditions:
|
|
|
|
- condition: state
|
|
|
|
entity_id: sensor.trash_day
|
|
|
|
state: "yes"
|
|
|
|
- condition: state
|
|
|
|
entity_id: sensor.recycle_day
|
|
|
|
state: "yes"
|
2019-04-17 22:46:06 +00:00
|
|
|
action:
|
2022-12-03 16:28:12 +00:00
|
|
|
- service: script.notify_family
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
message: >
|
|
|
|
{% if states.sensor.trash_day.state == "yes" and states.sensor.recycle_day.state == "yes" %}
|
|
|
|
Tomorrow is the Trash AND Recycle Pickup day!
|
|
|
|
{% elif states.sensor.trash_day.state == "yes" %}
|
|
|
|
Attention!: Tomorrow is the Trash Pickup day. Please don't forget to put the Trash bin outside tonight!
|
|
|
|
{% elif states.sensor.recycle_day.state == "yes" %}
|
|
|
|
Attention!: Tomorrow is the Recycle Pickup day. Please don't forget to put the recycle bin outside tonight!
|
|
|
|
{% endif %}
|
2022-12-03 16:28:12 +00:00
|
|
|
notify_options:
|
|
|
|
- telegram
|
|
|
|
- tv
|
|
|
|
- led
|
2019-04-17 22:46:06 +00:00
|
|
|
|
2022-12-04 17:38:48 +00:00
|
|
|
- alias: Reset Trash Alerts
|
2019-04-17 22:46:06 +00:00
|
|
|
initial_state: true
|
|
|
|
trigger:
|
|
|
|
- platform: time
|
2020-09-30 02:36:02 +00:00
|
|
|
at: "09:00:00"
|
2019-04-17 22:46:06 +00:00
|
|
|
action:
|
|
|
|
- service: input_boolean.turn_on
|
2022-12-04 17:38:48 +00:00
|
|
|
entity_id: input_boolean.trash_alerts
|
2019-04-17 22:46:06 +00:00
|
|
|
- service: input_select.select_option
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_select.trash_pickup_day
|
|
|
|
option: "{{states.sensor.trash_pickup_day.state}}"
|
|
|
|
- service: input_select.select_option
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_select.recycle_pickup_day
|
|
|
|
option: "{{states.sensor.recycle_pickup_day.state}}"
|
|
|
|
- service: input_select.select_option
|
2022-12-05 00:02:34 +00:00
|
|
|
data:
|
2019-04-17 22:46:06 +00:00
|
|
|
entity_id: input_select.recycle_pickup_week
|
2020-09-30 02:36:02 +00:00
|
|
|
option: "{{states.sensor.recycle_pickup_week.state}}"
|