ESPHome 2026.2.1
Loading...
Searching...
No Matches
esphome::mqtt Namespace Reference

Data Structures

struct  Availability
 Simple data struct for Home Assistant component availability. More...
 
class  CustomMQTTDevice
 This class is a helper class for custom components that communicate using MQTT. More...
 
struct  Event
 
class  MQTTAlarmControlPanelComponent
 
class  MQTTBackend
 
class  MQTTBackendESP32
 
class  MQTTBackendESP8266
 
class  MQTTBackendLibreTiny
 
class  MQTTBinarySensorComponent
 
class  MQTTButtonComponent
 
class  MQTTClientComponent
 
class  MQTTClimateComponent
 
class  MQTTComponent
 MQTTComponent is the base class for all components that interact with MQTT to expose certain functionality or data from actuators or sensors to clients. More...
 
class  MQTTConnectedCondition
 
class  MQTTConnectTrigger
 
class  MQTTCoverComponent
 
struct  MQTTCredentials
 internal struct for MQTT credentials. More...
 
class  MQTTDateComponent
 
class  MQTTDateTimeComponent
 
class  MQTTDisableAction
 
class  MQTTDisconnectTrigger
 
struct  MQTTDiscoveryInfo
 Internal struct for MQTT Home Assistant discovery. More...
 
class  MQTTEnableAction
 
class  MQTTEventComponent
 
class  MQTTFanComponent
 
class  MQTTJSONLightComponent
 
class  MQTTJsonMessageTrigger
 
class  MQTTLockComponent
 
struct  MQTTMessage
 internal struct for MQTT messages. More...
 
class  MQTTMessageTrigger
 
class  MQTTNumberComponent
 
class  MQTTPublishAction
 
class  MQTTPublishJsonAction
 
class  MQTTSelectComponent
 
class  MQTTSensorComponent
 
struct  MQTTSubscription
 internal struct for MQTT subscriptions. More...
 
class  MQTTSwitchComponent
 
class  MQTTTextComponent
 
class  MQTTTextSensor
 
class  MQTTTimeComponent
 
class  MQTTUpdateComponent
 
class  MQTTValveComponent
 
struct  QueueElement
 
struct  SendDiscoveryConfig
 Simple Helper struct used for Home Assistant MQTT send_discovery(). More...
 

Typedefs

using mqtt_on_connect_callback_t = std::function<MQTTBackend::on_connect_callback_t>
 Callback for MQTT events.
 
using mqtt_on_disconnect_callback_t = std::function<MQTTBackend::on_disconnect_callback_t>
 
using mqtt_callback_t = std::function<void(const std::string &, const std::string &)>
 Callback for MQTT subscriptions.
 
using mqtt_json_callback_t = std::function<void(const std::string &, JsonObject)>
 

Enumerations

enum class  MQTTClientDisconnectReason : int8_t {
  TCP_DISCONNECTED = 0 , MQTT_UNACCEPTABLE_PROTOCOL_VERSION = 1 , MQTT_IDENTIFIER_REJECTED = 2 , MQTT_SERVER_UNAVAILABLE = 3 ,
  MQTT_MALFORMED_CREDENTIALS = 4 , MQTT_NOT_AUTHORIZED = 5 , ESP8266_NOT_ENOUGH_SPACE = 6 , TLS_BAD_FINGERPRINT = 7 ,
  DNS_RESOLVE_ERROR = 8
}
 
enum  MqttQueueTypeT : uint8_t { MQTT_QUEUE_TYPE_NONE = 0 , MQTT_QUEUE_TYPE_SUBSCRIBE , MQTT_QUEUE_TYPE_UNSUBSCRIBE , MQTT_QUEUE_TYPE_PUBLISH }
 
enum  MQTTDiscoveryUniqueIdGenerator { MQTT_LEGACY_UNIQUE_ID_GENERATOR = 0 , MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR }
 available discovery unique_id generators More...
 
enum  MQTTDiscoveryObjectIdGenerator { MQTT_NONE_OBJECT_ID_GENERATOR = 0 , MQTT_DEVICE_NAME_OBJECT_ID_GENERATOR }
 available discovery object_id generators More...
 
