17 static const char *
const TAG =
"mqtt.sensor";
30 ESP_LOGCONFIG(TAG,
" Expire After: %" PRIu32
"s", this->
get_expire_after() / 1000);
32 LOG_MQTT_COMPONENT(
true,
false)
bool get_force_update() const
Get whether force update mode is enabled.
MQTTSensorComponent(sensor::Sensor *sensor)
Construct this MQTTSensorComponent instance with the provided friendly_name and sensor.
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
std::string value_accuracy_to_string(float value, int8_t accuracy_decimals)
Create a string from a value and an accuracy in decimals.
std::string get_device_class()
Get the device class, using the manual override if set.
void dump_config() override
bool send_initial_state() override
optional< uint32_t > expire_after_
void disable_expire_after()
Disable Home Assistant value expiry.
bool command_topic
If the command topic should be included. Default to true.
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
void setup() override
Override setup.
MQTTClientComponent * global_mqtt_client
virtual std::string unique_id()
Override this method to set the unique ID of this sensor.
float state
This member variable stores the last state that has passed through all filters.
constexpr const char *const MQTT_STATE_CLASS
void set_expire_after(uint32_t expire_after)
Setup an expiry, 0 disables it.
std::string state_class_to_string(StateClass state_class)
constexpr const char *const MQTT_UNIT_OF_MEASUREMENT
constexpr const char *const MQTT_FORCE_UPDATE
Simple Helper struct used for Home Assistant MQTT send_discovery().
std::string get_unit_of_measurement()
Get the unit of measurement, using the manual override if set.
bool publish_state(float value)
StateClass get_state_class()
Get the state class, using the manual override if set.
std::string unique_id() override
constexpr const char * c_str() const
constexpr const char *const MQTT_EXPIRE_AFTER
Implementation of SPI Controller mode.
bool has_state() const
Return whether this sensor has gotten a full state (that passed through all filters) yet...
int8_t get_accuracy_decimals()
Get the accuracy in decimals, using the manual override if set.
constexpr const char *const MQTT_DEVICE_CLASS
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
Base-class for all sensors.
uint32_t get_expire_after() const
Get the expire_after in milliseconds used for Home Assistant discovery, first checks override...
std::string component_type() const override
Override for MQTTComponent, returns "sensor".
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
esphome::sensor::Sensor * sensor
const StringRef & get_name() const
const EntityBase * get_entity() const override