-
-
Notifications
You must be signed in to change notification settings - Fork 1
Querying Fan States
This guide follows the code snippets and concepts from previous guides. Please refer to these first.
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.
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);
});
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. |
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
})
Dyson4J is not in any way associated with nor endorsed by Dyson™️ Ltd. or any subsidiary entities. This project is maintained separately by the community and does not bare any responsibility for damage caused to Dyson™️ devices.