Skip to content

Querying Fan States

Parker Hawke edited this page Sep 10, 2022 · 1 revision

This guide follows the code snippets and concepts from previous guides. Please refer to these first.

Querying Current Fan States

Because Dyson fans can be changed externally with apps and remotes, states are not cached by Dyson4J and must be queried for each time. Caching of states is the responsibility of the library user. Dyson4J provides instances of DysonFan two methods to query two different state snapshots, requestCurrentState() and requestEnvironmentalSensorData(). Both of these methods are asynchronous and will return instances of DeviceStatus and EnvironmentalSensorData respectively.

requestCurrentState()

The current state of the fan can be queried which includes information about the fan's current settings (such as its mode, speed, oscillation, etc.), as well as other miscellaneous data. From the DeviceStatus, we can extract the following information:

DysonFan dysonFan = // ...

dysonFan.connect()
    .thenCompose(DysonFan::requestCurrentState) // We're calling requestCurrentState() here
    .thenAccept(state -> { // And reading from it here
        // See below for information on error and warning codes
        String errorCode = state.getErrorCode();
        String warningCode = state.getWarningCode();

        // The remaining filter life calculated in hours
        int remainingFilterLife = state.getRemainingFilterLife();

        // Any state can be fetched (so long as the fan supports it)
        FanMode mode = state.getState(FanState.MODE);
        FanOscillation oscillation = state.getState(FanState.OSCILLATION);
    });

Error & Warning Codes

There are a few error and warning codes for which constants are defined in the DeviceStatus class.

Error Code DeviceStatus Constant Meaning
02C0 ERROR_CODE_NORMAL The fan is operating normally.
02C9 ERROR_CODE_NORMAL_2 The fan is operating normally.
NONE ERROR_CODE_REPLACE_FILTER The filter life has reached zero and needs replacing.
Warning Code DeviceStatus Constant Meaning
NONE WARNING_CODE_NORMAL The fan is operating normally.
FLTR WARNING_CODE_REPLACE_FILTER The filter life has reached zero and needs replacing.

requestEnvironmentalSensorData()

In addition to the fan's current state, environmental sensor data can be queried and extracted using the requestEnvironmentalSensorData() method. We can extract the following information:

DysonFan dysonFan = // ...

dysonFan.connect()
    .thenCompose(DysonFan::requestEnvironmentalSensorData)
    .thenAccept(data -> {
        double temperature = data.getTemperature(); // Measured in Kelvin
        int relativeHumidity = data.getRelativeHumidity(); // Measured as a percentage from 0 - 100%
        int particles = data.getParticles(); // The amount of particles in the air, from 0 - 9999
        int volatileCompounds = data.getVolatileCompounds(); // The amount of volatile particles in the air, from 0 - 9999, or -1 if initializing
        SleepTimer sleepTimer = data.getSleepTimer(); // The active sleep timer, or SleepTimer.OFF if none
    })

(internal documentation is not API. You may use this if you wish to create your own library).

Clone this wiki locally