enum  MQTTClientState {
  MQTT_CLIENT_DISABLED = 0 , MQTT_CLIENT_DISCONNECTED , MQTT_CLIENT_RESOLVING_ADDRESS , MQTT_CLIENT_CONNECTING ,
  MQTT_CLIENT_CONNECTED
}
 

Functions

 PROGMEM_STRING_TABLE (AlarmMqttStateStrings, "disarmed", "armed_home", "armed_away", "armed_night", "armed_vacation", "armed_custom_bypass", "pending", "arming", "disarming", "triggered", "unknown")
 
 MQTT_COMPONENT_TYPE (MQTTAlarmControlPanelComponent, "alarm_control_panel") const EntityBase *MQTTAlarmControlPanelComponent
 
 MQTT_COMPONENT_TYPE (MQTTBinarySensorComponent, "binary_sensor") const EntityBase *MQTTBinarySensorComponent
 
 PROGMEM_STRING_TABLE (ClimateMqttModeStrings, "off", "heat_cool", "cool", "heat", "fan_only", "dry", "auto", "unknown")
 
 PROGMEM_STRING_TABLE (ClimateMqttActionStrings, "off", "unknown", "cooling", "heating", "idle", "drying", "fan", "unknown")
 
 PROGMEM_STRING_TABLE (ClimateMqttFanModeStrings, "on", "off", "auto", "low", "medium", "high", "middle", "focus", "diffuse", "quiet", "unknown")
 
 PROGMEM_STRING_TABLE (ClimateMqttSwingModeStrings, "off", "both", "vertical", "horizontal", "unknown")
 
 PROGMEM_STRING_TABLE (ClimateMqttPresetStrings, "none", "home", "away", "boost", "comfort", "eco", "sleep", "activity", "unknown")
 
 MQTT_COMPONENT_TYPE (MQTTClimateComponent, "climate") const EntityBase *MQTTClimateComponent
 
 PROGMEM_STRING_TABLE (EntityCategoryMqttStrings, "", "config", "diagnostic")
 
char * append_str (char *p, const char *s, size_t len)
 
char * append_char (char *p, char c)
 
void log_mqtt_component (const char *tag, MQTTComponent *obj, bool state_topic, bool command_topic)
 
 MQTT_COMPONENT_TYPE (MQTTCoverComponent, "cover") const EntityBase *MQTTCoverComponent
 
 MQTT_COMPONENT_TYPE (MQTTDateComponent, "date") const EntityBase *MQTTDateComponent
 
 MQTT_COMPONENT_TYPE (MQTTDateTimeComponent, "datetime") const EntityBase *MQTTDateTimeComponent
 
 MQTT_COMPONENT_TYPE (MQTTFanComponent, "fan") const EntityBase *MQTTFanComponent
 
 MQTT_COMPONENT_TYPE (MQTTJSONLightComponent, "light") const EntityBase *MQTTJSONLightComponent
 
 MQTT_COMPONENT_TYPE (MQTTLockComponent, "lock") const EntityBase *MQTTLockComponent
 
 PROGMEM_STRING_TABLE (NumberMqttModeStrings, "", "box", "slider")
 
 MQTT_COMPONENT_TYPE (MQTTNumberComponent, "number") const EntityBase *MQTTNumberComponent
 
 MQTT_COMPONENT_TYPE (MQTTSelectComponent, "select") const EntityBase *MQTTSelectComponent
 
 MQTT_COMPONENT_TYPE (MQTTSensorComponent, "sensor") const EntityBase *MQTTSensorComponent
 
 MQTT_COMPONENT_TYPE (MQTTSwitchComponent, "switch") const EntityBase *MQTTSwitchComponent
 
 PROGMEM_STRING_TABLE (TextMqttModeStrings, "text", "password")
 
 MQTT_COMPONENT_TYPE (MQTTTextComponent, "text") const EntityBase *MQTTTextComponent
 
 MQTT_COMPONENT_TYPE (MQTTTimeComponent, "time") const EntityBase *MQTTTimeComponent
 
 MQTT_COMPONENT_TYPE (MQTTValveComponent, "valve") const EntityBase *MQTTValveComponent
 

Variables

MQTTClientComponentglobal_mqtt_client
 

Typedef Documentation

◆ mqtt_callback_t

using esphome::mqtt::mqtt_callback_t = std::function<void(const std::string &, const std::string &)>

Callback for MQTT subscriptions.

First parameter is the topic, the second one is the payload.

Definition at line 38 of file mqtt_client.h.

◆ mqtt_json_callback_t

using esphome::mqtt::mqtt_json_callback_t = std::function<void(const std::string &, JsonObject)>

Definition at line 39 of file mqtt_client.h.

◆ mqtt_on_connect_callback_t

Callback for MQTT events.

Definition at line 31 of file mqtt_client.h.

◆ mqtt_on_disconnect_callback_t

Enumeration Type Documentation

◆ MQTTClientDisconnectReason

enum class esphome::mqtt::MQTTClientDisconnectReason : int8_t
strong
Enumerator
TCP_DISCONNECTED 
MQTT_UNACCEPTABLE_PROTOCOL_VERSION 
MQTT_IDENTIFIER_REJECTED 
MQTT_SERVER_UNAVAILABLE 
MQTT_MALFORMED_CREDENTIALS 
MQTT_NOT_AUTHORIZED 
ESP8266_NOT_ENOUGH_SPACE 
TLS_BAD_FINGERPRINT 
DNS_RESOLVE_ERROR 

Definition at line 11 of file mqtt_backend.h.

◆ MQTTClientState

Enumerator
MQTT_CLIENT_DISABLED 
MQTT_CLIENT_DISCONNECTED 
MQTT_CLIENT_RESOLVING_ADDRESS 
MQTT_CLIENT_CONNECTING 
MQTT_CLIENT_CONNECTED 

Definition at line 92 of file mqtt_client.h.

◆ MQTTDiscoveryObjectIdGenerator

available discovery object_id generators

Enumerator
MQTT_NONE_OBJECT_ID_GENERATOR 
MQTT_DEVICE_NAME_OBJECT_ID_GENERATOR 

Definition at line 74 of file mqtt_client.h.

◆ MQTTDiscoveryUniqueIdGenerator

available discovery unique_id generators

Enumerator
MQTT_LEGACY_UNIQUE_ID_GENERATOR 
MQTT_MAC_ADDRESS_UNIQUE_ID_GENERATOR 

Definition at line 68 of file mqtt_client.h.

◆ MqttQueueTypeT

Enumerator
MQTT_QUEUE_TYPE_NONE 
MQTT_QUEUE_TYPE_SUBSCRIBE 
MQTT_QUEUE_TYPE_UNSUBSCRIBE 
MQTT_QUEUE_TYPE_PUBLISH 

Definition at line 49 of file mqtt_backend_esp32.h.

Function Documentation

◆ append_char()

char * esphome::mqtt::append_char ( char * p,
char c )
inline

Definition at line 26 of file mqtt_component.cpp.

◆ append_str()

char * esphome::mqtt::append_str ( char * p,
const char * s,
size_t len )
inline

Definition at line 21 of file mqtt_component.cpp.

◆ log_mqtt_component()

void esphome::mqtt::log_mqtt_component ( const char * tag,
MQTTComponent * obj,
bool state_topic,
bool command_topic )

Definition at line 40 of file mqtt_component.cpp.

◆ MQTT_COMPONENT_TYPE() [1/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTAlarmControlPanelComponent ,
"alarm_control_panel"  ) const

Definition at line 91 of file mqtt_alarm_control_panel.cpp.

◆ MQTT_COMPONENT_TYPE() [2/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTBinarySensorComponent ,
"binary_sensor"  ) const

Definition at line 13 of file mqtt_binary_sensor.cpp.

◆ MQTT_COMPONENT_TYPE() [3/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTClimateComponent ,
"climate"  ) const

Definition at line 298 of file mqtt_climate.cpp.

◆ MQTT_COMPONENT_TYPE() [4/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTCoverComponent ,
"cover"  ) const

Definition at line 137 of file mqtt_cover.cpp.

◆ MQTT_COMPONENT_TYPE() [5/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTDateComponent ,
"date"  ) const

Definition at line 42 of file mqtt_date.cpp.

◆ MQTT_COMPONENT_TYPE() [6/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTDateTimeComponent ,
"datetime"  ) const

Definition at line 53 of file mqtt_datetime.cpp.

◆ MQTT_COMPONENT_TYPE() [7/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTFanComponent ,
"fan"  ) const

Definition at line 27 of file mqtt_fan.cpp.

◆ MQTT_COMPONENT_TYPE() [8/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTJSONLightComponent ,
"light"  ) const

Definition at line 17 of file mqtt_light.cpp.

◆ MQTT_COMPONENT_TYPE() [9/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTLockComponent ,
"lock"  ) const

Definition at line 38 of file mqtt_lock.cpp.

◆ MQTT_COMPONENT_TYPE() [10/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTNumberComponent ,
"number"  ) const

Definition at line 40 of file mqtt_number.cpp.

◆ MQTT_COMPONENT_TYPE() [11/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTSelectComponent ,
"select"  ) const

Definition at line 31 of file mqtt_select.cpp.

◆ MQTT_COMPONENT_TYPE() [12/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTSensorComponent ,
"sensor"  ) const

Definition at line 34 of file mqtt_sensor.cpp.

◆ MQTT_COMPONENT_TYPE() [13/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTSwitchComponent ,
"switch"  ) const

Definition at line 44 of file mqtt_switch.cpp.

◆ MQTT_COMPONENT_TYPE() [14/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTTextComponent ,
"text"  ) const

Definition at line 36 of file mqtt_text.cpp.

◆ MQTT_COMPONENT_TYPE() [15/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTTimeComponent ,
"time"  ) const

Definition at line 42 of file mqtt_time.cpp.

◆ MQTT_COMPONENT_TYPE() [16/16]

esphome::mqtt::MQTT_COMPONENT_TYPE ( MQTTValveComponent ,
"valve"  ) const

Definition at line 83 of file mqtt_valve.cpp.

◆ PROGMEM_STRING_TABLE() [1/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( AlarmMqttStateStrings ,
"disarmed" ,
"armed_home" ,
"armed_away" ,
"armed_night" ,
"armed_vacation" ,
"armed_custom_bypass" ,
"pending" ,
"arming" ,
"disarming" ,
"triggered" ,
"unknown"  )

◆ PROGMEM_STRING_TABLE() [2/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( ClimateMqttActionStrings ,
"off" ,
"unknown" ,
"cooling" ,
"heating" ,
"idle" ,
"drying" ,
"fan" ,
"unknown"  )

◆ PROGMEM_STRING_TABLE() [3/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( ClimateMqttFanModeStrings ,
"on" ,
"off" ,
"auto" ,
"low" ,
"medium" ,
"high" ,
"middle" ,
"focus" ,
"diffuse" ,
"quiet" ,
"unknown"  )

◆ PROGMEM_STRING_TABLE() [4/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( ClimateMqttModeStrings ,
"off" ,
"heat_cool" ,
"cool" ,
"heat" ,
"fan_only" ,
"dry" ,
"auto" ,
"unknown"  )

◆ PROGMEM_STRING_TABLE() [5/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( ClimateMqttPresetStrings ,
"none" ,
"home" ,
"away" ,
"boost" ,
"comfort" ,
"eco" ,
"sleep" ,
"activity" ,
"unknown"  )

◆ PROGMEM_STRING_TABLE() [6/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( ClimateMqttSwingModeStrings ,
"off" ,
"both" ,
"vertical" ,
"horizontal" ,
"unknown"  )

◆ PROGMEM_STRING_TABLE() [7/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( EntityCategoryMqttStrings ,
"" ,
"config" ,
"diagnostic"  )

◆ PROGMEM_STRING_TABLE() [8/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( NumberMqttModeStrings ,
"" ,
"box" ,
"slider"  )

◆ PROGMEM_STRING_TABLE() [9/9]

esphome::mqtt::PROGMEM_STRING_TABLE ( TextMqttModeStrings ,
"text" ,
"password"  )

Variable Documentation

◆ global_mqtt_client

MQTTClientComponent* esphome::mqtt::global_mqtt_client
extern