Struct hass_mqtt_discovery::entity::BinarySensor
source · pub struct BinarySensor<'a> {Show 21 fields
pub availability: Cow<'a, [Availability<'a>]>,
pub availability_mode: AvailabilityMode,
pub device: Option<Device<'a>>,
pub enabled_by_default: Option<bool>,
pub encoding: Option<Cow<'a, str>>,
pub entity_category: EntityCategory,
pub icon: Option<Icon<'a>>,
pub json_attributes_template: Option<Template<'a>>,
pub json_attributes_topic: Option<Topic<'a>>,
pub name: Option<Name<'a>>,
pub object_id: Option<Cow<'a, str>>,
pub qos: MqttQoS,
pub unique_id: Option<UniqueId<'a>>,
pub device_class: DeviceClass,
pub expire_after: Option<NonZeroU32>,
pub force_update: Option<bool>,
pub off_delay: Option<NonZeroU32>,
pub payload_off: Option<Payload<'a>>,
pub payload_on: Option<Payload<'a>>,
pub state_topic: Topic<'a>,
pub value_template: Option<Template<'a>>,
}
Expand description
The mqtt binary sensor platform uses an MQTT message received to set the binary sensor’s
state to on
, off
or unknown
.
The state will be updated only after a new message is published on state_topic
matching payload_on
, payload_off
or None
.
If these messages are published with the retain
flag set, the binary sensor will receive an
instant state update after subscription and Home Assistant will display the correct state on
startup. Otherwise, the initial state displayed in Home Assistant will be unknown
.
Stateless devices such as buttons, remote controls etc are better represented by MQTT device triggers than by binary sensors.
See: https://www.home-assistant.io/integrations/binary_sensor.mqtt/
Fields§
§availability: Cow<'a, [Availability<'a>]>
A list of MQTT topics subscribed to receive availability (online/offline) updates.
availability_mode: AvailabilityMode
When availability
is configured, this controls the conditions needed
to set the entity to available
.
device: Option<Device<'a>>
Information about the device this entity is a part of to tie it into the device registry.
Only works through MQTT discovery and when unique_id
is set.
At least one of identifiers or connections must be present to identify the device.
enabled_by_default: Option<bool>
Flag which defines if the entity should be enabled when first added.
Defaults to true
.
encoding: Option<Cow<'a, str>>
The encoding of the payloads received and published messages. Set to “” to disable decoding of incoming payload.
Defaults to "utf-8"
.
entity_category: EntityCategory
The category of the entity.
icon: Option<Icon<'a>>
Icon for the entity.
json_attributes_template: Option<Template<'a>>
Defines a template to extract the JSON dictionary from messages received
on the json_attributes_topic
.
json_attributes_topic: Option<Topic<'a>>
The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes.
Implies force_update
of the current state when a message is received on this topic.
name: Option<Name<'a>>
The name of the MQTT entity.
object_id: Option<Cow<'a, str>>
Used instead of name
for automatic generation of entity_id
.
qos: MqttQoS
The maximum QoS level of the state topic.
unique_id: Option<UniqueId<'a>>
An ID that uniquely identifies this entity. If two entities have the same unique ID, Home Assistant will raise an exception.
device_class: DeviceClass
The type/class of the sensor to set the icon in the frontend.
expire_after: Option<NonZeroU32>
Defines the number of seconds after the value expires if it’s not updated. After
expiry, the sensor’s state becomes unavailable
.
force_update: Option<bool>
Sends update events (which results in update of state object’s last_changed) even if the sensor’s state hasn’t changed. Useful if you want to have meaningful value graphs in history or want to create an automation that triggers on every incoming state message (not only when the sensor’s new state is different to the current one).
off_delay: Option<NonZeroU32>
For sensors that only send on
state updates (like PIRs), this variable sets a
delay in seconds after which the sensor’s state will be updated back to off
.
payload_off: Option<Payload<'a>>
The string that represents the off
state. It will be compared to the message in the
state_topic
(see value_template
for details)
Defaults to "OFF"
.
payload_on: Option<Payload<'a>>
The string that represents the on
state. It will be compared to the message in the
state_topic
(see value_template
for details)
Defaults to "ON"
.
state_topic: Topic<'a>
The MQTT topic subscribed to receive sensor values.
value_template: Option<Template<'a>>
Defines a template that returns a string to be compared to
payload_on
/payload_off
or an empty string, in which case the MQTT message will be removed.
Available variables: entity_id
.
Remove this option when payload_on
and payload_off
are sufficient to match your payloads
(i.e no pre-processing of original message is required).
Implementations§
source§impl<'a> BinarySensor<'a>
impl<'a> BinarySensor<'a>
pub fn new(state_topic: impl Into<Topic<'a>>) -> Self
sourcepub fn availability(
self,
availability: impl Into<Cow<'a, [Availability<'a>]>>
) -> Self
pub fn availability(
self,
availability: impl Into<Cow<'a, [Availability<'a>]>>
) -> Self
A list of MQTT topics subscribed to receive availability (online/offline) updates.
sourcepub fn availability_mode(
self,
availability_mode: impl Into<AvailabilityMode>
) -> Self
pub fn availability_mode(
self,
availability_mode: impl Into<AvailabilityMode>
) -> Self
When availability
is configured, this controls the conditions needed
to set the entity to available
.
sourcepub fn device(self, device: impl Into<Device<'a>>) -> Self
pub fn device(self, device: impl Into<Device<'a>>) -> Self
Information about the device this entity is a part of to tie it into the device registry.
Only works through MQTT discovery and when unique_id
is set.
At least one of identifiers or connections must be present to identify the device.
sourcepub fn unset_device(&mut self) -> &mut Self
pub fn unset_device(&mut self) -> &mut Self
Information about the device this entity is a part of to tie it into the device registry.
Only works through MQTT discovery and when unique_id
is set.
At least one of identifiers or connections must be present to identify the device.
sourcepub fn enabled_by_default(self, enabled_by_default: impl Into<bool>) -> Self
pub fn enabled_by_default(self, enabled_by_default: impl Into<bool>) -> Self
Flag which defines if the entity should be enabled when first added.
Defaults to true
.
sourcepub fn unset_enabled_by_default(&mut self) -> &mut Self
pub fn unset_enabled_by_default(&mut self) -> &mut Self
Flag which defines if the entity should be enabled when first added.
Defaults to true
.
sourcepub fn encoding(self, encoding: impl Into<Cow<'a, str>>) -> Self
pub fn encoding(self, encoding: impl Into<Cow<'a, str>>) -> Self
The encoding of the payloads received and published messages. Set to “” to disable decoding of incoming payload.
Defaults to "utf-8"
.
sourcepub fn unset_encoding(&mut self) -> &mut Self
pub fn unset_encoding(&mut self) -> &mut Self
The encoding of the payloads received and published messages. Set to “” to disable decoding of incoming payload.
Defaults to "utf-8"
.
sourcepub fn entity_category(self, entity_category: impl Into<EntityCategory>) -> Self
pub fn entity_category(self, entity_category: impl Into<EntityCategory>) -> Self
The category of the entity.
sourcepub fn unset_icon(&mut self) -> &mut Self
pub fn unset_icon(&mut self) -> &mut Self
Icon for the entity.
sourcepub fn json_attributes_template(
self,
json_attributes_template: impl Into<Template<'a>>
) -> Self
pub fn json_attributes_template(
self,
json_attributes_template: impl Into<Template<'a>>
) -> Self
Defines a template to extract the JSON dictionary from messages received
on the json_attributes_topic
.
sourcepub fn unset_json_attributes_template(&mut self) -> &mut Self
pub fn unset_json_attributes_template(&mut self) -> &mut Self
Defines a template to extract the JSON dictionary from messages received
on the json_attributes_topic
.
sourcepub fn json_attributes_topic(
self,
json_attributes_topic: impl Into<Topic<'a>>
) -> Self
pub fn json_attributes_topic(
self,
json_attributes_topic: impl Into<Topic<'a>>
) -> Self
The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes.
Implies force_update
of the current state when a message is received on this topic.
sourcepub fn unset_json_attributes_topic(&mut self) -> &mut Self
pub fn unset_json_attributes_topic(&mut self) -> &mut Self
The MQTT topic subscribed to receive a JSON dictionary payload and then set as entity attributes.
Implies force_update
of the current state when a message is received on this topic.
sourcepub fn unset_name(&mut self) -> &mut Self
pub fn unset_name(&mut self) -> &mut Self
The name of the MQTT entity.
sourcepub fn object_id(self, object_id: impl Into<Cow<'a, str>>) -> Self
pub fn object_id(self, object_id: impl Into<Cow<'a, str>>) -> Self
Used instead of name
for automatic generation of entity_id
.
sourcepub fn unset_object_id(&mut self) -> &mut Self
pub fn unset_object_id(&mut self) -> &mut Self
Used instead of name
for automatic generation of entity_id
.
sourcepub fn unique_id(self, unique_id: impl Into<UniqueId<'a>>) -> Self
pub fn unique_id(self, unique_id: impl Into<UniqueId<'a>>) -> Self
An ID that uniquely identifies this entity. If two entities have the same unique ID, Home Assistant will raise an exception.
sourcepub fn unset_unique_id(&mut self) -> &mut Self
pub fn unset_unique_id(&mut self) -> &mut Self
An ID that uniquely identifies this entity. If two entities have the same unique ID, Home Assistant will raise an exception.
sourcepub fn device_class(self, device_class: impl Into<DeviceClass>) -> Self
pub fn device_class(self, device_class: impl Into<DeviceClass>) -> Self
The type/class of the sensor to set the icon in the frontend.
sourcepub fn expire_after(self, expire_after: impl Into<NonZeroU32>) -> Self
pub fn expire_after(self, expire_after: impl Into<NonZeroU32>) -> Self
Defines the number of seconds after the value expires if it’s not updated. After
expiry, the sensor’s state becomes unavailable
.
sourcepub fn unset_expire_after(&mut self) -> &mut Self
pub fn unset_expire_after(&mut self) -> &mut Self
Defines the number of seconds after the value expires if it’s not updated. After
expiry, the sensor’s state becomes unavailable
.
sourcepub fn force_update(self, force_update: impl Into<bool>) -> Self
pub fn force_update(self, force_update: impl Into<bool>) -> Self
Sends update events (which results in update of state object’s last_changed) even if the sensor’s state hasn’t changed. Useful if you want to have meaningful value graphs in history or want to create an automation that triggers on every incoming state message (not only when the sensor’s new state is different to the current one).
sourcepub fn unset_force_update(&mut self) -> &mut Self
pub fn unset_force_update(&mut self) -> &mut Self
Sends update events (which results in update of state object’s last_changed) even if the sensor’s state hasn’t changed. Useful if you want to have meaningful value graphs in history or want to create an automation that triggers on every incoming state message (not only when the sensor’s new state is different to the current one).
sourcepub fn off_delay(self, off_delay: impl Into<NonZeroU32>) -> Self
pub fn off_delay(self, off_delay: impl Into<NonZeroU32>) -> Self
For sensors that only send on
state updates (like PIRs), this variable sets a
delay in seconds after which the sensor’s state will be updated back to off
.
sourcepub fn unset_off_delay(&mut self) -> &mut Self
pub fn unset_off_delay(&mut self) -> &mut Self
For sensors that only send on
state updates (like PIRs), this variable sets a
delay in seconds after which the sensor’s state will be updated back to off
.
sourcepub fn payload_off(self, payload_off: impl Into<Payload<'a>>) -> Self
pub fn payload_off(self, payload_off: impl Into<Payload<'a>>) -> Self
The string that represents the off
state. It will be compared to the message in the
state_topic
(see value_template
for details)
Defaults to "OFF"
.
sourcepub fn unset_payload_off(&mut self) -> &mut Self
pub fn unset_payload_off(&mut self) -> &mut Self
The string that represents the off
state. It will be compared to the message in the
state_topic
(see value_template
for details)
Defaults to "OFF"
.
sourcepub fn payload_on(self, payload_on: impl Into<Payload<'a>>) -> Self
pub fn payload_on(self, payload_on: impl Into<Payload<'a>>) -> Self
The string that represents the on
state. It will be compared to the message in the
state_topic
(see value_template
for details)
Defaults to "ON"
.
sourcepub fn unset_payload_on(&mut self) -> &mut Self
pub fn unset_payload_on(&mut self) -> &mut Self
The string that represents the on
state. It will be compared to the message in the
state_topic
(see value_template
for details)
Defaults to "ON"
.
sourcepub fn state_topic(self, state_topic: impl Into<Topic<'a>>) -> Self
pub fn state_topic(self, state_topic: impl Into<Topic<'a>>) -> Self
The MQTT topic subscribed to receive sensor values.
sourcepub fn value_template(self, value_template: impl Into<Template<'a>>) -> Self
pub fn value_template(self, value_template: impl Into<Template<'a>>) -> Self
Defines a template that returns a string to be compared to
payload_on
/payload_off
or an empty string, in which case the MQTT message will be removed.
Available variables: entity_id
.
Remove this option when payload_on
and payload_off
are sufficient to match your payloads
(i.e no pre-processing of original message is required).
sourcepub fn unset_value_template(&mut self) -> &mut Self
pub fn unset_value_template(&mut self) -> &mut Self
Defines a template that returns a string to be compared to
payload_on
/payload_off
or an empty string, in which case the MQTT message will be removed.
Available variables: entity_id
.
Remove this option when payload_on
and payload_off
are sufficient to match your payloads
(i.e no pre-processing of original message is required).
Trait Implementations§
source§impl<'a> Clone for BinarySensor<'a>
impl<'a> Clone for BinarySensor<'a>
source§fn clone(&self) -> BinarySensor<'a>
fn clone(&self) -> BinarySensor<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for BinarySensor<'a>
impl<'a> Debug for BinarySensor<'a>
source§impl<'de: 'a, 'a> Deserialize<'de> for BinarySensor<'a>
impl<'de: 'a, 'a> Deserialize<'de> for BinarySensor<'a>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<'a> Document for BinarySensor<'a>
impl<'a> Document for BinarySensor<'a>
fn serialize_validated<S>(
validated: Validated<&BinarySensor<'a>>,
serializer: S
) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>
source§impl<'a> PartialEq<BinarySensor<'a>> for BinarySensor<'a>
impl<'a> PartialEq<BinarySensor<'a>> for BinarySensor<'a>
source§fn eq(&self, other: &BinarySensor<'a>) -> bool
fn eq(&self, other: &BinarySensor<'a>) -> bool
source§impl<'a> Serialize for BinarySensor<'a>
impl<'a> Serialize for BinarySensor<'a>
source§impl<'a> Validate for BinarySensor<'a>
impl<'a> Validate for BinarySensor<'a>
§type Invalidity = BinarySensorInvalidity
type Invalidity = BinarySensorInvalidity
source§fn validate(&self) -> ValidationResult<Self::Invalidity>
fn validate(&self) -> ValidationResult<Self::Invalidity>
impl<'a> Eq for BinarySensor<'a>
impl<'a> StructuralEq for BinarySensor<'a>
impl<'a> StructuralPartialEq for BinarySensor<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for BinarySensor<'a>
impl<'a> Send for BinarySensor<'a>
impl<'a> Sync for BinarySensor<'a>
impl<'a> Unpin for BinarySensor<'a>
impl<'a> UnwindSafe for BinarySensor<'a>
Blanket Implementations§
source§impl<T, V> IntoValidated<V> for Twhere
V: ValidatedFrom<T>,
impl<T, V> IntoValidated<V> for Twhere
V: ValidatedFrom<T>,
source§fn into_validated(
self
) -> Result<Validated<V>, (V, Context<<V as Validate>::Invalidity>)>
fn into_validated(
self
) -> Result<Validated<V>, (V, Context<<V as Validate>::Invalidity>)>
self
into output value and validate the output Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more