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);
24PROGMEM_STRING_TABLE(ClimateMqttActionStrings,
"off",
"unknown",
"cooling",
"heating",
"idle",
"drying",
"fan",
28 return ClimateMqttActionStrings::get_progmem_str(
static_cast<uint8_t
>(action), ClimateMqttActionStrings::LAST_INDEX);
32PROGMEM_STRING_TABLE(ClimateMqttFanModeStrings,
"on",
"off",
"auto",
"low",
"medium",
"high",
"middle",
"focus",
33 "diffuse",
"quiet",
"unknown");
36 return ClimateMqttFanModeStrings::get_progmem_str(
static_cast<uint8_t
>(
fan_mode),
37 ClimateMqttFanModeStrings::LAST_INDEX);
44 return ClimateMqttSwingModeStrings::get_progmem_str(
static_cast<uint8_t
>(
swing_mode),
45 ClimateMqttSwingModeStrings::LAST_INDEX);
49PROGMEM_STRING_TABLE(ClimateMqttPresetStrings,
"none",
"home",
"away",
"boost",
"comfort",
"eco",
"sleep",
"activity",
53 return ClimateMqttPresetStrings::get_progmem_str(
static_cast<uint8_t
>(
preset), ClimateMqttPresetStrings::LAST_INDEX);
61 root[MQTT_CURRENT_TEMPERATURE_TOPIC] = this->get_current_temperature_state_topic();
65 root[MQTT_CURRENT_HUMIDITY_TOPIC] = this->get_current_humidity_state_topic();
68 root[MQTT_MODE_COMMAND_TOPIC] = this->get_mode_command_topic();
70 root[MQTT_MODE_STATE_TOPIC] = this->get_mode_state_topic();
72 JsonArray modes = root[MQTT_MODES].to<JsonArray>();
75 modes.add(ESPHOME_F(
"auto"));
76 modes.add(ESPHOME_F(
"off"));
78 modes.add(ESPHOME_F(
"cool"));
80 modes.add(ESPHOME_F(
"heat"));
82 modes.add(ESPHOME_F(
"fan_only"));
84 modes.add(ESPHOME_F(
"dry"));
86 modes.add(ESPHOME_F(
"heat_cool"));
91 root[MQTT_TEMPERATURE_LOW_COMMAND_TOPIC] = this->get_target_temperature_low_command_topic();
93 root[MQTT_TEMPERATURE_LOW_STATE_TOPIC] = this->get_target_temperature_low_state_topic();
95 root[MQTT_TEMPERATURE_HIGH_COMMAND_TOPIC] = this->get_target_temperature_high_command_topic();
97 root[MQTT_TEMPERATURE_HIGH_STATE_TOPIC] = this->get_target_temperature_high_state_topic();
100 root[MQTT_TEMPERATURE_COMMAND_TOPIC] = this->get_target_temperature_command_topic();
102 root[MQTT_TEMPERATURE_STATE_TOPIC] = this->get_target_temperature_state_topic();
107 root[MQTT_TARGET_HUMIDITY_COMMAND_TOPIC] = this->get_target_humidity_command_topic();
109 root[MQTT_TARGET_HUMIDITY_STATE_TOPIC] = this->get_target_humidity_state_topic();
113 root[MQTT_MIN_TEMP] = traits.get_visual_min_temperature();
115 root[MQTT_MAX_TEMP] = traits.get_visual_max_temperature();
117 root[MQTT_TARGET_TEMPERATURE_STEP] = roundf(traits.get_visual_target_temperature_step() * 10) * 0.1;
119 root[MQTT_CURRENT_TEMPERATURE_STEP] = roundf(traits.get_visual_current_temperature_step() * 10) * 0.1;
121 root[MQTT_TEMPERATURE_UNIT] =
"C";
124 root[MQTT_MIN_HUMIDITY] = traits.get_visual_min_humidity();
126 root[MQTT_MAX_HUMIDITY] = traits.get_visual_max_humidity();
128 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
130 root[MQTT_PRESET_MODE_COMMAND_TOPIC] = this->get_preset_command_topic();
132 root[MQTT_PRESET_MODE_STATE_TOPIC] = this->get_preset_state_topic();
134 JsonArray presets = root[ESPHOME_F(
"preset_modes")].to<JsonArray>();
136 presets.add(ESPHOME_F(
"home"));
138 presets.add(ESPHOME_F(
"away"));
140 presets.add(ESPHOME_F(
"boost"));
142 presets.add(ESPHOME_F(
"comfort"));
144 presets.add(ESPHOME_F(
"eco"));
146 presets.add(ESPHOME_F(
"sleep"));
148 presets.add(ESPHOME_F(
"activity"));
149 for (
const auto &
preset : traits.get_supported_custom_presets())
155 root[MQTT_ACTION_TOPIC] = this->get_action_state_topic();
158 if (traits.get_supports_fan_modes()) {
160 root[MQTT_FAN_MODE_COMMAND_TOPIC] = this->get_fan_mode_command_topic();
162 root[MQTT_FAN_MODE_STATE_TOPIC] = this->get_fan_mode_state_topic();
164 JsonArray fan_modes = root[ESPHOME_F(
"fan_modes")].to<JsonArray>();
166 fan_modes.add(ESPHOME_F(
"on"));
168 fan_modes.add(ESPHOME_F(
"off"));
170 fan_modes.add(ESPHOME_F(
"auto"));
172 fan_modes.add(ESPHOME_F(
"low"));
174 fan_modes.add(ESPHOME_F(
"medium"));
176 fan_modes.add(ESPHOME_F(
"high"));
178 fan_modes.add(ESPHOME_F(
"middle"));
180 fan_modes.add(ESPHOME_F(
"focus"));
182 fan_modes.add(ESPHOME_F(
"diffuse"));
184 fan_modes.add(ESPHOME_F(
"quiet"));
185 for (
const auto &
fan_mode : traits.get_supported_custom_fan_modes())
189 if (traits.get_supports_swing_modes()) {
191 root[MQTT_SWING_MODE_COMMAND_TOPIC] = this->get_swing_mode_command_topic();
193 root[MQTT_SWING_MODE_STATE_TOPIC] = this->get_swing_mode_state_topic();
195 JsonArray swing_modes = root[ESPHOME_F(
"swing_modes")].to<JsonArray>();
197 swing_modes.add(ESPHOME_F(
"off"));
199 swing_modes.add(ESPHOME_F(
"both"));
201 swing_modes.add(ESPHOME_F(
"vertical"));
203 swing_modes.add(ESPHOME_F(
"horizontal"));
212 this->
subscribe(this->get_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
220 this->
subscribe(this->get_target_temperature_low_command_topic(),
221 [
this](
const std::string &topic,
const std::string &payload) {
223 if (!
val.has_value()) {
224 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
231 this->
subscribe(this->get_target_temperature_high_command_topic(),
232 [
this](
const std::string &topic,
const std::string &payload) {
234 if (!
val.has_value()) {
235 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
243 this->
subscribe(this->get_target_temperature_command_topic(),
244 [
this](
const std::string &topic,
const std::string &payload) {
246 if (!
val.has_value()) {
247 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
257 this->
subscribe(this->get_target_humidity_command_topic(),
258 [
this](
const std::string &topic,
const std::string &payload) {
260 if (!
val.has_value()) {
261 ESP_LOGW(TAG,
"Can't convert '%s' to number!", payload.c_str());
270 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
271 this->
subscribe(this->get_preset_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
278 if (traits.get_supports_fan_modes()) {
279 this->
subscribe(this->get_fan_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
286 if (traits.get_supports_swing_modes()) {
287 this->
subscribe(this->get_swing_mode_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
304 char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN];
307 if (!this->
publish(this->get_mode_state_topic_to(topic_buf), climate_mode_to_mqtt_str(this->
device_->
mode)))
310 int8_t current_accuracy = traits.get_current_temperature_accuracy_decimals();
311 char payload[VALUE_ACCURACY_MAX_LEN];
314 !std::isnan(this->device_->current_temperature)) {
316 if (!this->
publish(this->get_current_temperature_state_topic_to(topic_buf), payload,
len))
322 if (!this->
publish(this->get_target_temperature_low_state_topic_to(topic_buf), payload,
len))
325 if (!this->
publish(this->get_target_temperature_high_state_topic_to(topic_buf), payload,
len))
329 if (!this->
publish(this->get_target_temperature_state_topic_to(topic_buf), payload,
len))
334 !std::isnan(this->device_->current_humidity)) {
336 if (!this->
publish(this->get_current_humidity_state_topic_to(topic_buf), payload,
len))
340 !std::isnan(this->device_->target_humidity)) {
342 if (!this->
publish(this->get_target_humidity_state_topic_to(topic_buf), payload,
len))
346 if (traits.get_supports_presets() || !traits.get_supported_custom_presets().empty()) {
351 if (!this->
publish(this->get_preset_state_topic_to(topic_buf),
354 }
else if (!this->
publish(this->get_preset_state_topic_to(topic_buf),
"")) {
360 if (!this->
publish(this->get_action_state_topic_to(topic_buf), climate_action_to_mqtt_str(this->
device_->
action)))
364 if (traits.get_supports_fan_modes()) {
369 if (!this->
publish(this->get_fan_mode_state_topic_to(topic_buf),
372 }
else if (!this->
publish(this->get_fan_mode_state_topic_to(topic_buf),
"")) {
377 if (traits.get_supports_swing_modes()) {
378 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.