Android light sensor via RxJava - optimizations
<p>I've implemented the light sensor using RxJava implementation. I receive <code>lux</code> values correctly, but the variation is very high. 
For example, even when the device moves very little, the values change and are emitted via the sensor listener. </p>

<pre><code>@NonNull
@Override
Observable&lt;Boolean&gt; createObservable(@NonNull Context context) {
    SensorManager sensorManager = (SensorManager) context.getSystemService(
            Context.SENSOR_SERVICE);
    List&lt;Sensor&gt; sensorList = sensorManager.getSensorList(Sensor.TYPE_LIGHT);
    if (null == sensorList || sensorList.isEmpty()) {
        throw new IllegalStateException("Unsupported Sensor: Device has no light sensor");
    }

    return SensorEventObservableFactory
            .createSensorEventObservable(sensorList.get(0), sensorManager,
                    SensorManager.SENSOR_DELAY_NORMAL)
            // Ambient light level in SI lux units
            .map(sensorEvent -&gt; sensorEvent.values[0])
            // Make sure the lux value is valid
            .filter(lx -&gt; !(null == lx || lx &lt; 0))
            // Detect if light or dark environment
            .map(lx -&gt; {
                Timber.d("new LX value = %s", lx);
                // Over 15 lx means it is a light environment
                // Bellow 15 lx means it is a dark environment
                return lx &gt; 15f;
            })
            .distinctUntilChanged();
}
</code></pre>

<p>How can I avoid this issue? I've been thinking I can add an delay between events, but this could get me in situations where the detection is not very fast and the risk is high to get stuck in an ambient mode. I've been struggling with this for a few hours and I'm out of ideas on how to efficiently detect ambient light.</p>

<p>Thank you in advance.</p>