# @capgo/capacitor-light-sensor

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

Latest version **8.1.18** (published 2026-09-15) · MPL-2.0 license · 3.0K weekly downloads

## Install

```sh
npm install @capgo/capacitor-light-sensor
pnpm add @capgo/capacitor-light-sensor
yarn add @capgo/capacitor-light-sensor
bun add @capgo/capacitor-light-sensor
```

## Health

**Score 80/100 (A)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

## Facts

| | |
|---|---|
| Version | 8.1.18 |
| Published | 2026-09-15 |
| First published | 2026-01-04 |
| Weekly downloads | 3.0K |
| License | MPL-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 75.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 5 |
| Author | Capgo |
| Maintainers | riderx, torichancapgo |
| Keywords | capacitor, plugin, native, light, sensor, ambient, illuminance, lux, android |

## Links

- npm: https://www.npmjs.com/package/@capgo/capacitor-light-sensor
- Repository: https://github.com/Cap-go/capacitor-light-sensor
- Homepage: https://capgo.app/docs/plugins/light-sensor/
- Issues: https://github.com/Cap-go/capacitor-light-sensor/issues
- npm.io page: https://npm.io/package/@capgo/capacitor-light-sensor

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads
- [angular-ui-block](https://npm.io/package/angular-ui-block.md) — 8 weekly downloads

## Recent versions

- 8.1.18 (latest) — 2026-09-15
- 8.1.17 — 2026-08-20
- 8.1.16 — 2026-07-11
- 8.1.15 — 2026-06-19
- 8.1.14 — 2026-06-16
- 8.1.13 — 2026-06-16
- 8.1.12 — 2026-06-15
- 8.1.11 — 2026-06-04
- 8.1.10 — 2026-06-04
- 8.1.9 — 2026-05-24
- 8.1.8 — 2026-05-11
- 8.1.7 — 2026-04-08
- 8.1.6 — 2026-02-06
- 8.1.5 — 2026-02-04
- 8.1.4 — 2026-01-31
- … 4 more at https://npm.io/package/@capgo/capacitor-light-sensor/versions

## README

# @capgo/capacitor-light-sensor
<a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-light-sensor" alt="Capgo - Instant updates for Capacitor" /></a>

<div align="center">
  <h2><a href="https://capgo.app/?ref=plugin_light_sensor"> ➡️ Get Instant updates for your App with Capgo</a></h2>
  <h2><a href="https://capgo.app/consulting/?ref=plugin_light_sensor"> Missing a feature? We'll build the plugin for you 💪</a></h2>
</div>

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

## 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 |
| -------------- | ----------------------- | ---------- |
| v8.\*.\*       | v8.\*.\*                | ✅          |
| 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 v8 for Capacitor 8). Only the latest major version is actively maintained.

## Installation

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

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

Then use the following prompt:

```text
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:

```bash
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`:

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

## Usage

```typescript
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

<docgen-index>

* [`isAvailable()`](#isavailable)
* [`start(...)`](#start)
* [`stop()`](#stop)
* [`addListener('lightSensorChange', ...)`](#addlistenerlightsensorchange-)
* [`removeAllListeners()`](#removealllisteners)
* [`checkPermissions()`](#checkpermissions)
* [`requestPermissions()`](#requestpermissions)
* [`getPluginVersion()`](#getpluginversion)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)

</docgen-index>

<docgen-api>
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->

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

### isAvailable()

```typescript
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:** <code>Promise&lt;<a href="#isavailableresult">IsAvailableResult</a>&gt;</code>

**Since:** 0.0.1

--------------------


### start(...)

```typescript
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`** | <code><a href="#startoptions">StartOptions</a></code> | - Configuration options for the sensor |

**Since:** 0.0.1

--------------------


### stop()

```typescript
stop() => Promise<void>
```

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

**Since:** 0.0.1

--------------------


### addListener('lightSensorChange', ...)

```typescript
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`**    | <code>'lightSensorChange'</code>                                    | - Must be 'lightSensorChange'              |
| **`listenerFunc`** | <code><a href="#lightsensorcallback">LightSensorCallback</a></code> | - Callback function to receive sensor data |

**Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>

**Since:** 0.0.1

--------------------


### removeAllListeners()

```typescript
removeAllListeners() => Promise<void>
```

Remove all listeners for light sensor events.

**Since:** 0.0.1

--------------------


### checkPermissions()

```typescript
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:** <code>Promise&lt;<a href="#permissionstatus">PermissionStatus</a>&gt;</code>

**Since:** 0.0.1

--------------------


### requestPermissions()

```typescript
requestPermissions() => Promise<PermissionStatus>
```

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

**Returns:** <code>Promise&lt;<a href="#permissionstatus">PermissionStatus</a>&gt;</code>

**Since:** 0.0.1

--------------------


### getPluginVersion()

```typescript
getPluginVersion() => Promise<VersionResult>
```

Get the current version of the plugin.

**Returns:** <code>Promise&lt;<a href="#versionresult">VersionResult</a>&gt;</code>

**Since:** 0.0.1

--------------------


### Interfaces


#### IsAvailableResult

Result indicating whether the sensor is available.

| Prop            | Type                 | Description                                                                                                         | Since |
| --------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------- | ----- |
| **`available`** | <code>boolean</code> | 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`** | <code>number</code> | 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. | <code>200</code> | 0.0.1 |


#### PluginListenerHandle

| Prop         | Type                                      |
| ------------ | ----------------------------------------- |
| **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |


#### LightSensorMeasurement

A single light sensor measurement.

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


#### PermissionStatus

Result of a permission request or check.

| Prop                   | Type                                                                      | Description                                                                                                                                | Since |
| ---------------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----- |
| **`highSamplingRate`** | <code>'prompt' \| 'prompt-with-rationale' \| 'granted' \| 'denied'</code> | 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`** | <code>string</code> | The current version of the plugin. | 0.0.1 |


### Type Aliases


#### LightSensorCallback

Callback function for light sensor updates.

<code>(measurement: <a href="#lightsensormeasurement">LightSensorMeasurement</a>): void</code>

</docgen-api>

## Contributing

See [CONTRIBUTING.md](./CONTRIBUTING.md) for details on how to contribute to this plugin.

## License

[MPL-2.0](./LICENSE)

## Credits

This SDK has been inspired by [Expo light sensor](https://docs.expo.dev/versions/latest/sdk/light-sensor/).

---
_Source: https://npm.io/package/@capgo/capacitor-light-sensor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
