ESPHome 2025.7.1
Loading...
Searching...
No Matches
esphome::binary_sensor::BinarySensor Class Reference

Base class for all binary_sensor-type classes. More...

#include <binary_sensor.h>

Inheritance diagram for esphome::binary_sensor::BinarySensor:
esphome::StatefulEntityBase< bool > esphome::EntityBase_DeviceClass esphome::EntityBase esphome::analog_threshold::AnalogThresholdBinarySensor esphome::binary_sensor::BinarySensorInitiallyOff esphome::cap1188::CAP1188Channel esphome::copy::CopyBinarySensor esphome::cst226::CST226Button esphome::demo::DemoBinarySensor esphome::esp32_touch::ESP32TouchBinarySensor esphome::gpio::GPIOBinarySensor esphome::gt911::GT911Button esphome::homeassistant::HomeassistantBinarySensor esphome::ld2420::LD2420BinarySensor esphome::m5stack_8angle::M5Stack8AngleSwitchBinarySensor esphome::modbus_controller::ModbusBinarySensor esphome::mpr121::MPR121BinarySensor esphome::nfc::NfcTagBinarySensor esphome::pn532::PN532BinarySensor esphome::qwiic_pir::QwiicPIRComponent esphome::rc522::RC522BinarySensor esphome::status::StatusBinarySensor esphome::switch_::SwitchBinarySensor esphome::sx1509::SX1509BinarySensor esphome::template_::TemplateBinarySensor esphome::tm1637::TM1637Key esphome::tm1638::TM1638Key esphome::touchscreen::TouchscreenBinarySensor esphome::tt21100::TT21100Button esphome::ttp229_bsf::TTP229BSFChannel esphome::ttp229_lsf::TTP229Channel esphome::tuya::TuyaBinarySensor esphome::vbus::VBusCustomSubBSensor

Public Member Functions

 BinarySensor ()
 
void publish_state (bool new_state)
 Publish a new state to the front-end.
 
void publish_initial_state (bool new_state)
 Publish the initial state, this will not make the callback manager send callbacks and is meant only for the initial state on boot.
 
void add_filter (Filter *filter)
 
void add_filters (const std::vector< Filter * > &filters)
 
void send_state_internal (bool new_state)
 
virtual bool is_status_binary_sensor () const
 Return whether this binary sensor has outputted a state.
 
- Public Member Functions inherited from esphome::StatefulEntityBase< bool >
virtual bool has_state () const
 
virtual const bool & get_state () const
 
virtual bool get_state_default (bool default_value) const
 
void invalidate_state ()
 
void add_full_state_callback (std::function< void(optional< bool > previous, optional< bool > current)> &&callback)
 
void add_on_state_callback (std::function< void(bool)> &&callback)
 
void set_trigger_on_initial_state (bool trigger_on_initial_state)
 
- Public Member Functions inherited from esphome::EntityBase
const StringRefget_name () const
 
void set_name (const char *name)
 
bool has_own_name () const
 
std::string get_object_id () const
 
void set_object_id (const char *object_id)
 
uint32_t get_object_id_hash ()
 
bool is_internal () const
 
void set_internal (bool internal)
 
bool is_disabled_by_default () const
 
void set_disabled_by_default (bool disabled_by_default)
 
EntityCategory get_entity_category () const
 
void set_entity_category (EntityCategory entity_category)
 
std::string get_icon () const
 
void set_icon (const char *icon)
 
uint32_t get_device_id () const
 
void set_device (Device *device)
 
bool has_state () const
 
void set_has_state (bool state)
 
- Public Member Functions inherited from esphome::EntityBase_DeviceClass
std::string get_device_class ()
 Get the device class, using the manual override if set.
 
void set_device_class (const char *device_class)
 Manually set the device class.
 

Data Fields

bool state {}
 

Protected Attributes

Filterfilter_list_ {nullptr}
 
- Protected Attributes inherited from esphome::StatefulEntityBase< bool >
optional< bool > state_
 
bool trigger_on_initial_state_
 
CallbackManager< void(optional< bool > previous, optional< bool > current)> * full_state_callbacks_
 
CallbackManager< void(bool)> * state_callbacks_
 
- Protected Attributes inherited from esphome::EntityBase
StringRef name_
 
const char * object_id_c_str_ {nullptr}
 
const char * icon_c_str_ {nullptr}
 
uint32_t object_id_hash_ {}
 
Devicedevice_ {}
 
struct esphome::EntityBase::EntityFlags flags_
 
- Protected Attributes inherited from esphome::EntityBase_DeviceClass
const char * device_class_ {nullptr}
 Device class override.
 

Additional Inherited Members

- Protected Member Functions inherited from esphome::StatefulEntityBase< bool >
bool set_state_ (const optional< bool > &state)
 Set a new state for this entity.
 
- Protected Member Functions inherited from esphome::EntityBase
virtual uint32_t hash_base ()
 The hash_base() function has been deprecated.
 
void calc_object_id_ ()
 

Detailed Description

Base class for all binary_sensor-type classes.

This class includes a callback that components such as MQTT can subscribe to for state changes. The sub classes should notify the front-end of new states via the publish_state() method which handles inverted inputs for you.

Definition at line 36 of file binary_sensor.h.

Constructor & Destructor Documentation

◆ BinarySensor()

esphome::binary_sensor::BinarySensor::BinarySensor ( )
inlineexplicit

Definition at line 38 of file binary_sensor.h.

Member Function Documentation

◆ add_filter()

void esphome::binary_sensor::BinarySensor::add_filter ( Filter * filter)

Definition at line 30 of file binary_sensor.cpp.

◆ add_filters()

void esphome::binary_sensor::BinarySensor::add_filters ( const std::vector< Filter * > & filters)

Definition at line 41 of file binary_sensor.cpp.

◆ is_status_binary_sensor()

bool esphome::binary_sensor::BinarySensor::is_status_binary_sensor ( ) const
virtual

Return whether this binary sensor has outputted a state.

Reimplemented in esphome::status::StatusBinarySensor.

Definition at line 46 of file binary_sensor.cpp.

◆ publish_initial_state()

void esphome::binary_sensor::BinarySensor::publish_initial_state ( bool new_state)

Publish the initial state, this will not make the callback manager send callbacks and is meant only for the initial state on boot.

Parameters
new_stateThe new state.

Definition at line 17 of file binary_sensor.cpp.

◆ publish_state()

void esphome::binary_sensor::BinarySensor::publish_state ( bool new_state)

Publish a new state to the front-end.

Parameters
new_stateThe new state.

Definition at line 10 of file binary_sensor.cpp.

◆ send_state_internal()

void esphome::binary_sensor::BinarySensor::send_state_internal ( bool new_state)

Definition at line 21 of file binary_sensor.cpp.

Field Documentation

◆ filter_list_

Filter* esphome::binary_sensor::BinarySensor::filter_list_ {nullptr}
protected

Definition at line 68 of file binary_sensor.h.

◆ state

bool esphome::binary_sensor::BinarySensor::state {}

Definition at line 65 of file binary_sensor.h.


The documentation for this class was generated from the following files: