Ambient Light Sensor

Editor’s Draft,

This version:
https://w3c.github.io/ambient-light/
Latest published version:
http://www.w3.org/TR/ambient-light/
Previous Versions:
Version History:
https://github.com/w3c/ambient-light/commits/gh-pages/index.bs
Feedback:
public-device-apis@w3.org with subject line “[ambient-light] … message topic …” (archives)
Issue Tracking:
GitHub
Level 2 Issues
Editor:
Anssi Kostiainen (Intel Corporation)
Former Editors:
Tobie Langel (Codespeaks, formerly on behalf of Intel Corporation)
Doug Turner (Mozilla Corporation)
Bug Reports:
via the w3c/ambient-light repository on GitHub
Test Suite:
web-platform-tests on GitHub

Abstract

This specification defines a concrete sensor interface to monitor the ambient light level or illuminance of the device’s environment.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

If you wish to make comments regarding this document, please send them to public-device-apis@w3.org (subscribe, archives). When sending e-mail, please put the text “ambient-light” in the subject, preferably like this: “[ambient-light] …summary of comment…”. All comments are welcome.

This document was produced by the Device and Sensors Working Group.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 1 March 2017 W3C Process Document.

1. Introduction

The Ambient Light Sensor extends the Generic Sensor API [GENERIC-SENSOR] to provide information about ambient light levels, as detected by the device’s main light detector, in terms of lux units.

The light-level media feature [MEDIAQUERIES-4] provides less granular information about the ambient light level.

Note: it might be worthwhile to provide a high-level Light Level Sensor which would mirror the light-level media feature, but in JavaScript. This sensor would not require additional user permission to be activated in user agents that exposed the light-level media feature.

2. Examples

let sensor = new AmbientLightSensor();
sensor.start();
    
sensor.onreading = function(event) {
    console.log(sensor.illuminance);
};

sensor.onerror = function(event) {
    console.log(event.error.name, event.error.message);
};

3. Security and Privacy Considerations

There are no specific security and privacy considerations beyond those described in the Generic Sensor API [GENERIC-SENSOR].

4. Model

The Ambient Light Sensor’s associated Sensor subclass is the AmbientLightSensor class.

The Ambient Light Sensor has a default sensor, which is the device’s main light detector.

The Ambient Light Sensor’s reporting mode is implementation specific.

The Ambient Light Sensor has an associated PermissionName which is "ambient-light-sensor".

The current light level or illuminance is a value that represents the ambient light levels around the hosting device. Its unit is the lux (lx) [SI].

Note: The precise lux value reported by different devices in the same light can be different, due to differences in detection method, sensor construction, etc.

5. API

5.1. The AmbientLightSensor Interface

[Constructor(optional SensorOptions sensorOptions)]
interface AmbientLightSensor : Sensor {
  readonly attribute unrestricted double? illuminance;
};

To Construct an AmbientLightSensor Object the user agent must invoke the construct a Sensor object abstract operation.

5.1.1. The illuminance attribute

The illuminance attribute of the AmbientLightSensor interface represents the current light level.

6. Use Cases and Requirements

  1. A Web application gradually updates document style based on light level changes.

  2. A Web application provides input for a smart home system to control lighting.

  3. A Web aplication checks whether light level at work space is sufficient, based on occupational health regulations.

  4. A Web application monitors light level changes produced by hovering hand user gesture and interprets them to control a game character.

  5. A Web application calculates settings for a camera with manual controls (apperture, shutter speed, ISO).

The mentioned use cases require plain light level data, not a pre-defined set of values.

7. Acknowledgements

Doug Turner for the initial prototype and Marcos Caceres for the test suite.

Paul Bakaus for the LightLevelSensor idea.

Mikhail Pozdnyakov and Alexander Shalamov for the use cases and requirements.

8. Conformance

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

A conformant user agent must implement all the requirements listed in this specification that are applicable to user agents.

The IDL fragments in this specification must be interpreted as required for conforming IDL fragments, as described in the Web IDL specification. [WEBIDL]

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[GENERIC-SENSOR]
Tobie Langel; Rick Waldron. Generic Sensor API. URL: https://w3c.github.io/sensors/
[PERMISSIONS]
Mounir Lamouri; Marcos Caceres. The Permissions API. URL: https://w3c.github.io/permissions/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119
[WEBIDL]
Cameron McCormack; Boris Zbarsky; Tobie Langel. Web IDL. URL: https://heycam.github.io/webidl/

Informative References

[MEDIAQUERIES-4]
Florian Rivoal; Tab Atkins Jr.. Media Queries Level 4. URL: https://drafts.csswg.org/mediaqueries-4/
[SI]
SI Brochure: The International System of Units (SI), 8th edition. 2014. URL: http://www.bipm.org/en/publications/si-brochure/

IDL Index

[Constructor(optional SensorOptions sensorOptions)]
interface AmbientLightSensor : Sensor {
  readonly attribute unrestricted double? illuminance;
};