npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@capgo/capacitor-light-sensor

v9.0.0

Published

Capacitor plugin for accessing the device light sensor (Android only)

Readme

@capgo/capacitor-light-sensor

Read the ambient light level from the device sensor in your Capacitor app, to adapt themes, brightness or camera hints to the room.

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-light-sensor in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-light-sensor to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

Built and maintained with AI

We build, improve and fix our plugins with heavy use of AI, so issues usually get fixed in under a day and pull requests get feedback the same day. A human still reviews, tests and merges 50+ pull requests daily.

  • Most plugin issues get a fix pull request the same day, often within a couple of hours, and are usually resolved in one to two days.
  • Every pull request goes through our AI review system, usually within minutes.
  • Our AI pre-checks tests, code review, conventions and security, then a human reviews, tests and merges.
  • A human, Martin, reviews, tests and merges 50+ pull requests every day.
  • In the last 90 days, 95% of plugin issues were resolved.

Learn more about how we build with AI

Key features

  • Live readings: start() streams lux values through the lightSensorChange event.
  • Sampling control: pass an update interval to start().
  • Availability: isAvailable() checks for a light sensor first.
  • Stop: stop() ends updates to save battery.
  • Permissions: checkPermissions() and requestPermissions() exist for API parity. Both always report highSamplingRate as granted.
  • Platforms: Android. Android only. iOS has no public ambient light sensor API, and web is not available.

Why Capacitor Light Sensor?

  • Real Ambient Light Data: Get accurate light level readings in lux
  • Efficient Sensor Access: Uses native Android sensor APIs for optimal performance
  • Configurable Update Intervals: Control how often you receive sensor updates
  • Battery Conscious: Start and stop the sensor as needed to conserve battery
  • TypeScript Support: Full type definitions for a great developer experience

Platform Support

| Platform | Support | |----------|---------| | Android | ✅ Full support via TYPE_LIGHT sensor | | iOS | ❌ Not available (no public API) | | Web | ❌ Not available |

Compatibility

| Plugin version | Capacitor compatibility | Maintained | | -------------- | ----------------------- | ---------- | | v9.*.* | v9.*.* | ✅ | | v8.*.* | v8.*.* | On demand | | v7.*.* | v7.*.* | On demand | | v6.*.* | v6.*.* | ❌ | | v5.*.* | v5.*.* | ❌ |

Note: The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v9 for Capacitor 9). Only the latest major version is actively maintained.

Migrating from v8 to v9

v9 of @capgo/capacitor-light-sensor targets Capacitor 9. Update Capacitor and this plugin together, then sync the native projects:

npm install @capacitor/core@^9.0.0 @capacitor/cli@^9.0.0 @capacitor/ios@^9.0.0 @capacitor/android@^9.0.0 @capgo/capacitor-light-sensor@^9.0.0
npx cap sync

Capacitor 9 needs Node.js 24+, iOS 16+ (Xcode 27) and Android minSdk 26 / compileSdk 37. Follow the official Capacitor 9 update guide for the app side changes.

