Esp32-c3 board with deep sleep, won't sleep and erroneous readings

Hello everyone, it’s my first post here
As the title says, i have this little board setup to work as a small weather station, nothing supuer complicated, only a bmp280, a rain sensor i recovered from an old Lidl weather station and a guva-s125d for uv index readings.
I setup HA a little more than 2 months ago and at first the sensor was working fine going in deep sleep reporting only dots in the graph(as expected) but it’s quite a month or more that the board doesn’t sleep or at least i think, because i can see in the graph that the readings are constant and more strange the uv index readings are randoms. I’m not an expert becauseit’s only a small time i’m into this so every help can be useful.

substitutions:
  name: "meteo"
  friendly_name: meteo

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  platformio_options:
    board_build.flash_mode: dio
  min_version: 2024.6.0
  name_add_mac_suffix: false
  project:
    name: esphome.web
    version: dev

esp32:
  variant: ESP32C3
  board: esp32-c3-devkitm-1
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: !secret api

# Allow Over-The-Air updates
ota:
  platform: esphome  # Specifies the OTA platform

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password

  output_power: 8.5  # Sets power to 10 dBm
  fast_connect: on
  manual_ip:
    static_ip: 192.168.1.202
    subnet: 255.255.255.0
    gateway: 192.168.1.1
  # power_save_mode: HIGH

  ap:
    ssid: "meteo"
    password: ""
    # cannot be 0, if no wifi a reset will occur after this timeout
    ap_timeout: 60min
# Include time component
time:
  - platform: homeassistant
    id: homeassistant_time

i2c:
  sda: GPIO8
  scl: GPIO9
  scan: true
  id: bus_a

sensor:
  - platform: bmp280_i2c
    temperature:
      name: "Outside Temperature"
      oversampling: 16x
    pressure:
      name: "Outside Pressure"
    address: 0x76
    update_interval: 60s

  - platform: pulse_counter
    pin:
      number: GPIO2
      mode: INPUT_PULLUP
    unit_of_measurement: 'mm/min'
    name: 'Rain Rate per minute'
    filters:
      - multiply: 0.3  # Each pulse corresponds to 0.3 mm of rain
    total:
      unit_of_measurement: 'mm'
      name: 'Total Rain'
      id: total_rain
      filters:
        - multiply: 0.3  # Conversion for total accumulated rain in mm
    accuracy_decimals: 2
    update_interval: 60s

  - platform: adc
    pin: GPIO01  # Use your desired input pin here
    name: "ADC voltage"
    update_interval: 60s
    id: "uv_index_source"
    accuracy_decimals: 3
    internal: true

  - platform: adc
    pin: GPIO3  # Sostituisci con il pin corretto
    name: "Tensione Ingresso"
    update_interval: 60s
    attenuation: 12db  # Usa 12dB per una lettura fino a 3.3V o più
    filters:
      - multiply: 1.72  # Moltiplica il valore letto per 2.45 per ottenere la tensione di ingresso corretta
      - lambda: |-
          float tensione = x;  // Tensione letta (già in volt)
          ESP_LOGI("info", "Tensione letta: %.2f V", tensione);

          // Riconoscimento della fonte di alimentazione in base alla tensione letta
          if (tensione > 4.5) {
            ESP_LOGI("info", "Collegato a 5V");
          } else if (tensione > 3.5) {
            ESP_LOGI("info", "Collegata una batteria carica");
          } else if (tensione > 3.0) {
            ESP_LOGI("info", "Batteria scarica");
          } else {
            ESP_LOGW("warning", "Tensione molto bassa! Controlla l'alimentazione");
          }

          return tensione;  // Restituisce la tensione






  - platform: template
    name: "UV index"
    accuracy_decimals: 0
    unit_of_measurement: ""
    icon: "mdi:sun-wireless"
    lambda: |-
      if (id(uv_index_source).state < 0.05)
        return 0;
      if (id(uv_index_source).state <= 0.227)
        return 1;
      if (id(uv_index_source).state <= 0.32)
        return 2;
      if (id(uv_index_source).state <= 0.4)
        return 3;
      if (id(uv_index_source).state <= 0.5)
        return 4;
      if (id(uv_index_source).state <= 0.6)
        return 5;
      if (id(uv_index_source).state <= 0.69)
        return 6;
      if (id(uv_index_source).state <= 0.8)
        return 7;
      if (id(uv_index_source).state <= 0.88)
        return 8;
      if (id(uv_index_source).state <= 0.97)
        return 9;
      if (id(uv_index_source).state <= 1.08)
        return 10;
      return 11;

  - platform: wifi_signal  # Reports the WiFi signal strength/RSSI in dB
    name: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"

  - platform: copy  # Reports the WiFi signal strength in %
    source_id: wifi_signal_db
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
    device_class: ""

# Configuration for Deep Sleep (commented out)
deep_sleep:
 run_duration: 20s         # Time active for data collection
 sleep_duration: 10min     # Deep sleep duration before next cycle

