INFO ESPHome 2025.7.1
INFO Reading configuration /config/esphome/office-noise.yaml...
INFO Updating https://github.com/Reubertt/esphome-components@None
Failed config
external_components: [source /config/esphome/office-noise.yaml:9]
- source:
type: git
url: https://github.com/Reubertt/esphome-components
components:
Could not find __init__.py file for component volume-sensor. Please check the component is defined by this source (search path: /data/external_components/eea7c684/components/volume-sensor/__init__.py).
- volume-sensor
refresh: 0s
esphome:
name: volume-sensor
friendly_name: Volume-Sensor
esp8266:
board: nodemcuv2
external_components:
- source:
type: git
url: https://github.com/Reubertt/esphome-components
components: [volume_sensor]
#refresh: 1h
# Enable logging
#logger:
# Enable Home Assistant API
api:
encryption:
key: !secret apikey
ota:
- platform: esphome
password: !secret ota
# This automation is CRUCIAL for stability.
# It starts sampling slowly, then speeds up after Wi-Fi connects.
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "volume-sensor Fallback Hotspot"
password: !secret wifi_password
on_connect:
then:
- logger.log: "WiFi connected. Starting fast sampling."
- component.resume:
id: volume_sensor_main
# This sets the high-frequency sampling rate.
update_interval: 50ms
captive_portal:
sensor:
- platform: volume_sensor
id: volume_sensor_main
internal: true # The main component is just a controller.
pin: A0
# Start with a very long interval to allow Wi-Fi to connect reliably.
# The 'on_connect' automation above will override this.
update_interval: 100s
# Publish the peak value found every 5 seconds.
publish_interval: 5s
# Each sample burst lasts 30ms. The next burst starts immediately.
sampling_duration: 30ms
# --- Measurement Configuration ---
sensitivity: 50
# Use calibration to narrow the focus to your sensor's actual operating range,
# determined after completing the hardware calibration in Step 1.
adc_min_calibration: 200
adc_max_calibration: 900
# --- Child Sensors ---
db_sensor:
name: "Volume DB"
raw_max_sensor:
name: "Raw ADC Max"
raw_min_sensor:
name: "Raw ADC Min"
percentage_sensor:
name: "Volume Percent"
number:
- platform: template
name: "Sound Sensitivity"
optimistic: true
initial_value: 50
min_value: 0.0
max_value: 100.0
step: 0.5
set_action:
- lambda: id(volume_sensor_main).set_sensitivity(x);
As adchavira pointed out, I ended up misspelling a character when I was trying to post it here. I’ve already corrected the example on GitHub, but for those who are just going to browse the post and not read anything, I’m creating this answer to simplify the process for them. Thanks again to adchavira for noticing my mistake that went unnoticed.
Thanks for the update. Just got into HA and found everything here extremely helpful. I got the below when trying it out.
INFO ESPHome 2025.6.3
INFO Reading configuration /config/mic-s3.yaml...
INFO Generating C++ source...
INFO Updating https://github.com/espressif/[email protected]
INFO Compiling app...
--------------------------------------------------------------------------------
src/esphome/components/volume_sensor/volume_sensor.cpp: In member function 'virtual void esphome::volume_sensor::VolumeSensor::update()':
src/esphome/components/volume_sensor/volume_sensor.cpp:39:30: error: 'millis' was not declared in this scope
39 | unsigned long start_time = millis();
| ^~~~~~
src/esphome/components/volume_sensor/volume_sensor.cpp:41:23: error: 'analogRead' was not declared in this scope
41 | uint16_t sample = analogRead(this->pin_);
| ^~~~~~~~~~
*** [.pioenvs/mic-s3/src/esphome/components/volume_sensor/volume_sensor.cpp.o] Error 1
========================== [FAILED] Took 6.06 seconds ==========================
Even though I have the inmp441 here at home, I’m a little short on time to try and see how well it would work with an 8266. And when I went to check the new ESPHome implementations (when I developed this code they didn’t have this others components) of volume meter and microphone integrations, all components were limited to use in I2S and ESP32. It would probably be possible to use an ESP8266, but for that I would have to create a specific component for it to be able to handle I2S and 8266. Not to mention that it might not even work, as it really consumes a lot of processing power. I think the ideal is to go for a more powerful MCU like ESP32/C3/C6…
Hello. I got this working using esp8266 D1 mini and now I am creating another using esp32-C3. I’ve used the same codes from my esp8266 and am getting this error while compiling.
Seems to be the same error as @ rasta0981 posted a few posts above this.
src/esphome/components/volume_sensor/volume_sensor.cpp: In member function 'virtual void esphome::volume_sensor::VolumeSensor::update()':
src/esphome/components/volume_sensor/volume_sensor.cpp:39:30: error: 'millis' was not declared in this scope
39 | unsigned long start_time = millis();
| ^~~~~~
src/esphome/components/volume_sensor/volume_sensor.cpp:41:23: error: 'analogRead' was not declared in this scope
41 | uint16_t sample = analogRead(this->pin_);
| ^~~~~~~~~~
*** [.pioenvs/master-airfreshener/src/esphome/components/volume_sensor/volume_sensor.cpp.o] Error 1
========================== [FAILED] Took 6.45 seconds ==========================
I don’t have any C3 esp to test, but from what I’ve seen I believe it’s a problem with the libraries being used to compile the code. Theoretically, it was supposed to import the standard library “Arduino.h” where these functions would already be implemented. This happens due to the architecture change that ESP made in its MCUs. I’m moving house, so it might take a while, but I’ll try to implement a failsafe for other boards. Okay?
Hi, i´m also playing around and your component is super helpful and work perfect on 8266.
When trying to run this on ESP32 C3 you have to specify framework as arduino like so the needed libraries are there.
Next issue is, that esp32 is using a 12bit adc vs 10bit on 8266 so measurement is completely off but this can be configured on ESP32 so I just created a PR and tested on my ESP32-C3 Supermini.
Interestingly enough is that ESP8266 ADC seems to be more precise so less fluctuation but for my usecase it is ok.