12static const char *
const TAG =
"mqtt.climate";
17PROGMEM_STRING_TABLE(ClimateMqttModeStrings,
"off",
"heat_cool",
"cool",
"heat",
"fan_only",
"dry",
"auto",
"unknown");
20 return ClimateMqttModeStrings::get_progmem_str(
static_cast<uint8_t
>(
mode), ClimateMqttModeStrings::LAST_INDEX);
25PROGMEM_STRING_TABLE(ClimateMqttActionStrings,
"off",
"unknown",
"cooling",
"heating",
"idle",
"drying",
"fan",
26 "defrosting",
"unknown");
29 return ClimateMqttActionStrings::get_progmem_str(
static_cast<uint8_t
>(action), ClimateMqttActionStrings::LAST_INDEX);
33PROGMEM_STRING_TABLE(ClimateMqttFanModeStrings,
"on",
"off",
"auto",
"low",
"medium",
"high",
"middle",
"focus",
34 "diffuse",
"quiet",
"unknown");
37 return ClimateMqttFanModeStrings::get_progmem_str(
static_cast<uint8_t
>(
fan_mode),
38 ClimateMqttFanModeStrings::LAST_INDEX);
45 return ClimateMqttSwingModeStrings::get_progmem_str(
static_cast<uint8_t
>(
swing_mode),
46 ClimateMqttSwingModeStrings::LAST_INDEX);
50PROGMEM_STRING_TABLE(ClimateMqttPresetStrings,
"none",
"home",
"away",
"boost",
"comfort",
"eco",
"sleep",
"activity",
54 return ClimateMqttPresetStrings::get_progmem_str(
static_cast<uint8_t
>(
preset), ClimateMqttPresetStrings::LAST_INDEX);
62 root[MQTT_CURRENT_TEMPERATURE_TOPIC] = this->get_current_temperature_state_topic();
66 root[MQTT_CURRENT_HUMIDITY_TOPIC] = this->get_current_humidity_state_topic();
69 root[MQTT_MODE_COMMAND_TOPIC] = this->get_mode_command_topic();
71 root[MQTT_MODE_STATE_TOPIC] = this->get_mode_state_topic();
73 JsonArray modes = root[MQTT_MODES].to<JsonArray>();
76 modes.add(ESPHOME_F(
"auto"));
77 modes.add(ESPHOME_F(
"off"));
79 modes.add(ESPHOME_F(
"cool"));
81 modes.add(ESPHOME_F(
"heat"));
83 modes.add(ESPHOME_F(
"fan_only"));
85 modes.add(ESPHOME_F(
"dry"));
87 modes.add(ESPHOME_F(
"heat_cool"));
92 root[MQTT_TEMPERATURE_LOW_COMMAND_TOPIC] = this->get_target_temperature_low_command_topic();
94 root[MQTT_TEMPERATURE_LOW_STATE_TOPIC] = this->get_target_temperature_low_state_topic();
96 root[MQTT_TEMPERATURE_HIGH_COMMAND_TOPIC] = this->get_target_temperature_high_command_topic();
98 root[MQTT_TEMPERATURE_HIGH_STATE_TOPIC] = this->get_target_temperature_high_state_topic();
101 root[MQTT_TEMPERATURE_COMMAND_TOPIC] = this->get_target_temperature_command_topic();
103 root[MQTT_TEMPERATURE_STATE_TOPIC] = this->get_target_temperature_state_topic();
108 root[MQTT_TARGET_HUMIDITY_COMMAND_TOPIC] = this->get_target_humidity_command_topic();
110 root[MQTT_TARGET_HUMIDITY_STATE_TOPIC] = this->get_target_humidity_state_topic();
114 root[MQTT_MIN_TEMP] = traits.get_visual_min_temperature();
116 root[MQTT_MAX_TEMP] = traits.get_visual_max_temperature();
118 root[MQTT_TARGET_TEMPERATURE_STEP] = roundf(traits.get_visual_target_temperature_step() * 10) * 0.1;
120 root[MQTT_CURRENT_TEMPERATURE_STEP] = roundf(traits.get_visual_current_temperature_step() * 10) * 0.1;
122 root[MQTT_TEMPERATURE_UNIT] =
"C";
125 root[MQTT_MIN_HUMIDITY] = traits.get_visual_min_humidity();
127 root[MQTT_MAX_HUMIDITY] = traits.get_visual_max_humidity();
129 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
131 root[MQTT_PRESET_MODE_COMMAND_TOPIC] = this->get_preset_command_topic();
133 root[MQTT_PRESET_MODE_STATE_TOPIC] = this->get_preset_state_topic();
135 JsonArray presets = root[ESPHOME_F(
"preset_modes")].to<JsonArray>();
137 presets.add(ESPHOME_F(
"home"));
139 presets.add(ESPHOME_F(
"away"));
141 presets.add(ESPHOME_F(
"boost"));
143 presets.add(ESPHOME_F(
"comfort"));
145 presets.add(ESPHOME_F(
"eco"));
147 presets.add(ESPHOME_F(
"sleep"));
149 presets.add(ESPHOME_F(
"activity"));
150 for (
const auto &
preset : traits.get_supported_custom_presets())
156 root[MQTT_ACTION_TOPIC] = this->get_action_state_topic();
159 if (traits.get_supports_fan_modes()) {
161 root[MQTT_FAN_MODE_COMMAND_TOPIC] = this->get_fan_mode_command_topic();
163 root[MQTT_FAN_MODE_STATE_TOPIC] = this->get_fan_mode_state_topic();
165 JsonArray fan_modes = root[ESPHOME_F(
"fan_modes")].to<JsonArray>();
167 fan_modes.add(ESPHOME_F(
"on"));
169 fan_modes.add(ESPHOME_F(
"off"));
171 fan_modes.add(ESPHOME_F(
"auto"));
173 fan_modes.add(ESPHOME_F(
"low"));
175 fan_modes.add(ESPHOME_F(
"medium"));
177 fan_modes.add(ESPHOME_F(
"high"));
179 fan_modes.add(ESPHOME_F(
"middle"));
181 fan_modes.add(ESPHOME_F(
"focus"));
183 fan_modes.add(ESPHOME_F(
"diffuse"));
185 fan_modes.add(ESPHOME_F(
"quiet"));
186 for (
const auto &
fan_mode : traits.get_supported_custom_fan_modes())
190 if (traits.get_supports_swing_modes()) {
192 root[MQTT_SWING_MODE_COMMAND_TOPIC] = this->get_swing_mode_command_topic();
194 root[MQTT_SWING_MODE_STATE_TOPIC] = this->get_swing_mode_state_topic();
196 JsonArray swing_modes = root[ESPHOME_F(
"swing_modes")].to<JsonArray>();
198 swing_modes.add(ESPHOME_F(
"off"));
200 swing_modes.add(ESPHOME_F(
"both"));
202 swing_modes.add(ESPHOME_F(
"vertical"));
204 swing_modes.add(ESPHOME_F(
"horizontal"));
213 this->
subscribe(this->get_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
221 this->
subscribe(this->get_target_temperature_low_command_topic(),
222 [
this](
const std::string &topic,
const std::string &payload) {
224 if (!
val.has_value()) {
225 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
232 this->
subscribe(this->get_target_temperature_high_command_topic(),
233 [
this](
const std::string &topic,
const std::string &payload) {
235 if (!
val.has_value()) {
236 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
244 this->
subscribe(this->get_target_temperature_command_topic(),
245 [
this](
const std::string &topic,
const std::string &payload) {
247 if (!
val.has_value()) {
248 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
258 this->
subscribe(this->get_target_humidity_command_topic(),
259 [
this](
const std::string &topic,
const std::string &payload) {
261 if (!
val.has_value()) {
262 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
271 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
272 this->
subscribe(this->get_preset_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
279 if (traits.get_supports_fan_modes()) {
280 this->
subscribe(this->get_fan_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
287 if (traits.get_supports_swing_modes()) {
288 this->
subscribe(this->get_swing_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
305 char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN];
308 if (!this->
publish(this->get_mode_state_topic_to(topic_buf), climate_mode_to_mqtt_str(this->
device_->
mode)))
311 int8_t current_accuracy = traits.get_current_temperature_accuracy_decimals();
312 char payload[VALUE_ACCURACY_MAX_LEN];
315 !std::isnan(this->device_->current_temperature)) {
317 if (!this->
publish(this->get_current_temperature_state_topic_to(topic_buf), payload,
len))
323 if (!this->
publish(this->get_target_temperature_low_state_topic_to(topic_buf), payload,
len))
326 if (!this->
publish(this->get_target_temperature_high_state_topic_to(topic_buf), payload,
len))
330 if (!this->
publish(this->get_target_temperature_state_topic_to(topic_buf), payload,
len))
335 !std::isnan(this->device_->current_humidity)) {
337 if (!this->
publish(this->get_current_humidity_state_topic_to(topic_buf), payload,
len))
341 !std::isnan(this->device_->target_humidity)) {
343 if (!this->
publish(this->get_target_humidity_state_topic_to(topic_buf), payload,
len))
347 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
352 if (!this->
publish(this->get_preset_state_topic_to(topic_buf),
355 }
else if (!this->
publish(this->get_preset_state_topic_to(topic_buf),
"")) {
361 if (!this->
publish(this->get_action_state_topic_to(topic_buf), climate_action_to_mqtt_str(this->
device_->
action)))
365 if (traits.get_supports_fan_modes()) {
370 if (!this->
publish(this->get_fan_mode_state_topic_to(topic_buf),
373 }
else if (!this->
publish(this->get_fan_mode_state_topic_to(topic_buf),
"")) {
378 if (traits.get_supports_swing_modes()) {
379 if (!this->
publish(this->get_swing_mode_state_topic_to(topic_buf),
BedjetMode mode
BedJet operating mode.
constexpr const char * c_str() const
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.
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...
bool has_custom_preset() const
Check if a custom preset is currently active.
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...
StringRef get_custom_preset() const
Get the active custom preset (read-only access). Returns StringRef.
bool has_custom_fan_mode() const
Check if a custom fan mode is currently active.
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...
StringRef get_custom_fan_mode() const
Get the active custom fan mode (read-only access). Returns StringRef.
int8_t get_target_temperature_accuracy_decimals() const
MQTTClimateComponent(climate::Climate *device)
state command command command command command command state state state MQTT_COMPONENT_CUSTOM_TOPIC(preset, command) protected bool publish_state_()
climate::Climate * device_
bool send_initial_state() override
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to a MQTT topic.
value_type const & value() const
ClimateSwingMode swing_mode
PROGMEM_STRING_TABLE(AlarmControlPanelStateStrings, "DISARMED", "ARMED_HOME", "ARMED_AWAY", "ARMED_NIGHT", "ARMED_VACATION", "ARMED_CUSTOM_BYPASS", "PENDING", "ARMING", "DISARMING", "TRIGGERED", "UNKNOWN")
@ CLIMATE_SUPPORTS_CURRENT_HUMIDITY
@ CLIMATE_SUPPORTS_TARGET_HUMIDITY
@ CLIMATE_SUPPORTS_TWO_POINT_TARGET_TEMPERATURE
@ CLIMATE_SUPPORTS_CURRENT_TEMPERATURE
@ CLIMATE_SUPPORTS_ACTION
@ CLIMATE_REQUIRES_TWO_POINT_TARGET_TEMPERATURE
ClimatePreset
Enum for all preset modes NOTE: If adding values, update ClimatePresetMask in climate_traits....
@ 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.
ClimateSwingMode
Enum for all modes a climate swing can be in NOTE: If adding values, update ClimateSwingModeMask in c...
@ 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.
ClimateMode
Enum for all modes a climate device can be in.
@ 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_AUTO
The climate device is adjusting the temperature dynamically.
ClimateAction
Enum for the current action of the climate device. Values match those of ClimateMode.
ClimateFanMode
NOTE: If adding values, update ClimateFanModeMask in climate_traits.h to use the new last value.
@ 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.
MQTT_COMPONENT_TYPE(MQTTAlarmControlPanelComponent, "alarm_control_panel") const EntityBase *MQTTAlarmControlPanelComponent
size_t value_accuracy_to_buf(std::span< char, VALUE_ACCURACY_MAX_LEN > buf, float value, int8_t accuracy_decimals)
Format value with accuracy to buffer, returns chars written (excluding null)
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
const __FlashStringHelper * ProgmemStr
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.