Skip to content

Add support for APDS-9930 sensor#13125

Open
iyesin wants to merge 11 commits intoesphome:devfrom
iyesin:discussions/3459_add_support_for_apds9930
Open

Add support for APDS-9930 sensor#13125
iyesin wants to merge 11 commits intoesphome:devfrom
iyesin:discussions/3459_add_support_for_apds9930

Conversation

@iyesin
Copy link

@iyesin iyesin commented Jan 10, 2026

Add support for APDS-9930 sensor (ambient light + proximity)

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Developer breaking change (an API change that could break external components)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

Pull request in esphome-docs with documentation (if applicable):

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx
  • nRF52840

Example entry for config.yaml:

external_components:
  - source: github://pr#13125
    components: [apds9930]
    refresh: 1h

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true

apds9930:
  id: light_proximity_sensor
  address: 0x39
  update_interval: 60s
  led_drive: 100ma
  proximity_gain: 8x
  ambient_light_gain: 1x
  proximity_diode: 2

sensor:
  - platform: apds9930
    apds9930_id: light_proximity_sensor
    type: illuminance
    illuminance:
      name: "Living Room Illuminance"
      id: living_room_lux
      filters:
        - sliding_window_moving_average:
            window_size: 5
            send_every: 5
      on_value_range:
        - below: 50
          then:
            - light.turn_on: main_light
        - above: 200
          then:
            - light.turn_off: main_light

  - platform: apds9930
    apds9930_id: light_proximity_sensor
    type: proximity
    proximity:
      name: "Object Proximity"
      id: object_proximity
      filters:
        - throttle: 1s
      on_value_range:
        - above: 500
          then:
            - logger.log: "Object detected nearby"
            - switch.turn_on: proximity_alert
        - below: 100
          then:
            - switch.turn_off: proximity_alert

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@github-actions
Copy link
Contributor

To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file:

external_components:
  - source: github://pr#13125
    components: [apds9930]
    refresh: 1h

(Added by the PR bot)

esphome[bot]
esphome bot previously requested changes Jan 10, 2026
Copy link

@esphome esphome bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👥 Code Ownership

Hey there @iyesin,
Thanks for submitting this pull request! Can you add yourself as a codeowner for this integration? This way we can notify you if a bug report for this integration is reported.

In __init__.py of the integration, please add:

CODEOWNERS = ["@iyesin"]

And run script/build_codeowners.py

@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.96%. Comparing base (a43e3e5) to head (49c1cd0).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #13125   +/-   ##
=======================================
  Coverage   73.96%   73.96%           
=======================================
  Files          55       55           
  Lines       11575    11575           
  Branches     1577     1577           
=======================================
  Hits         8562     8562           
  Misses       2611     2611           
  Partials      402      402           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@esphome esphome bot dismissed their stale review January 10, 2026 19:58

Review dismissed: All requirements have been met

@github-actions
Copy link
Contributor

github-actions bot commented Jan 10, 2026

Memory Impact Analysis

Components: apds9930
Platform: esp8266-ard

Metric Target Branch This PR Change
RAM 28,192 bytes 28,832 bytes 📈 🚨 +640 bytes (+2.27%)
Flash 276,191 bytes 287,575 bytes 📈 🚨 +11,384 bytes (+4.12%)
📊 Component Memory Breakdown
Component Target Flash PR Flash Change
other 7,516 bytes 9,984 bytes 📈 +2,468 bytes (+32.84%)
[esphome]i2c 0 bytes 2,363 bytes 📈 🔸 +2,363 bytes (0.00%)
[esphome]apds9930 0 bytes 1,654 bytes 📈 🔸 +1,654 bytes (0.00%)
[esphome]core 7,330 bytes 8,757 bytes 📈 🚨 +1,427 bytes (+19.47%)
[esphome]sensor 0 bytes 1,069 bytes 📈 🔸 +1,069 bytes (0.00%)
app_framework 1,585 bytes 1,923 bytes 📈 +338 bytes (+21.32%)
misc_system 3,911 bytes 4,216 bytes 📈 +305 bytes (+7.80%)
wifi_config 2,489 bytes 2,759 bytes 📈 +270 bytes (+10.85%)
interrupt_handlers 899 bytes 1,099 bytes 📈 +200 bytes (+22.25%)
static_init 52 bytes 181 bytes 📈 +129 bytes (+248.08%)
power_mgmt 7,013 bytes 7,140 bytes 📈 +127 bytes (+1.81%)
wifi_stack 40,435 bytes 40,308 bytes 📉 -127 bytes (-0.31%)
arduino_core 2,336 bytes 2,400 bytes 📈 +64 bytes (+2.74%)
esp_system 5,657 bytes 5,605 bytes 📉 -52 bytes (-0.92%)
wifi_phy_pp 2,896 bytes 2,948 bytes 📈 +52 bytes (+1.80%)
exception_handling 2,488 bytes 2,531 bytes 📈 +43 bytes (+1.73%)
memory_alloc 901 bytes 927 bytes 📈 +26 bytes (+2.89%)
rom_functions 5,471 bytes 5,484 bytes 📈 +13 bytes (+0.24%)
error_handling 120 bytes 128 bytes 📈 +8 bytes (+6.67%)
freertos 35 bytes 41 bytes 📈 +6 bytes (+17.14%)
🔍 Symbol-Level Changes (click to expand)

