-
Notifications
You must be signed in to change notification settings - Fork 0
/
fridge_sensors.yaml
201 lines (172 loc) · 8.53 KB
/
fridge_sensors.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
# -----------------------------------------------------------------------------
# ESPHome config file for a temperature sensor (and alarm) for the fridge
#
# CAH 2021-04-21
#
# +----------------------------------------+
# | Description and basic information |
# +----------------------------------------+
#
# This is a NodeMCU board with a couple Dallas DS18B20 temperature sensors,
# one for the fridge's internal temperature and the other for the room temp.
# There is also a passive buzzer to serve as an alarm sound.
#
# DS18B20 GPIO-13 / D7
# Buzzer GPIO-04 / D2
# Status GPIO-14 / D5
#
#
# +----------------------------------------+
# | Playing arbitraty songs with RTTTL |
# +----------------------------------------+
#
# A simple automation is defined to sound the alarm in the device should the
# internal temperature become too high. Other automations (like messaging)
# are handled in Home Asistant
#
# There's an exposed API endpoint for playing an arbitrary song on the buzzer.
# To invoke it, open HA's developer tools, and call:
# esphome.fridge_sensors_rtttl_play
#
# and in the service data field enter the song, for example:
# song_str: "mario:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6"
#
#
# +----------------------------------------+
# | Conecting sensors and the buzzer |
# +----------------------------------------+
#
# The two Dallas temperature sensors are wired to +3.3 and ground, and their data
# pins are wired together (in paralel) to D7, without any pullup resistor.
#
# The buzzer uses a BC-548 NPN transistor as a driver, with a 220 ohm
# resistor from D2 to the base of the transistor; its emitter is connected to
# ground and its collector goes to the negative lead of the buzzer, with the
# positive lead to 3.3v. A flyback diode is wired in paralel with the buzzer
# to arrest any reverse voltage spikes.
#
#
# +----------------------------------------+
# | Relevant information |
# +----------------------------------------+
#
# - https://diyi0t.com/active-passive-buzzer-arduino-esp8266-esp32/
# - https://esphome.io/components/rtttl.html
# - https://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language
#
#
# -----------------------------------------------------------------------------
substitutions:
node_hostname: fridge_sensors
node_name: "Fridge"
packages:
device_base: !include common/device_base.yaml
plaform: !include common/nodemcu.yaml
# custom status LED on pin D5
status_led:
pin:
number: D5
inverted: False
# -----------------------------------------------------------------------------
# API settings
# -----------------------------------------------------------------------------
api:
services:
# endpoint to allow playing an arbitraty song via API call
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda 'return song_str;'
# goofing out: some pre-defined tunes to invoke from HA:
- service: play_rtttl_simpsons
then:
- rtttl.play: 'The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6'
- service: play_rtttl_mario
then:
- rtttl.play: 'mario:d=4,o=5,b=100:16e6,16e6,32p,8e6,16c6,8e6,8g6,8p,8g,8p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,16p,8c6,16p,8g,16p,8e,16p,8a,8b,16a#,8a,16g.,16e6,16g6,8a6,16f6,8g6,8e6,16c6,16d6,8b,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16c7,16p,16c7,16c7,p,16g6,16f#6,16f6,16d#6,16p,16e6,16p,16g#,16a,16c6,16p,16a,16c6,16d6,8p,16d#6,8p,16d6,8p,16c6'
- service: play_rtttl_indiana
then:
- rtttl.play: 'Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6'
- service: play_rtttl_take_on
then:
- rtttl.play: 'TakeOnMe:d=4,o=4,b=160:8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5,8f#5,8e5,8f#5,8f#5,8f#5,8d5,8p,8b,8p,8e5,8p,8e5,8p,8e5,8g#5,8g#5,8a5,8b5,8a5,8a5,8a5,8e5,8p,8d5,8p,8f#5,8p,8f#5,8p,8f#5,8e5,8e5'
- service: play_rtttl_bond
then:
- rtttl.play: 'Bond:d=4,o=5,b=80:32p,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d#6,16d#6,16c#6,32d#6,32d#6,16d#6,8d#6,16c#6,16c#6,16c#6,16c#6,32e6,32e6,16e6,8e6,16d#6,16d6,16c#6,16c#7,c.7,16g#6,16f#6,g#.6'
- service: play_rtttl_star_wars
then:
- rtttl.play: 'StarWars:d=4,o=5,b=45:32p,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#.6,32f#,32f#,32f#,8b.,8f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32c#6,8b.6,16f#.6,32e6,32d#6,32e6,8c#6'
- service: play_rtttl_top_gun
then:
- rtttl.play: 'TopGun:d=4,o=4,b=31:32p,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,16f,d#,16c#,16g#,16g#,32f#,32f,32f#,32f,16d#,16d#,32c#,32d#,16f,32d#,32f,16f#,32f,32c#,g#'
- service: play_rtttl_smurfs
then:
- rtttl.play: 'Smurfs:d=32,o=5,b=200:4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8f#,p,8a#,p,4g#,4p,g#,p,a#,p,b,p,c6,p,4c#6,16p,4f#6,p,16c#6,p,8d#6,p,8b,p,4g#,16p,4c#6,p,16a#,p,8b,p,8f,p,4f#'
- service: play_rtttl_mission_impossible
then:
- rtttl.play: 'MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d'
# -----------------------------------------------------------------------------
# I/O
# -----------------------------------------------------------------------------
# Dallas DS18B20 temperature sensor
dallas:
- pin: D7
# SW PWM output for the buzzer RTTTL library
output:
- platform: esp8266_pwm
frequency: 1000 Hz
pin: D2
id: rtttl_out
# RTTTL buzzer configuration
rtttl:
output: rtttl_out
# -----------------------------------------------------------------------------
# Scripts
# -----------------------------------------------------------------------------
script:
# script to play an alarm sound in a loop while the temperature is above the max value
- id: sound_main_alarm
mode: single
then:
- while:
condition:
lambda: |-
return id(fridge_main_temperature).state > 10.0;
then:
#- rtttl.play: 'MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d'
- delay: 30s
# script to play an alarm sound in a loop while the temperature is above the max value
- id: sound_freezer_alarm
mode: single
then:
- while:
condition:
lambda: |-
return id(fridge_freezer_temperature).state > -10.0;
then:
#- rtttl.play: 'MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d'
- delay: 30s
# -----------------------------------------------------------------------------
# Sensors
# -----------------------------------------------------------------------------
sensor:
# main compartment (sensor A - 0xE20316B1564CFF28)
- platform: dallas
id: fridge_main_temperature
address: 0xE20316B1564CFF28
name: "${node_name} Main Temperature"
on_value_range:
- above: 10.0
then:
- script.execute: sound_main_alarm
# freezer compartment temperature (sensor B - 0x6B0316B1854CFF28)
- platform: dallas
id: fridge_freezer_temperature
address: 0x6B0316B1854CFF28
name: "${node_name} Freezer Temperature"
on_value_range:
- above: -10.0
then:
- script.execute: sound_freezer_alarm