12static const char *
const TAG =
"mqtt.climate";
19 if (traits.get_supports_current_temperature()) {
23 if (traits.get_supports_current_humidity()) {
31 JsonArray modes = root.createNestedArray(
MQTT_MODES);
41 modes.add(
"fan_only");
45 modes.add(
"heat_cool");
47 if (traits.get_supports_two_point_target_temperature()) {
63 if (traits.get_supports_target_humidity()) {
86 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
92 JsonArray presets = root.createNestedArray(
"preset_modes");
100 presets.add(
"comfort");
104 presets.add(
"sleep");
106 presets.add(
"activity");
107 for (
const auto &
preset : traits.get_supported_custom_presets())
111 if (traits.get_supports_action()) {
116 if (traits.get_supports_fan_modes()) {
122 JsonArray fan_modes = root.createNestedArray(
"fan_modes");
126 fan_modes.add(
"off");
128 fan_modes.add(
"auto");
130 fan_modes.add(
"low");
132 fan_modes.add(
"medium");
134 fan_modes.add(
"high");
136 fan_modes.add(
"middle");
138 fan_modes.add(
"focus");
140 fan_modes.add(
"diffuse");
142 fan_modes.add(
"quiet");
143 for (
const auto &
fan_mode : traits.get_supported_custom_fan_modes())
147 if (traits.get_supports_swing_modes()) {
153 JsonArray swing_modes = root.createNestedArray(
"swing_modes");
155 swing_modes.add(
"off");
157 swing_modes.add(
"both");
159 swing_modes.add(
"vertical");
161 swing_modes.add(
"horizontal");
169 this->
subscribe(this->get_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
175 if (traits.get_supports_two_point_target_temperature()) {
176 this->
subscribe(this->get_target_temperature_low_command_topic(),
177 [
this](
const std::string &topic,
const std::string &payload) {
179 if (!
val.has_value()) {
180 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
187 this->
subscribe(this->get_target_temperature_high_command_topic(),
188 [
this](
const std::string &topic,
const std::string &payload) {
190 if (!
val.has_value()) {
191 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
199 this->
subscribe(this->get_target_temperature_command_topic(),
200 [
this](
const std::string &topic,
const std::string &payload) {
202 if (!
val.has_value()) {
203 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
212 if (traits.get_supports_target_humidity()) {
213 this->
subscribe(this->get_target_humidity_command_topic(),
214 [
this](
const std::string &topic,
const std::string &payload) {
216 if (!
val.has_value()) {
217 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
226 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
227 this->
subscribe(this->get_preset_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
234 if (traits.get_supports_fan_modes()) {
235 this->
subscribe(this->get_fan_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
242 if (traits.get_supports_swing_modes()) {
243 this->
subscribe(this->get_swing_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
281 mode_s =
"heat_cool";
287 if (!this->
publish(this->get_mode_state_topic(), mode_s))
290 int8_t current_accuracy = traits.get_current_temperature_accuracy_decimals();
291 if (traits.get_supports_current_temperature() && !std::isnan(this->device_->current_temperature)) {
293 if (!this->
publish(this->get_current_temperature_state_topic(), payload))
296 if (traits.get_supports_two_point_target_temperature()) {
298 if (!this->
publish(this->get_target_temperature_low_state_topic(), payload))
301 if (!this->
publish(this->get_target_temperature_high_state_topic(), payload))
305 if (!this->
publish(this->get_target_temperature_state_topic(), payload))
309 if (traits.get_supports_current_humidity() && !std::isnan(this->device_->current_humidity)) {
311 if (!this->
publish(this->get_current_humidity_state_topic(), payload))
314 if (traits.get_supports_target_humidity() && !std::isnan(this->device_->target_humidity)) {
316 if (!this->
publish(this->get_target_humidity_state_topic(), payload))
320 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
346 payload =
"activity";
354 if (!this->
publish(this->get_preset_state_topic(), payload))
358 if (traits.get_supports_action()) {
382 if (!this->
publish(this->get_action_state_topic(), payload))
386 if (traits.get_supports_fan_modes()) {
426 if (!this->
publish(this->get_fan_mode_state_topic(), payload))
430 if (traits.get_supports_swing_modes()) {
440 payload =
"vertical";
443 payload =
"horizontal";
448 if (!this->
publish(this->get_swing_mode_state_topic(), payload))
ClimateCall & set_target_temperature(float target_temperature)
Set the target temperature of the climate device.
ClimateCall & set_swing_mode(ClimateSwingMode swing_mode)
Set the swing mode of the climate device.
ClimateCall & set_target_temperature_low(float target_temperature_low)
Set the low point target temperature of the climate device.
ClimateCall & set_preset(ClimatePreset preset)
Set the preset of the climate device.
ClimateCall & set_fan_mode(ClimateFanMode fan_mode)
Set the fan mode of the climate device.
ClimateCall & set_target_humidity(float target_humidity)
Set the target humidity of the climate device.
ClimateCall & set_target_temperature_high(float target_temperature_high)
Set the high point target temperature of the climate device.
ClimateCall & set_mode(ClimateMode mode)
Set the mode of the climate device.
ClimateDevice - This is the base class for all climate integrations.
ClimateMode mode
The active mode of the climate device.
optional< ClimateFanMode > fan_mode
The active fan mode of the climate device.
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
float target_temperature
The target temperature of the climate device.
float current_humidity
The current humidity of the climate device, as reported from the integration.
optional< std::string > custom_fan_mode
The active custom fan mode of the climate device.
ClimateSwingMode swing_mode
The active swing mode of the climate device.
float target_temperature_low
The minimum target temperature of the climate device, for climate devices with split target temperatu...
void add_on_state_callback(std::function< void(Climate &)> &&callback)
Add a callback for the climate device state, each time the state of the climate device is updated (us...
optional< std::string > custom_preset
The active custom preset mode of the climate device.
float current_temperature
The current temperature of the climate device, as reported from the integration.
ClimateAction action
The active state of the climate device.
ClimateCall make_call()
Make a climate device control call, this is used to control the climate device, see the ClimateCall d...
optional< ClimatePreset > preset
The active preset of the climate device.
float target_humidity
The target humidity of the climate device.
float target_temperature_high
The maximum target temperature of the climate device, for climate devices with split target temperatu...
int8_t get_target_temperature_accuracy_decimals() const
MQTTClimateComponent(climate::Climate *device)
climate::Climate * device_
bool send_initial_state() override
state command command command command command command state state state MQTT_COMPONENT_CUSTOM_TOPIC(preset, command) protected bool publish_state_()
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
std::string component_type() const override
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
virtual const EntityBase * get_entity() const =0
Gets the Entity served by this MQTT component.
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to a MQTT topic.
value_type const & value() const
@ CLIMATE_PRESET_NONE
No preset is active.
@ CLIMATE_PRESET_COMFORT
Device is in comfort preset.
@ CLIMATE_PRESET_AWAY
Device is in away preset.
@ CLIMATE_PRESET_BOOST
Device is in boost preset.
@ CLIMATE_PRESET_ACTIVITY
Device is reacting to activity (e.g., movement sensors)
@ CLIMATE_PRESET_SLEEP
Device is prepared for sleep.
@ CLIMATE_PRESET_HOME
Device is in home preset.
@ CLIMATE_PRESET_ECO
Device is running an energy-saving preset.
@ CLIMATE_SWING_OFF
The swing mode is set to Off.
@ CLIMATE_SWING_HORIZONTAL
The fan mode is set to Horizontal.
@ CLIMATE_SWING_VERTICAL
The fan mode is set to Vertical.
@ CLIMATE_SWING_BOTH
The fan mode is set to Both.
@ CLIMATE_MODE_DRY
The climate device is set to dry/humidity mode.
@ CLIMATE_MODE_FAN_ONLY
The climate device only has the fan enabled, no heating or cooling is taking place.
@ CLIMATE_MODE_HEAT
The climate device is set to heat to reach the target temperature.
@ CLIMATE_MODE_COOL
The climate device is set to cool to reach the target temperature.
@ CLIMATE_MODE_HEAT_COOL
The climate device is set to heat/cool to reach the target temperature.
@ CLIMATE_MODE_OFF
The climate device is off.
@ CLIMATE_MODE_AUTO
The climate device is adjusting the temperature dynamically.
@ CLIMATE_ACTION_OFF
The climate device is off (inactive or no power)
@ CLIMATE_ACTION_IDLE
The climate device is idle (monitoring climate but no action needed)
@ CLIMATE_ACTION_DRYING
The climate device is drying.
@ CLIMATE_ACTION_HEATING
The climate device is actively heating.
@ CLIMATE_ACTION_COOLING
The climate device is actively cooling.
@ CLIMATE_ACTION_FAN
The climate device is in fan only mode.
@ CLIMATE_FAN_MEDIUM
The fan mode is set to Medium.
@ CLIMATE_FAN_DIFFUSE
The fan mode is set to Diffuse.
@ CLIMATE_FAN_ON
The fan mode is set to On.
@ CLIMATE_FAN_AUTO
The fan mode is set to Auto.
@ CLIMATE_FAN_FOCUS
The fan mode is set to Focus.
@ CLIMATE_FAN_LOW
The fan mode is set to Low.
@ CLIMATE_FAN_MIDDLE
The fan mode is set to Middle.
@ CLIMATE_FAN_QUIET
The fan mode is set to Quiet.
@ CLIMATE_FAN_OFF
The fan mode is set to Off.
@ CLIMATE_FAN_HIGH
The fan mode is set to High.
constexpr const char *const MQTT_TEMPERATURE_HIGH_COMMAND_TOPIC
constexpr const char *const MQTT_TEMPERATURE_LOW_COMMAND_TOPIC
constexpr const char *const MQTT_CURRENT_TEMPERATURE_TOPIC
constexpr const char *const MQTT_TEMPERATURE_STATE_TOPIC
constexpr const char *const MQTT_TARGET_HUMIDITY_STATE_TOPIC
constexpr const char *const MQTT_MIN_HUMIDITY
constexpr const char *const MQTT_TEMPERATURE_COMMAND_TOPIC
constexpr const char *const MQTT_SWING_MODE_STATE_TOPIC
constexpr const char *const MQTT_CURRENT_HUMIDITY_TOPIC
constexpr const char *const MQTT_TEMPERATURE_UNIT
constexpr const char *const MQTT_TARGET_HUMIDITY_COMMAND_TOPIC
constexpr const char *const MQTT_MIN_TEMP
constexpr const char *const MQTT_FAN_MODE_STATE_TOPIC
constexpr const char *const MQTT_TARGET_TEMPERATURE_STEP
constexpr const char *const MQTT_PRESET_MODE_STATE_TOPIC
constexpr const char *const MQTT_TEMPERATURE_LOW_STATE_TOPIC
constexpr const char *const MQTT_TEMPERATURE_HIGH_STATE_TOPIC
constexpr const char *const MQTT_CURRENT_TEMPERATURE_STEP
constexpr const char *const MQTT_ACTION_TOPIC
constexpr const char *const MQTT_FAN_MODE_COMMAND_TOPIC
constexpr const char *const MQTT_PRESET_MODE_COMMAND_TOPIC
constexpr const char *const MQTT_MAX_HUMIDITY
constexpr const char *const MQTT_MODE_STATE_TOPIC
constexpr const char *const MQTT_MAX_TEMP
constexpr const char *const MQTT_MODES
constexpr const char *const MQTT_MODE_COMMAND_TOPIC
constexpr const char *const MQTT_SWING_MODE_COMMAND_TOPIC
Providing packet encoding functions for exchanging data with a remote host.
std::string value_accuracy_to_string(float value, int8_t accuracy_decimals)
Create a string from a value and an accuracy in decimals.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Simple Helper struct used for Home Assistant MQTT send_discovery().
bool command_topic
If the command topic should be included. Default to true.
bool state_topic
If the state topic should be included. Defaults to true.