-
Notifications
You must be signed in to change notification settings - Fork 57
/
radon_notify.yaml
175 lines (164 loc) · 6.2 KB
/
radon_notify.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
#
# Check if radon levels are too high
#
# Radon (Rn) is an element that comes from the natural decay of underground
# uranium, thorium, and radium. It is a radioactive, colorless, and odorless
# noble gas. Radon-222 tends to accumulate in enclosed locations like houses.
# It has a short half-life of 3.8 days before decaying into other short-lived
# radioactive gases (Polonium-218, Lead-214, Bismuth-214, Polonium-214) then
# into solid, long-lasting, radiactive Lead-210. This means that when breathing
# in air or dust particles, radioactive isotopes either transmutate or get
# deposited inside the lungs, increasing the odds of developping lung cancer.
# Keeping a place well ventilated is a good way to mitigate this risk.
#
# Notifications are sent whenever radon levels reach tresholds, and reminders
# are then sent every few hours until levels get back to normal. Only
# a few reminders are sent out however, to avoid notification spam when action
# cannot immediately be taken to bring radiation levels back to normal (say,
# while out of town).
#
# @link https://en.wikipedia.org/wiki/Radon#Concentration_scale
# @link https://www.who.int/news-room/fact-sheets/detail/radon-and-health
# @link https://airthings.com/us/radon-levels/
#
# @subscribe counter.radon_notify
# @subscribe input_boolean.quiet_mode
# @subscribe sensor.radon_daily
#
# @publish counter.radon_notify
#
# @see automations/notifications/radon_notify_reset.yaml
#
- id: radon_notify
alias: "Radon NOTIFY"
trigger:
# When radon levels are over the recommended maximum.
- platform: numeric_state
entity_id: sensor.radon_daily
above: 200
for:
seconds: 10
# When radon levels are way too high.
- platform: numeric_state
entity_id: sensor.radon_daily
above: 150
for:
seconds: 10
# When radon levels are getting too high.
- platform: numeric_state
entity_id: sensor.radon_daily
above: 100
for:
seconds: 10
# When quiet mode is disabled.
- platform: state
entity_id: input_boolean.quiet_mode
to: 'off'
for:
minutes: 2
# When the last check was a while ago (reminder).
- platform: time_pattern
hours: '/12'
minutes: 00
seconds: 00
condition:
# If automation was not trigered lately (hey, do not nag).
- condition: template
value_template: >-
{% set delay = 6 * 60 * 60 %}
{% set current = as_timestamp(utcnow()) %}
{% set last = as_timestamp(state_attr('automation.radon_notify', 'last_triggered')) | float %}
{{ current - last > delay }}
# If radon levels are too high.
- condition: numeric_state
entity_id: sensor.radon_daily
above: 100
action:
# Pin a warning message in the frontend.
- service: persistent_notification.create
data:
notification_id: radon
data_template:
title: >-
{% set radon = states('sensor.radon_daily') | int %}
{% if (radon >= 200) %}
Radon levels are WAY too high
{% elif (radon >= 150) %}
Radon levels are too high
{% elif (radon >= 100) %}
Radon levels are getting too high
{% endif %}
message: >-
{% set radon = states('sensor.radon_daily') | int %}
{% set unit = state_attr('sensor.radon_daily', 'unit_of_measurement') %}
{% if (radon >= 200) %}
{{ radon }} {{ unit }} is dangerous!<br>
<strong>Air out the place NOW, and start looking into mitigation solutions!<strong>
{% elif (radon >= 150) %}
{{ radon }} {{ unit }} is getting dangerous.<br>
<strong>Air out the place NOW!<strong>
{% elif (radon >= 100) %}
{{ radon }} {{ unit }} is excessive.<br>
<strong>Air out the place.<strong>
{% endif %}
# Warn someone by text to take action.
- condition: numeric_state
entity_id: counter.radon_notify
above: 0
- service: counter.decrement
entity_id: counter.radon_notify
- service: notify.text
data_template:
title: >-
{% set radon = states('sensor.radon_daily') | int %}
{% if (radon >= 200) %}
Radon levels are WAY too high
{% elif (radon >= 150) %}
Radon levels are too high
{% elif (radon >= 100) %}
Radon levels are getting too high
{% endif %}
message: |
{% set radon = states('sensor.radon_daily') | int %}
{% set unit = state_attr('sensor.radon_daily', 'unit_of_measurement') %}
{% if (radon >= 200) %}
{{ radon }} {{ unit }} is dangerous!
Air out the place NOW, and start looking into mitigation solutions!
{% elif (radon >= 150) %}
{{ radon }} {{ unit }} is getting dangerous.
Air out the place NOW!
{% elif (radon >= 100) %}
{{ radon }} {{ unit }} is excessive.
Air out the place.
{% endif %}
{% if states('counter.radon_notify')|int == 10 -%}
No further notifications will be sent about this issue until it gets resolved.
{% endif %}
# Play a warning sound and message.
- condition: state
entity_id: input_boolean.quiet_mode
state: 'off'
- service: notify.sound
data:
message: 'alarm'
data:
method: 'alarm'
- delay:
seconds: 2
- service: notify.speech
data_template:
message: >-
{% set radon = states('sensor.radon_daily') | int %}
{% if (radon >= 200) %}
Radon levels are WAY too high.
Radiation is currently at {{ radon }} becquerels per cubic meter, which is dangerous.
Air out the place NOW, and start looking into mitigation solutions!
{% elif (radon >= 150) %}
Radon levels are too high.
Radiation is currently at {{ radon }} becquerels per cubic meter, which is getting dangerous.
Air out the place NOW.
{% elif (radon >= 100) %}
Radon levels are getting too high
Radiation is currently at {{ radon }} becquerels per cubic meter, which is excessive.
Air out the place.
{% endif %}