Constructor for the CreateCeilingFanAccessory object.
The plugin platform object.
The homebridge platform accessory object.
Private
Readonly
accessoryThe homebridge platform accessory object.
Private
devicePrivate
Readonly
fanPrivate
fanPrivate
Readonly
fanPrivate
fanPrivate
Readonly
getPrivate
Readonly
getPrivate
Readonly
getPrivate
Readonly
getPrivate
getPrivate
isPrivate
lightPrivate
mutexPrivate
Readonly
platformThe plugin platform object.
Private
Readonly
setPrivate
statePrivate
adjustAdjust the rotation speed input value.
This method is used for converting the input state of the slider value to the nearest value that corresponds to the device fan speed.
See the CreateCeilingFanAccessory class description for more details.
The input value of the rotation speed.
The adjusted value of the rotation speed.
Private
fanConvert the fan active state of the accessory to Fanv2 Active characteristic value.
The Fanv2 Active characteristic value.
Private
fanConvert the fan rotation direction of the accessory to Fanv2 Rotation Direction characteristic value.
The Fanv2 Rotation Direction characteristic value.
Private
fanConvert the fan rotation speed of the accessory to Fanv2 Rotation Speed characteristic value.
The Fanv2 Rotation Speed characteristic value.
Private
getGet device status.
This method reads the status of the device periodically and updates the accessory state after completing the operation. The actual communication is carried out with a timeout mechanism, so that an unresponsive device will not make the plugin and HomeKit unresponsive. If the communication fails, the periodic timer will be set with a shorter timeout so that the next retry attempt happens fast. After the communication with the device is recovered, the period will be reset to the original period value.
The function can be called in two ways:
await
: the method starts the reading operation and
waits (i.e. blocks) until the reading has been completed (or timed out).await
): the method starts the reading
operation and returns right afterwards, not waiting for the reading
to be completed. This is used when handling accessory GET requests
from HomeKit. Get requests should return as fast as possible, because
long delays will result in HomeKit being unresponsive and a bad user
experience in general.If the function is called again while there is already an ongoing read operation, the reading will simply be skipped - the accessory status will be updated anyway after executing the already ongoing reading operation. This can happen e.g. when a periodic read operation is already in place and a GET request arrives from HomeKit at the same time.
Handle the get requests from HomeKit to get the current value of the Fanv2 Active characteristic
The Fanv2 Active characteristic value from the device state cache.
Handle the set requests from HomeKit to set the device with the Fanv2 Active characteristic value
The Fanv2 Active characteristic value to be set.
Handle the get requests from HomeKit to get the current value of the Fanv2 Rotation Direction characteristic
The Fanv2 Rotation Direction characteristic value from the device state cache.
Handle the set requests from HomeKit to set the device with the Fanv2 Rotation Direction characteristic value
The Fanv2 Rotation Direction characteristic value to be set.
Handle the get requests from HomeKit to get the current value of the Fanv2 Rotation Speed characteristic
The Fanv2 Rotation Speed characteristic value from the device state cache.
Handle the set requests from HomeKit to set the device with the Fanv2 Rotation Speed characteristic value
The Fanv2 Rotation Speed characteristic value to be set.
Handle the get requests from HomeKit to get the current value of the Lightbulb On characteristic
The Lightbulb On characteristic value from the device state cache.
Handle the set requests from HomeKit to set the device with the Lightbulb On characteristic value
The Lightbulb On characteristic value to be set.
Private
lightConvert the light on state of the accessory to Lightbulb On characteristic value.
The Lightbulb On characteristic value.
Private
logWrapper function to log device communication errors depending on the device configuration.
By default, the device communication errors are logged as debug logs, and they are only visible if the Homebridge Debug Mode is enabled. If the corresponding setting is set in the device configuration, the communication errors are logged as info messages and they are visible in the Homebridge log regardless whether the Homebridge Debug Mode is enabled.
Message to be logged; analogous to the Logger interface.
Additional arguments; analogous to the Logger interface.
Private
setSet device value.
This method sends a command to the device to set the device into the required state. Only one parameter can be set at a time.
The data point index of the device to be set.
The value to be set.
Private
setSet device value with timeout.
This is a simple wrapper for the setDeviceValue method with a timeout mechanism. If the method fails to execute within the setDeviceStatusTimeout value, it throws a HomeKit No Response status.
The data point index of the device to be set.
The value to be set.
Private
throwThrow a HomeKit No Response status if the accessory state is invalid.
Private
updateUpdate all accessory service characteristics based on the accessory state.
Private
updateUpdate the accessory state with the values received from the device.
The raw data points object received from the device.
Private
waitWait for a promise to be resolved within a given timeout.
The promise to be resolved within a given timeout.
The timeout in [ms] within the promise should be resolved.
The resolved promise if it gets resolved within the timeout, otherwise reject the promise.
CreateCeilingFanAccessory: the accessory implementation for CREATE ceiling fans.
This class contains the accessory implementation and follows the Homebridge plugin development recommendations.
Exposed services and characteristics
Fanv2
Active
,Rotation Direction
,Rotation Speed
Lightbulb
On
Note: the
Lightbulb
service is only exposed if the accessory has been configured with the light option enabled.Fan rotation speed representation
CREATE fans have speed settings ranging from
1
(lowest) to6
(highest). The HomeKit UI slider for the fan rotation speed provides a value from1
to100
and0
means the fan is turned off. The slider steps can be configured to a desired value via theMin Step
Characteristic. This works well e.g. for Dyson devices where the speed settings ranges from1
to10
. In this case theMin Step
Characteristic can be configured to10
, resulting in a nice user experience where the0
-100
UI slider is divided into 10 steps. However, this does not work well for CREATE fans with 6 speed steps. In order to provide smooth user experience, the following representation is implemented:The UI slider is configured with the default
Min Step
Characteristic of1
. This provides smooth and fluid user input and slider operation.The following UI slider inputs represent the different speed settings of the fan:
When the user operates the slider, a debouncing timer with the value of fanSetSpeedDebouncePeriod member is set. When the timer fires, the current state of the slider value is converted to the nearest value that corresponds to the device fan speed. The purpose of the debounce timer is to provide great user experience. Without the debounce timer, every moment the user slides the finger would result in generating lots of events - making the slider jump around immediately, without waiting for the user to finish adjusting the speed.
Fan rotation direction representation
The rotation of the device as seen from standing below the fan follows the HomeKit rotation representation.
forward
(default)reverse
Device communication
The fan is a Tuya-compatible device and its firmware is mildly put: not the best. Among other issues, devices with these firmware are known to stop responding to commands, randomly drop connection, etc (see e.g. https://github.com/jasonacox/tinytuya/discussions/443 and https://github.com/moifort/homebridge-create-fan/issues/18).
To provide reliable operation via HomeKit, this plugin implements the device communication the following way:
Communication failure tends to happen when attempting to control the device via HomeKit right after using the device's physical remote. The device used for development & testing (CREATE Wind Calm model purchased in 2025) seemed to always recover from a failed communication latest after a few retry attempts.
See