-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsound-level.yaml
More file actions
119 lines (104 loc) · 2.47 KB
/
Copy pathsound-level.yaml
File metadata and controls
119 lines (104 loc) · 2.47 KB
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
substitutions:
name: sound-level
friendly_name: Sound Level
# Change this if the SEN0232 OUT pin is connected to another ADC-capable GPIO.
# Current wiring: SEN0232 OUT -> ESP32-C3 Super Mini GPIO3.
sound_adc_pin: GPIO3
# Leave this at 1.0 when "Sound Voltage" matches a multimeter reading.
adc_voltage_correction: "1.0"
esphome:
name: ${name}
friendly_name: ${friendly_name}
esp32:
board: esp32-c3-devkitm-1
variant: ESP32C3
framework:
type: esp-idf
logger:
api:
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: "${friendly_name}"
password: "soundlevel"
captive_portal:
web_server:
port: 80
version: 3
local: true
include_internal: false
button:
- platform: restart
name: Restart
globals:
- id: sound_calibration_offset_db
type: float
restore_value: no
initial_value: "-8.0"
number:
- platform: template
id: sound_calibration_offset
name: Calibration Offset
icon: mdi:tune
entity_category: config
unit_of_measurement: dB
min_value: -30
max_value: 30
step: 0.1
initial_value: -8.0
optimistic: true
restore_value: false
set_action:
- lambda: |-
id(sound_calibration_offset_db) = x;
if (!isnan(id(sound_voltage).state)) {
id(sound_level).publish_state(id(sound_voltage).state * 50.0f + x);
}
sensor:
- platform: adc
id: sound_voltage
name: Sound Voltage
pin: ${sound_adc_pin}
attenuation: auto
update_interval: 125ms
accuracy_decimals: 3
unit_of_measurement: V
device_class: voltage
state_class: measurement
entity_category: diagnostic
filters:
- multiply: ${adc_voltage_correction}
- median:
window_size: 5
send_every: 1
send_first_at: 1
- sliding_window_moving_average:
window_size: 8
send_every: 8
send_first_at: 8
- platform: template
name: Sound Level
id: sound_level
unit_of_measurement: dBA
icon: mdi:volume-high
state_class: measurement
accuracy_decimals: 1
update_interval: 1s
lambda: |-
if (isnan(id(sound_voltage).state)) {
return NAN;
}
return id(sound_voltage).state * 50.0f + id(sound_calibration_offset_db);
filters:
- clamp:
min_value: 30.0
max_value: 130.0
text_sensor:
- platform: wifi_info
ip_address:
name: IP Address
ssid:
name: Connected SSID