No plugin API was removed: the JavaScript API of v9 is the same as v8.

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-light-sensor` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-light-sensor
npx cap sync

Requirements

Android

  • Minimum SDK: 24 (Android 7.0)
  • Target SDK: 36
  • Device must have a light sensor (most Android phones do)

High Sampling Rate (Android 12+)

For update intervals below 200ms on Android 12 and above, add this permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />

Usage

import { LightSensor } from '@capgo/capacitor-light-sensor';

// Check if sensor is available
const { available } = await LightSensor.isAvailable();

if (available) {
  // Start listening with 500ms update interval
  await LightSensor.start({ updateInterval: 500 });

  // Add listener for sensor data
  const handle = await LightSensor.addListener('lightSensorChange', (data) => {
    console.log(`Light level: ${data.illuminance} lux`);
    console.log(`Timestamp: ${data.timestamp}`);
  });

  // Later, stop the sensor
  await LightSensor.stop();
  await handle.remove();
}

Light Level Reference

| Lux Value | Condition | |-----------|-----------| | 0.0001 | Moonless, overcast night | | 0.27-1 | Full moon on a clear night | | 3.4 | Dark limit of civil twilight | | 50 | Family living room | | 80 | Office hallway | | 100 | Very dark overcast day | | 400 | Sunrise/sunset on clear day | | 1,000 | Overcast day | | 10,000-25,000 | Full daylight (indirect) | | 32,000-100,000 | Direct sunlight |

API

Capacitor plugin for accessing the device's ambient light sensor.

isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check if the light sensor is available on the current device. You should always check sensor availability before attempting to use it.

Returns: Promise<IsAvailableResult>

Since: 0.0.1


start(...)

start(options?: StartOptions | undefined) => Promise<void>

Start listening to light sensor updates. This will begin sensor measurements at the specified interval. Use addListener to receive the sensor data.

| Param | Type | Description | | ------------- | ----------------------------------------------------- | -------------------------------------- | | options | StartOptions | - Configuration options for the sensor |

Since: 0.0.1


stop()

stop() => Promise<void>

Stop listening to light sensor updates. This will stop the sensor and conserve battery.

Since: 0.0.1


addListener('lightSensorChange', ...)

addListener(eventName: 'lightSensorChange', listenerFunc: LightSensorCallback) => Promise<PluginListenerHandle>

Add a listener for light sensor change events. The listener will be called whenever new sensor data is available.

| Param | Type | Description | | ------------------ | ------------------------------------------------------------------- | ------------------------------------------ | | eventName | 'lightSensorChange' | - Must be 'lightSensorChange' | | listenerFunc | LightSensorCallback | - Callback function to receive sensor data |

Returns: Promise<PluginListenerHandle>

Since: 0.0.1


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for light sensor events.

Since: 0.0.1


checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check the current permission status for high sampling rate sensors. On Android 12+, the HIGH_SAMPLING_RATE_SENSORS permission is required for sensor update intervals below 200ms.

Returns: Promise<PermissionStatus>

Since: 0.0.1


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request permission for high sampling rate sensors. On Android 12+, this requests the HIGH_SAMPLING_RATE_SENSORS permission.

Returns: Promise<PermissionStatus>

Since: 0.0.1


getPluginVersion()

getPluginVersion() => Promise<VersionResult>

Get the current version of the plugin.

Returns: Promise<VersionResult>

Since: 0.0.1


Interfaces

IsAvailableResult

Result indicating whether the sensor is available.

| Prop | Type | Description | Since | | --------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------- | ----- | | available | boolean | Whether the light sensor is available on this device. Always false on iOS as the light sensor API is not available. | 0.0.1 |

StartOptions

Options for starting the light sensor listener.

| Prop | Type | Description | Default | Since | | -------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------- | ----- | | updateInterval | number | The desired interval between sensor updates in milliseconds. On Android 12+, there's a minimum interval of 200ms unless the app has the HIGH_SAMPLING_RATE_SENSORS permission. | 200 | 0.0.1 |

PluginListenerHandle

| Prop | Type | | ------------ | ----------------------------------------- | | remove | () => Promise<void> |

LightSensorMeasurement

A single light sensor measurement.

| Prop | Type | Description | Since | | ----------------- | ------------------- | ---------------------------------------------------- | ----- | | illuminance | number | Ambient light level in lux (lx). | 0.0.1 | | timestamp | number | Timestamp of the measurement in seconds since epoch. | 0.0.1 |

PermissionStatus

Result of a permission request or check.

| Prop | Type | Description | Since | | ---------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----- | | highSamplingRate | 'prompt' | 'prompt-with-rationale' | 'granted' | 'denied' | Whether the high sampling rate sensor permission is granted. On Android 12+, this permission is required for update intervals below 200ms. | 0.0.1 |

VersionResult

Plugin version information.

| Prop | Type | Description | Since | | ------------- | ------------------- | ---------------------------------- | ----- | | version | string | The current version of the plugin. | 0.0.1 |

Type Aliases

LightSensorCallback

Callback function for light sensor updates.

(measurement: LightSensorMeasurement): void

Contributing

See CONTRIBUTING.md for details on how to contribute to this plugin.

License

MPL-2.0

Credits

This SDK has been inspired by Expo light sensor.