ESPhome Decibel Meter - HW-484/KY-037/KY-038

I just copied both (or rather, all three) bits of code together:

(... the usual stuff ...)
captive_portal:

globals:

  - id: esphome_sensitivity
    type: float
    initial_value: '36.5'
    restore_value: yes

  - id: esphome_volume
    type: int

sensor:
  - platform: adc
    pin: GPIO32
    id: esphome_db
    device_class: signal_strength
    name: "Db SoundEsp"
    icon: "mdi:volume-vibrate"
    unit_of_measurement: "db"
    update_interval: 5s
    raw: true
    filters:
      - lambda: |-
          unsigned int sample;
          unsigned long startMillis= millis(); 
          float peakToPeak = 0; 
          unsigned int signalMax = 0;
          unsigned int signalMin = 4096;
          while (millis() - startMillis < 500) {
            sample = analogRead(A0);
            if (sample < 4096){
                if (sample > signalMax){
                    signalMax = sample;
                }
                else if (sample < signalMin){
                    signalMin = sample;
                }
              }
          }
          peakToPeak = map((signalMax - signalMin),1,4096,1.5,4096);
          id(esphome_volume) = peakToPeak;
          float state = id(esphome_sensitivity)*log10(peakToPeak)+15;  
          return(state);

  - platform: template
    name: "Volume SoundEsp"
    icon: "mdi:volume-high"
    unit_of_measurement: "%"
    update_interval: 5s
    lambda: return(map((id(esphome_db).state),15,150,0,100));

  - platform: template
    name: "RAW SoundEsp"
    icon: "mdi:volume-source"
    unit_of_measurement: "%"
    update_interval: 5s
    lambda: return(map(id(esphome_volume),1,4096,0,100));

  - platform: copy
    source_id: esphome_db
    name: "Db SoundEsp Average"
    filters:
      - sliding_window_moving_average:
          window_size: 15
          send_every: 5

number:
  - platform: template
    id: sensitivity_slider
    name: "Sensitivity SoundEsp"
    icon: "mdi:knob"
    update_interval: 5s
    initial_value: "36.5"
    step: 0.1
    min_value: 20
    max_value: 40
    mode: slider
    set_action:
      then:
        - lambda:  id(esphome_sensitivity) = x;

binary_sensor:
  - platform: analog_threshold
    name: ATS alarm triggered
    sensor_id: volume_soundesp
    threshold:
      upper: 110.0
      lower: 80.0
    device_class: smoke

This returned the following errors:

PS C:\PortbleApps\ESPHome> esphome run esp32-tuinhuis.yaml
INFO ESPHome 2024.7.2
INFO Reading configuration esp32-tuinhuis.yaml...
Failed config

binary_sensor.analog_threshold: [source esp32-tuinhuis.yaml:173]
  platform: analog_threshold
  name: ATS alarm triggered

  Couldn't find ID 'volume_soundesp'. Please check you have defined an ID with that name in your configuration.
  sensor_id: volume_soundesp
  threshold:
    upper: 110.0
    lower: 80.0
  device_class: smoke
  disabled_by_default: False

Should that be esphome_db from the first post?

…? :slight_smile: