-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaste-can-notices.yaml
179 lines (165 loc) · 5.52 KB
/
waste-can-notices.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
---
# SPDX-License-Identifier: MIT
blueprint:
name: Waste Can Notifier (v0.3)
description: |
Basic notifier for use with Rental Control for requesting guest to take out
waste cans.
Notifications are expected to go to a Zulip notify service
domain: automation
input:
notify_service:
name: Zulip Notify
description: |
Notify service name to send to. Should be a Zulip (or compatible)
notify service
default: "zulip"
notify_topic:
name: Notification topic
description: |
The topic that will be used in the Zulip stream
default: "Waste Cans"
notification_time:
name: Time to send the notification
description: |
The time each day that the automation will fire to send the
notification.
selector:
time: {}
default: "09:00:00"
garbage_sensor:
name: Sensor for garbage collection
description: The sensor used for garbage collection
selector:
entity:
integration: waste_collection_schedule
domain: sensor
recycling_sensor:
name: Sensor for the recycling collection
description: The sensor used for the recycling collection
selector:
entity:
integration: waste_collection_schedule
domain: sensor
rental_control_event_0:
name: Primary Rental Control Event
description: The current or exiting guest event
selector:
entity:
integration: rental_control
domain: sensor
rental_control_event_1:
name: Secondary Rental Control Event
description: The next guest event
selector:
entity:
integration: rental_control
domain: sensor
garbage_message:
name: Message for garbage only
description: |
The message for when only garbage is to be collected
default: "take out the garbage this evening."
recycling_message:
name: Message for recycling and garbage
description: |
The message for when garbage and reycling is to be collected
# yamllint disable-line rule:line-length
default: "take out the garbage and recycling this evening."
guest_message:
name: Message prefix for asking guest
description: |
The message prefix for if the guest is notified
default: "Please ask the guest to"
cleaner_message:
name: Message prefix for asking the cleaner
description: |
The message prefix for if the cleaner is notified
default: "Cleaner please"
owner_message:
name: Message prefix for asking the owner
description: |
The message prefix for if the owner is notified
default: "Owner please"
mode: single
trigger:
- platform: time
at: !input notification_time
variables:
# Sensors
input_garbage_sensor: !input garbage_sensor
input_recycling_sensor: !input recycling_sensor
# Dates
today: "{{ int(as_timestamp(now().date())) }}"
tomorrow: "{{ today + 86400 }}"
# Events
# yamllint disable rule:line-length
input_rc_event_0: !input rental_control_event_0
event_0_start: >-
{%- if state_attr(input_rc_event_0, 'start') != none -%}
{{ int(as_timestamp(state_attr(input_rc_event_0, 'start').date(), tomorrow)) }}
{%- else -%}
{{ tomorrow }}
{%- endif -%}
event_0_end: >-
{%- if state_attr(input_rc_event_0, 'end') != none -%}
{{ int(as_timestamp(state_attr(input_rc_event_0, 'end').date(), tomorrow)) }}
{%- else -%}
{{ tomorrow }}
{%- endif -%}
input_rc_event_1: !input rental_control_event_1
event_1_start: >-
{% if state_attr(input_rc_event_1, 'start') != none -%}
{{ int(as_timestamp(state_attr(input_rc_event_1, 'start').date(), tomorrow)) }}
{%- else -%}
{{ tomorrow }}
{%- endif -%}
# yamllint enable
# Notify
input_garbage_message: !input garbage_message
input_recycling_message: !input recycling_message
input_guest_message: !input guest_message
input_cleaner_message: !input cleaner_message
input_owner_message: !input owner_message
input_notify_service: !input notify_service
input_notify_topic: !input notify_topic
notify_message: >-
{%- if int(states(input_recycling_sensor)) <= 1 -%}
{{ input_recycling_message }}
{%- else -%}
{{ input_garbage_message }}
{%- endif -%}
# yamllint disable-line rule:line-length
notify_target: "{{ input_notify_service | lower | replace('notify.', '') | replace(' ', '_') }}"
condition:
or:
- "{{ int(states(input_garbage_sensor)) == 1 }}"
- "{{ int(states(input_recycling_sensor)) == 1 }}"
action:
- choose:
- alias: Notify Owner
conditions:
- "{{ event_0_start > today }}"
sequence:
- service: notify.{{ notify_target }}
data:
title: "{{ input_notify_topic }}"
message: "{{ input_owner_message }} {{ notify_message }}"
- alias: Notify Cleaner
conditions:
- "{{ event_0_end == today }}"
- "{{ event_1_start == today }}"
sequence:
- service: notify.{{ notify_target }}
data:
title: "{{ input_notify_topic }}"
message: "{{ input_cleaner_message }} {{ notify_message }}"
- alias: Notify Guest
conditions:
- "{{ event_0_start <= today }}"
- "{{ event_0_end > today }}"
sequence:
- service: notify.{{ notify_target }}
data:
title: "{{ input_notify_topic }}"
message: "{{ input_guest_message }} {{ notify_message }}"