# Daily reset at 00:00
interval:
  - interval: 1min
    then:
      - lambda: |-
          auto now = id(homeassistant_time).now();
          if (now.hour == 0 && now.minute == 0) {
            id(total_rain).publish_state(0);  // Reset total value at midnight
          }

HI
Check your logs in esphome. It might give a clue to what’s happening.

logs

in esphome the sensor appears offline and the log is here:

INFO ESPHome 2024.12.2
INFO Reading configuration /config/esphome/meteo.yaml...
INFO Detected timezone 'Europe/Rome'
WARNING GPIO8 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO9 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO2 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
INFO Starting log output from 192.168.1.202 using esphome API
WARNING Can't connect to ESPHome API for meteo @ 192.168.1.202: Error connecting to [AddrInfo(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=6, sockaddr=IPv4Sockaddr(address='192.168.1.202', port=6053))]: [Errno 113] Connect call failed ('192.168.1.202', 6053) (SocketAPIError)
INFO Trying to connect to meteo @ 192.168.1.202 in the background

if i reset manually the board this is the log:

INFO Starting log output from 192.168.1.202 using esphome API
INFO Successfully connected to meteo @ 192.168.1.202 in 0.144s
INFO Successful handshake with meteo @ 192.168.1.202 in 0.079s
[15:35:07][I][app:100]: ESPHome version 2024.12.2 compiled on Jan  4 2025, 12:55:23
[15:35:07][I][app:102]: Project esphome.web version dev
[15:35:07][C][wifi:600]: WiFi:
[15:35:07][C][wifi:428]:   Local MAC: 3C:84:27:AD:2E:B4
[15:35:07][C][wifi:433]:   SSID: [redacted]
[15:35:07][C][wifi:436]:   IP Address: 192.168.1.202
[15:35:07][C][wifi:440]:   BSSID: [redacted]
[15:35:07][C][wifi:441]:   Hostname: 'meteo'
[15:35:07][C][wifi:443]:   Signal strength: -56 dB ▂▄▆█
[15:35:07][C][wifi:447]:   Channel: 12
[15:35:07][C][wifi:448]:   Subnet: 255.255.255.0
[15:35:07][C][wifi:449]:   Gateway: 192.168.1.1
[15:35:07][C][wifi:450]:   DNS1: 0.0.0.0
[15:35:07][C][wifi:451]:   DNS2: 0.0.0.0
[15:35:07][C][logger:185]: Logger:
[15:35:07][C][logger:186]:   Level: DEBUG
[15:35:07][C][logger:188]:   Log Baud Rate: 115200
[15:35:07][C][logger:189]:   Hardware UART: USB_CDC
[15:35:07][C][i2c.arduino:071]: I2C Bus:
[15:35:07][C][i2c.arduino:072]:   SDA Pin: GPIO8
[15:35:07][C][i2c.arduino:073]:   SCL Pin: GPIO9
[15:35:07][C][i2c.arduino:074]:   Frequency: 50000 Hz
[15:35:07][C][i2c.arduino:086]:   Recovery: bus successfully recovered
[15:35:07][I][i2c.arduino:096]: Results from i2c bus scan:
[15:35:07][I][i2c.arduino:102]: Found i2c device at address 0x76
[15:35:07][C][template.sensor:022]: Template Sensor 'UV index'
[15:35:07][C][template.sensor:022]:   State Class: ''
[15:35:07][C][template.sensor:022]:   Unit of Measurement: ''
[15:35:07][C][template.sensor:022]:   Accuracy Decimals: 0
[15:35:07][C][template.sensor:022]:   Icon: 'mdi:sun-wireless'
[15:35:07][C][template.sensor:023]:   Update Interval: 60.0s
[15:35:07][C][homeassistant.time:010]: Home Assistant Time:
[15:35:07][C][homeassistant.time:011]:   Timezone: 'CET-1CEST,M3.5.0,M10.5.0/3'
[15:35:07][C][bmp280_i2c.sensor:022]:   Address: 0x76
[15:35:07][C][bmp280.sensor:132]: BMP280:
[15:35:07][C][bmp280.sensor:144]:   IIR Filter: OFF
[15:35:07][C][bmp280.sensor:145]:   Update Interval: 60.0s
[15:35:07][C][bmp280.sensor:147]:   Temperature 'Outside Temperature'
[15:35:07][C][bmp280.sensor:147]:     Device Class: 'temperature'
[15:35:07][C][bmp280.sensor:147]:     State Class: 'measurement'
[15:35:07][C][bmp280.sensor:147]:     Unit of Measurement: '°C'
[15:35:07][C][bmp280.sensor:147]:     Accuracy Decimals: 1
[15:35:07][C][bmp280.sensor:148]:     Oversampling: 16x
[15:35:07][C][bmp280.sensor:149]:   Pressure 'Outside Pressure'
[15:35:07][C][bmp280.sensor:149]:     Device Class: 'pressure'
[15:35:07][C][bmp280.sensor:149]:     State Class: 'measurement'
[15:35:07][C][bmp280.sensor:149]:     Unit of Measurement: 'hPa'
[15:35:07][C][bmp280.sensor:149]:     Accuracy Decimals: 1
[15:35:07][C][bmp280.sensor:150]:     Oversampling: 16x
[15:35:07][C][pulse_counter:167]: Pulse Counter 'Rain Rate per minute'
[15:35:07][C][pulse_counter:167]:   State Class: 'measurement'
[15:35:07][C][pulse_counter:167]:   Unit of Measurement: 'mm/min'
[15:35:07][C][pulse_counter:167]:   Accuracy Decimals: 2
[15:35:07][C][pulse_counter:167]:   Icon: 'mdi:pulse'
[15:35:07][C][pulse_counter:168]:   Pin: GPIO2
[15:35:07][C][pulse_counter:169]:   Rising Edge: INCREMENT
[15:35:07][C][pulse_counter:170]:   Falling Edge: DISABLE
[15:35:07][C][pulse_counter:171]:   Filtering pulses shorter than 13 µs
[15:35:07][C][pulse_counter:172]:   Update Interval: 60.0s
[15:35:07][C][adc.esp32:058]: ADC Sensor 'ADC voltage'
[15:35:07][C][adc.esp32:058]:   Device Class: 'voltage'
[15:35:07][C][adc.esp32:058]:   State Class: 'measurement'
[15:35:07][C][adc.esp32:058]:   Unit of Measurement: 'V'
[15:35:07][C][adc.esp32:058]:   Accuracy Decimals: 3
[15:35:07][C][adc.esp32:059]:   Pin: GPIO1
[15:35:07][C][adc.esp32:065]:   Attenuation: 0db
[15:35:07][C][adc.esp32:080]:   Samples: 1
[15:35:07][C][adc.esp32:081]:   Update Interval: 60.0s
[15:35:07][C][adc.esp32:058]: ADC Sensor 'Tensione Ingresso'
[15:35:07][C][adc.esp32:058]:   Device Class: 'voltage'
[15:35:07][C][adc.esp32:058]:   State Class: 'measurement'
[15:35:07][C][adc.esp32:058]:   Unit of Measurement: 'V'
[15:35:07][C][adc.esp32:058]:   Accuracy Decimals: 2
[15:35:07][C][adc.esp32:059]:   Pin: GPIO3
[15:35:07][C][adc.esp32:074]:   Attenuation: 12db
[15:35:07][C][adc.esp32:080]:   Samples: 1
[15:35:07][C][adc.esp32:081]:   Update Interval: 60.0s
[15:35:07][C][copy.sensor:015]: Copy Sensor 'WiFi Signal Percent'
[15:35:07][C][copy.sensor:015]:   State Class: 'measurement'
[15:35:07][C][copy.sensor:015]:   Unit of Measurement: 'Signal %'
[15:35:07][C][copy.sensor:015]:   Accuracy Decimals: 0
[15:35:07][C][mdns:116]: mDNS:
[15:35:07][C][mdns:117]:   Hostname: meteo
[15:35:07][C][esphome.ota:073]: Over-The-Air updates:
[15:35:07][C][esphome.ota:074]:   Address: 192.168.1.202:3232
[15:35:08][C][esphome.ota:075]:   Version: 2
[15:35:08][C][safe_mode:018]: Safe Mode:
[15:35:08][C][safe_mode:020]:   Boot considered successful after 60 seconds
[15:35:08][C][safe_mode:021]:   Invoke after 10 boot attempts
[15:35:08][C][safe_mode:023]:   Remain in safe mode for 300 seconds
[15:35:08][C][api:140]: API Server:
[15:35:08][C][api:141]:   Address: 192.168.1.202:6053
[15:35:08][C][api:143]:   Using noise encryption: YES
[15:35:08][C][improv_serial:032]: Improv Serial:
[15:35:08][C][wifi_signal.sensor:010]: WiFi Signal 'WiFi Signal dB'
[15:35:08][C][wifi_signal.sensor:010]:   Device Class: 'signal_strength'
[15:35:08][C][wifi_signal.sensor:010]:   State Class: 'measurement'
[15:35:08][C][wifi_signal.sensor:010]:   Unit of Measurement: 'dBm'
[15:35:08][C][wifi_signal.sensor:010]:   Accuracy Decimals: 0
[15:35:08][C][deep_sleep:026]: Setting up Deep Sleep...
[15:35:08][C][deep_sleep:029]:   Sleep Duration: 600000 ms
[15:35:08][C][deep_sleep:032]:   Run Duration: 20000 ms
[15:35:22][I][deep_sleep:060]: Beginning Deep Sleep
[15:35:22][I][deep_sleep:062]: Sleeping for 600000000us
[15:35:22][D][esp32.preferences:114]: Saving 1 preferences to flash...
[15:35:22][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
INFO Processing expected disconnect from ESPHome API for meteo @ 192.168.1.202
WARNING Disconnected from API

but if i check for example the temperature graph i can see new values every 5 minutes

perhaps keep the logs running ,wait the 5 minutes after it goes into deep sleep to see it waking up.

You should also try using another pin other than GPIO8. Strapping pins often cause problems if used.

it’s a long time running with this setup, gpio8 is used for the i2c