HAHVAC class¶
-
class HAHVAC : public HABaseDeviceType¶
HAHVAC lets you control your HVAC devices.
Note
You can find more information about this entity in the Home Assistant documentation: https://www.home-assistant.io/integrations/climate.mqtt/
Public Types
-
enum Features¶
The list of features available in the HVAC. They’re used in the constructor.
Values:
-
enumerator DefaultFeatures¶
-
enumerator ActionFeature¶
-
enumerator AuxHeatingFeature¶
-
enumerator PowerFeature¶
-
enumerator FanFeature¶
-
enumerator SwingFeature¶
-
enumerator ModesFeature¶
-
enumerator TargetTemperatureFeature¶
-
enumerator DefaultFeatures¶
-
enum Action¶
The list of available actions of the HVAC.
Values:
-
enumerator UnknownAction¶
-
enumerator OffAction¶
-
enumerator HeatingAction¶
-
enumerator CoolingAction¶
-
enumerator DryingAction¶
-
enumerator IdleAction¶
-
enumerator FanAction¶
-
enumerator UnknownAction¶
-
enum FanMode¶
The list of available fan modes.
Values:
-
enumerator UnknownFanMode¶
-
enumerator AutoFanMode¶
-
enumerator LowFanMode¶
-
enumerator MediumFanMode¶
-
enumerator HighFanMode¶
-
enumerator UnknownFanMode¶
-
enum SwingMode¶
The list of available swing modes.
Values:
-
enumerator UnknownSwingMode¶
-
enumerator OnSwingMode¶
-
enumerator OffSwingMode¶
-
enumerator UnknownSwingMode¶
Public Functions
-
HAHVAC(const char *uniqueId, const uint16_t features = DefaultFeatures, const NumberPrecision precision = PrecisionP1)¶
- Parameters
uniqueId – The unique ID of the HVAC. It needs to be unique in a scope of your device.
features – Features that should be enabled for the HVAC.
precision – The precision of temperatures reported by the HVAC.
-
~HAHVAC()¶
Frees memory allocated for the arrays serialization.
-
bool setCurrentTemperature(const HANumeric &temperature, const bool force = false)¶
Changes current temperature of the HVAC and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
temperature – New current temperature.
force – Forces to update the temperature without comparing it to a previous known value.
- Returns
Returns
true
if MQTT message has been published successfully.
-
inline bool setCurrentTemperature(const int8_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setCurrentTemperature(const int16_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setCurrentTemperature(const int32_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setCurrentTemperature(const uint8_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setCurrentTemperature(const uint16_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setCurrentTemperature(const uint32_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setCurrentTemperature(const float temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
bool setAction(const Action action, const bool force = false)¶
Changes action of the HVAC and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
action – New action.
force – Forces to update the action without comparing it to a previous known value.
- Returns
Returns
true
if MQTT message has been published successfully.
-
bool setAuxState(const bool state, const bool force = false)¶
Changes state of the aux heating and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
state – The new state.
force – Forces to update the state without comparing it to a previous known value.
- Returns
Returns
true
if MQTT message has been published successfully.
-
bool setFanMode(const FanMode mode, const bool force = false)¶
Changes mode of the fan of the HVAC and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
mode – New fan’s mode.
force – Forces to update the mode without comparing it to a previous known value.
- Returns
Returns
true
if MQTT message has been published successfully.
-
bool setSwingMode(const SwingMode mode, const bool force = false)¶
Changes swing mode of the HVAC and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
mode – New swing mode.
force – Forces to update the mode without comparing it to a previous known value.
- Returns
Returns
true
if MQTT message has been published successfully.
-
bool setMode(const Mode mode, const bool force = false)¶
Changes mode of the HVAC and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
mode – New HVAC’s mode.
force – Forces to update the mode without comparing it to a previous known value.
- Returns
Returns
true
if MQTT message has been published successfully.
-
bool setTargetTemperature(const HANumeric &temperature, const bool force = false)¶
Changes target temperature of the HVAC and publishes MQTT message. Please note that if a new value is the same as previous one, the MQTT message won’t be published.
- Parameters
temperature – Target temperature to set.
force – Forces to update the mode without comparing it to a previous known value.
- Returns
Returns
true
if MQTT message has been published successfully.
-
inline bool setTargetTemperature(const int8_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setTargetTemperature(const int16_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setTargetTemperature(const int32_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setTargetTemperature(const uint8_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setTargetTemperature(const uint16_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setTargetTemperature(const uint32_t temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline bool setTargetTemperature(const float temperature, const bool force = false)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentCurrentTemperature(const HANumeric &temperature)¶
Sets current temperature of the HVAC without publishing it to Home Assistant. This method may be useful if you want to change temperature before connection with MQTT broker is acquired.
- Parameters
temperature – New current temperature.
-
inline void setCurrentCurrentTemperature(const int8_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentCurrentTemperature(const int16_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentCurrentTemperature(const int32_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentCurrentTemperature(const uint8_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentCurrentTemperature(const uint16_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentCurrentTemperature(const uint32_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentCurrentTemperature(const float temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline const HANumeric &getCurrentTemperature() const¶
Returns last known current temperature of the HVAC. If setCurrentTemperature method wasn’t called the initial value will be returned.
-
inline void setCurrentAction(const Action action)¶
Sets action of the HVAC without publishing it to Home Assistant. This method may be useful if you want to change the action before connection with MQTT broker is acquired.
- Parameters
action – New action.
-
inline Action getCurrentAction() const¶
Returns last known action of the HVAC. If setAction method wasn’t called the initial value will be returned.
-
inline void setCurrentAuxState(const bool state)¶
Sets aux heating state without publishing it to Home Assistant. This method may be useful if you want to change the state before connection with MQTT broker is acquired.
- Parameters
state – The new state.
-
inline bool getCurrentAuxState() const¶
Returns last known state of the aux heating. If setAuxState method wasn’t called the initial value will be returned.
-
inline void setCurrentFanMode(const FanMode mode)¶
Sets fan’s mode of the HVAC without publishing it to Home Assistant. This method may be useful if you want to change the mode before connection with MQTT broker is acquired.
- Parameters
mode – New fan’s mode.
-
inline FanMode getCurrentFanMode() const¶
Returns last known fan’s mode of the HVAC. If setFanMode method wasn’t called the initial value will be returned.
-
inline void setFanModes(const uint8_t modes)¶
Sets available fan modes.
- Parameters
modes – The modes to set (for example:
HAHVAC::AutoFanMode | HAHVAC::HighFanMode
).
-
inline void setCurrentSwingMode(const SwingMode mode)¶
Sets swing mode of the HVAC without publishing it to Home Assistant. This method may be useful if you want to change the mode before connection with MQTT broker is acquired.
- Parameters
mode – New swing mode.
-
inline SwingMode getCurrentSwingMode() const¶
Returns last known swing mode of the HVAC. If setSwingMode method wasn’t called the initial value will be returned.
-
inline void setSwingModes(const uint8_t modes)¶
Sets available swing modes.
- Parameters
modes – The modes to set (for example:
HAHVAC::OnSwingMode
).
-
inline void setCurrentMode(const Mode mode)¶
Sets mode of the HVAC without publishing it to Home Assistant. This method may be useful if you want to change the mode before connection with MQTT broker is acquired.
- Parameters
mode – New HVAC’s mode.
-
inline Mode getCurrentMode() const¶
Returns last known mode of the HVAC. If setMode method wasn’t called the initial value will be returned.
-
inline void setModes(const uint8_t modes)¶
Sets available HVAC’s modes.
- Parameters
modes – The modes to set (for example:
HAHVAC::CoolMode | HAHVAC::HeatMode
).
-
inline void setCurrentTargetTemperature(const HANumeric &temperature)¶
Sets target temperature of the HVAC without publishing it to Home Assistant. This method may be useful if you want to change the target before connection with MQTT broker is acquired.
- Parameters
temperature – Target temperature to set.
-
inline void setCurrentTargetTemperature(const int8_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentTargetTemperature(const int16_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentTargetTemperature(const int32_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentTargetTemperature(const uint8_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentTargetTemperature(const uint16_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentTargetTemperature(const uint32_t temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline void setCurrentTargetTemperature(const float temperature)¶
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline const HANumeric &getCurrentTargetTemperature() const¶
Returns last known target temperature of the HVAC. If setTargetTemperature method wasn’t called the initial value will be returned.
-
inline void setIcon(const char *icon)¶
Sets icon of the HVAC. Any icon from MaterialDesignIcons.com (for example:
mdi:home
).- Parameters
icon – The icon name.
-
inline void setRetain(const bool retain)¶
Sets retain flag for the HVAC’s command. If set to
true
the command produced by Home Assistant will be retained.- Parameters
retain –
-
inline void setTemperatureUnit(TemperatureUnit unit)¶
Changes the temperature unit.
- Parameters
unit – See the TemperatureUnit enum above.
-
inline void setMinTemp(const float min)¶
Sets the minimum temperature that can be set from the Home Assistant panel.
- Parameters
min – The minimum value.
-
inline void setMaxTemp(const float max)¶
Sets the maximum temperature that can be set from the Home Assistant panel.
- Parameters
min – The maximum value.
-
inline void setTempStep(const float step)¶
Sets the step of the temperature that can be set from the Home Assistant panel.
- Parameters
step – The setp value. By default it’s
1
.
-
inline void onAuxStateCommand(void (*callback)(bool state, HAHVAC *sender))¶
Registers callback that will be called each time the aux state command from HA is received. Please note that it’s not possible to register multiple callbacks for the same HVAC.
Note
The aux state must be reported back to HA using the HAHVAC::setAuxState method.
- Parameters
callback –
-
inline void onPowerCommand(void (*callback)(bool state, HAHVAC *sender))¶
Registers callback that will be called each time the power command from HA is received. Please note that it’s not possible to register multiple callbacks for the same HVAC.
- Parameters
callback –
-
inline void onFanModeCommand(void (*callback)(FanMode mode, HAHVAC *sender))¶
Registers callback that will be called each time the fan mode command from HA is received. Please note that it’s not possible to register multiple callbacks for the same HVAC.
Note
The fan mode must be reported back to HA using the HAHVAC::setFanMode method.
- Parameters
callback –
-
inline void onSwingModeCommand(void (*callback)(SwingMode mode, HAHVAC *sender))¶
Registers callback that will be called each time the swing mode command from HA is received. Please note that it’s not possible to register multiple callbacks for the same HVAC.
Note
The swing mode must be reported back to HA using the HAHVAC::setSwingMode method.
- Parameters
callback –
-
inline void onModeCommand(void (*callback)(Mode mode, HAHVAC *sender))¶
Registers callback that will be called each time the HVAC mode command from HA is received. Please note that it’s not possible to register multiple callbacks for the same HVAC.
Note
The mode must be reported back to HA using the HAHVAC::setMode method.
- Parameters
callback –
-
inline void onTargetTemperatureCommand(void (*callback)(HANumeric temperature, HAHVAC *sender))¶
Registers callback that will be called each time the target temperature is set via HA panel. Please note that it’s not possible to register multiple callbacks for the same HVAC.
Note
The target temperature must be reported back to HA using the HAHVAC::setTargetTemperature method.
- Parameters
callback –
Public Static Attributes
-
static const uint8_t DefaultFanModes¶
-
static const uint8_t DefaultSwingModes¶
-
static const uint8_t DefaultModes¶
Protected Functions
-
virtual void buildSerializer() override¶
-
virtual void onMqttConnected() override¶
-
virtual void onMqttMessage(const char *topic, const uint8_t *payload, const uint16_t length) override¶
Private Functions
-
bool publishCurrentTemperature(const HANumeric &temperature)¶
Publishes the MQTT message with the given current temperature.
- Parameters
temperature – The temperature to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
bool publishAction(const Action action)¶
Publishes the MQTT message with the given action.
- Parameters
action – The action to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
bool publishAuxState(const bool state)¶
Publishes the MQTT message with the given aux heating state.
- Parameters
state – The state to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
bool publishFanMode(const FanMode mode)¶
Publishes the MQTT message with the given fan mode.
- Parameters
mode – The mode to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
bool publishSwingMode(const SwingMode mode)¶
Publishes the MQTT message with the given swing mode.
- Parameters
mode – The mode to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
bool publishMode(const Mode mode)¶
Publishes the MQTT message with the given mode.
- Parameters
mode – The mode to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
bool publishTargetTemperature(const HANumeric &temperature)¶
Publishes the MQTT message with the given target temperature.
- Parameters
temperature – The temperature to publish.
- Returns
Returns
true
if the MQTT message has been published successfully.
-
void handleAuxStateCommand(const uint8_t *cmd, const uint16_t length)¶
Parses the given aux state command and executes the callback with proper value.
- Parameters
cmd – The data of the command.
length – Length of the command.
-
void handlePowerCommand(const uint8_t *cmd, const uint16_t length)¶
Parses the given power command and executes the callback with proper value.
- Parameters
cmd – The data of the command.
length – Length of the command.
-
void handleFanModeCommand(const uint8_t *cmd, const uint16_t length)¶
Parses the given fan mode command and executes the callback with proper value.
- Parameters
cmd – The data of the command.
length – Length of the command.
-
void handleSwingModeCommand(const uint8_t *cmd, const uint16_t length)¶
Parses the given swing mode command and executes the callback with proper value.
- Parameters
cmd – The data of the command.
length – Length of the command.
-
void handleModeCommand(const uint8_t *cmd, const uint16_t length)¶
Parses the given HVAC’s mode command and executes the callback with proper value.
- Parameters
cmd – The data of the command.
length – Length of the command.
-
void handleTargetTemperatureCommand(const uint8_t *cmd, const uint16_t length)¶
Parses the given HVAC’s target temperature command and executes the callback with proper value.
- Parameters
cmd – The data of the command.
length – Length of the command.
-
const __FlashStringHelper *getCommandWithFloatTemplate()¶
Returns progmem string representing value template for the command that contains floating point numbers.
Private Members
-
const uint16_t _features¶
Features enabled for the HVAC.
-
const NumberPrecision _precision¶
The precision of temperatures. By default it’s
HANumber::PrecisionP1
.
-
const char *_icon¶
The icon of the button. It can be nullptr.
-
bool _retain¶
The retain flag for the HA commands.
-
TemperatureUnit _temperatureUnit¶
The temperature unit for the HVAC. By default it’s
HAHVAC::DefaultUnit
.
-
void (*_auxCallback)(bool state, HAHVAC *sender)¶
Callback that will be called when the aux state command is received from the HA.
-
bool _auxState¶
The state of the aux heating. By default it’s
false
.
-
void (*_powerCallback)(bool state, HAHVAC *sender)¶
Callback that will be called when the power command is received from the HA.
-
uint8_t _fanModes¶
The supported fan modes. By default it’s
HAHVAC::DefaultFanModes
.
-
HASerializerArray *_fanModesSerializer¶
The serializer for the fan modes. It’s
nullptr
if the fan feature is disabled.
-
void (*_fanModeCallback)(FanMode mode, HAHVAC *sender)¶
Callback that will be called when the fan mode command is received from the HA.
-
uint8_t _swingModes¶
The supported swing modes. By default it’s
HAHVAC::DefaultSwingModes
.
-
HASerializerArray *_swingModesSerializer¶
The serializer for the swing modes. It’s
nullptr
if the swing feature is disabled.
-
void (*_swingModeCallback)(SwingMode mode, HAHVAC *sender)¶
Callback that will be called when the swing mode command is received from the HA.
-
uint8_t _modes¶
The supported modes. By default it’s
HAHVAC::DefaultModes
.
-
HASerializerArray *_modesSerializer¶
The serializer for the modes. It’s
nullptr
if the modes feature is disabled.
-
enum Features¶