Changed Symbols

Symbol Target Size PR Size Change
setup 210 bytes 548 bytes 📈 +338 bytes (+160.95%)
esphome::App 152 bytes 180 bytes 📈 +28 bytes (+18.42%)
[global constructor for: esphome::Application::register_component_(esphome::Component*)] 128 bytes 146 bytes 📈 +18 bytes (+14.06%)
esphome::esp8266::ESP8266Preferences::sync()::__pstr__ 15 bytes 7 bytes 📉 -8 bytes (-53.33%)
setup::__pstr__ 12 bytes 9 bytes 📉 -3 bytes (-25.00%)

New Symbols (top 15)

Symbol Size
_vfprintf_r 899 bytes
_svfprintf_r 798 bytes
Twi::onTwipEvent(unsigned char) 464 bytes
esphome::i2c::ArduinoI2CBus::write_readv(unsigned char, unsigned char const*, unsigned int, unsig...esphome::i2c::ArduinoI2CBus::write_readv(unsigned char, unsigned char const*, unsigned int, unsigned char*, unsigned int)
389 bytes
esphome::i2c::ArduinoI2CBus::recover_() 363 bytes
esphome::apds9930::APDS9930::setup() 341 bytes
esphome::apds9930::APDS9930::dump_config() 221 bytes
esphome::i2c::ArduinoI2CBus::dump_config() 221 bytes
esphome::apds9930::APDS9930::calculate_lux_(unsigned short, unsigned short) 219 bytes
std::pair<unsigned char, bool>& std::vector<std::pair<unsigned char, bool>, std::allocator<std::p...std::pair<unsigned char, bool>& std::vector<std::pair<unsigned char, bool>, std::allocator<std::pair<unsigned char, bool> > >::emplace_back<unsigned char&, bool>(unsigned char&, bool&&) [$isra$0]
200 bytes
Twi::readFrom(unsigned char, unsigned char*, unsigned int, unsigned char) 193 bytes
esphome::sensor::log_sensor(char const*, char const*, char const*, esphome::sensor::Sensor*) 187 bytes
esphome::format_hex_internal(char*, unsigned int, unsigned char const*, unsigned int, char, char)...esphome::format_hex_internal(char*, unsigned int, unsigned char const*, unsigned int, char, char) [$part$0]
174 bytes
twi 172 bytes
Twi::writeTo(unsigned char, unsigned char*, unsigned int, unsigned char) 171 bytes
161 more new symbols... Total: 11,815 bytes

Removed Symbols (top 15)

Symbol Size
_vfiprintf_r 899 bytes
_svfiprintf_r 798 bytes
wifi_fpm_open 127 bytes
_vsnprintf_r 112 bytes
esp_delay 91 bytes
__yield 69 bytes
vprintf 63 bytes
__esp_suspend 58 bytes
system_soft_wdt_restart 52 bytes
delay 46 bytes
__preloop_update_frequency 38 bytes
vsnprintf 32 bytes
vfiprintf 26 bytes
z2EapFree 6 bytes
_lock_try_acquire_recursive 4 bytes
2 more removed symbols... Total: 2,425 bytes

Note: This analysis measures static RAM and Flash usage only (compile-time allocation).
Dynamic memory (heap) cannot be measured automatically.
⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

@iyesin

This comment was marked as outdated.

@iyesin iyesin force-pushed the discussions/3459_add_support_for_apds9930 branch from e9b6d53 to 131a50a Compare January 11, 2026 18:59
@iyesin iyesin force-pushed the discussions/3459_add_support_for_apds9930 branch from 131a50a to 942977c Compare February 2, 2026 20:37
@iyesin iyesin force-pushed the discussions/3459_add_support_for_apds9930 branch from e3d1117 to c3b15aa Compare February 3, 2026 21:54
@iyesin iyesin force-pushed the discussions/3459_add_support_for_apds9930 branch from c3b15aa to 0edc6a3 Compare February 3, 2026 21:57
@iyesin iyesin marked this pull request as ready for review February 4, 2026 01:47
@iyesin
Copy link
Author

iyesin commented Feb 4, 2026

I tested this code on the real hardware. The only problem I found is with the proximity sensor: its feedback is kinda chaotic and all 3 (!!!) sensors I posses, showing me different values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants