Struct hass_mqtt_discovery::entity::Sensor
source · pub struct Sensor<'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 last_reset_value_template: Option<Template<'a>>,
pub state_class: StateClass,
pub state_topic: Topic<'a>,
pub unit_of_measurement: Option<Cow<'a, str>>,
pub value_template: Option<Template<'a>>,
}
Expand description
This mqtt sensor platform uses the MQTT message payload as the sensor value. If messages in this state_topic are published with RETAIN flag, the sensor will receive an instant update with last known value. Otherwise, the initial state will be undefined.
See: https://www.home-assistant.io/integrations/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 even if the value hasn’t changed. Useful if you want to have
meaningful value graphs in history. Defaults to false
.
last_reset_value_template: Option<Template<'a>>
Defines a template to extract the last_reset. Available variables: entity_id
.
The entity_id
can be used to reference the entity’s attributes.
state_class: StateClass
The state_class of the sensor.
state_topic: Topic<'a>
The MQTT topic subscribed to receive sensor values.
unit_of_measurement: Option<Cow<'a, str>>
Defines the units of measurement of the sensor, if any.
value_template: Option<Template<'a>>
Defines a template to extract the value. Available variables: entity_id
.
The entity_id
can be used to reference the entity’s attributes.
Implementations§
source§impl<'a> Sensor<'a>
impl<'a> Sensor<'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 even if the value hasn’t changed. Useful if you want to have
meaningful value graphs in history. Defaults to false
.
sourcepub fn unset_force_update(&mut self) -> &mut Self
pub fn unset_force_update(&mut self) -> &mut Self
Sends update events even if the value hasn’t changed. Useful if you want to have
meaningful value graphs in history. Defaults to false
.
sourcepub fn last_reset_value_template(
self,
last_reset_value_template: impl Into<Template<'a>>
) -> Self
pub fn last_reset_value_template(
self,
last_reset_value_template: impl Into<Template<'a>>
) -> Self
Defines a template to extract the last_reset. Available variables: entity_id
.
The entity_id
can be used to reference the entity’s attributes.
sourcepub fn unset_last_reset_value_template(&mut self) -> &mut Self
pub fn unset_last_reset_value_template(&mut self) -> &mut Self
Defines a template to extract the last_reset. Available variables: entity_id
.
The entity_id
can be used to reference the entity’s attributes.
sourcepub fn state_class(self, state_class: impl Into<StateClass>) -> Self
pub fn state_class(self, state_class: impl Into<StateClass>) -> Self
The state_class of the sensor.
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 unit_of_measurement(
self,
unit_of_measurement: impl Into<Cow<'a, str>>
) -> Self
pub fn unit_of_measurement(
self,
unit_of_measurement: impl Into<Cow<'a, str>>
) -> Self
Defines the units of measurement of the sensor, if any.
sourcepub fn unset_unit_of_measurement(&mut self) -> &mut Self
pub fn unset_unit_of_measurement(&mut self) -> &mut Self
Defines the units of measurement of the sensor, if any.
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 to extract the value. Available variables: entity_id
.
The entity_id
can be used to reference the entity’s attributes.
sourcepub fn unset_value_template(&mut self) -> &mut Self
pub fn unset_value_template(&mut self) -> &mut Self
Defines a template to extract the value. Available variables: entity_id
.
The entity_id
can be used to reference the entity’s attributes.
Trait Implementations§
source§impl<'de: 'a, 'a> Deserialize<'de> for Sensor<'a>
impl<'de: 'a, 'a> Deserialize<'de> for Sensor<'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> Validate for Sensor<'a>
impl<'a> Validate for Sensor<'a>
§type Invalidity = SensorInvalidity
type Invalidity = SensorInvalidity
source§fn validate(&self) -> ValidationResult<Self::Invalidity>
fn validate(&self) -> ValidationResult<Self::Invalidity>
impl<'a> Eq for Sensor<'a>
impl<'a> StructuralEq for Sensor<'a>
impl<'a> StructuralPartialEq for Sensor<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for Sensor<'a>
impl<'a> Send for Sensor<'a>
impl<'a> Sync for Sensor<'a>
impl<'a> Unpin for Sensor<'a>
impl<'a> UnwindSafe for Sensor<'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