Device

Required methods

init

init(provider: Provider): Promise<boolean>;

Called after the package is loaded from disk and the Provider for your device is initialized. This Provider gives you access to all the exposed features of QuantumHub, so you’ll probably want to store it in your device class.

You can return false if something goes wrong, in that case the device will be disabled in the UI and there will be no attempt to start your device.

start

start(): Promise<void>;

Called when the device is being started, during startup this is immediately after the init method (if the device isn’t disabled in the config, and init passed succesfully).

This is method returns a promise, but QuantumHub will not wait for it to finish, it will continue starting other devices.

stop

stop(): Promise<void>;

Called when the device is being stopped. This is only called when the device is stopped using the stop button in the QuantumHub UI or when QuantumHub is shutting down.

destroy

destroy(): Promise<void>;

Called when the device is being destroyed. This is only called when QuantumHub is shutting down.

valueChanged

valueChanged(attribute: Attribute, value: any): Promise<void>;

Called when the value of an Attribute is changed, for example a value is changed by the Home Assistant MQTT integration.

Optional methods

MQTT

onMessage

onMessage?(topic: string, message: Buffer): Promise<void>;

When your device is manually subscribed to a topic on the MQTT broker, this method is called when a new value is received on that topic.

Check out provider.mqtt.subscribeToTopic for more information.

Scene

onSceneTriggered

onSceneTriggered?(attribute: SceneAttribute): Promise<void>;

When your device exposes a scene to Home Assistant, this method is called when the scene is triggered. The supplied parameter contains the triggered SceneAttribute.

Button

onButtonPressed

onButtonPressed?(attribute: ButtonAttribute): Promise<void>;

When your device exposes a button to Home Assistant, this method is called when the button is pressed. The supplied parameter contains the triggered ButtonAttribute.

Select

onSelectChanged

onSelectChanged?(attribute: SelectAttribute, value: string): Promise<void>;

When the value of a select attribute is changed, this method is called. The supplied parameter contains the changed SelectAttribute and the selected value, which is supplied in the options field of the attribute.

Number

onNumberChanged

onNumberChanged?(attribute: NumberAttribute, value: number): Promise<void>;

When the value of a number attribute is changed, this method is called. The supplied parameter contains the changed NumberAttribute and the new value.

Switch

onSwitchChanged

onSwitchChanged?(attribute: SwitchAttribute, value: boolean): Promise<void>;

When the value of a switch attribute is changed, this method is called. The supplied parameter contains the changed SwitchAttribute and the new value.

Climate

onHvacModeChanged

onHvacModeChanged?(attribute: ClimateAttribute, value: string): Promise<void>;

When the hvac mode of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.

onClimateModeChanged

onClimateModeChanged?(attribute: ClimateAttribute, value: string): Promise<void>;

When the climate mode of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.

onClimatePresetModeChanged

onClimatePresetModeChanged?(attribute: ClimateAttribute, value: string): Promise<void>;

When the climate preset mode of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.

onClimateFanModeChanged

onClimateFanModeChanged?(attribute: ClimateAttribute, value: string): Promise<void>;

When the climate fan mode of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.

onClimateSwingModeChanged

onClimateSwingModeChanged?(attribute: ClimateAttribute, value: string): Promise<void>;

When the climate swing mode of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.

onPowerChanged

onPowerChanged?(attribute: ClimateAttribute, value: boolean): Promise<void>;

When the power state of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.

onTargetTemperatureChanged

onTargetTemperatureChanged?(attribute: ClimateAttribute, value: number): Promise<void>;

When the target temperature of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.

onTargetHumidityChanged

onTargetHumidityChanged?(attribute: ClimateAttribute, value: number): Promise<void>;

When the target humidity of a climate attribute is changed, this method is called. The supplied parameter contains the changed ClimateAttribute and the new value.