Table of Contents

Class Sensor

Namespace
HaMqttDiscoverable.Entities
Assembly
HaMqttDiscoverable.dll

A read-only value reported to Home Assistant, e.g. a temperature reading or a counter.

public sealed class Sensor : HaEntity<SensorConfig>, IAsyncDisposable
Inheritance
Sensor
Implements
Inherited Members

Examples

var sensor = new Sensor(connection, new SensorConfig
{
    Name = "Temperature",
    UniqueId = "weather-station-temperature",
    Device = device,
    UnitOfMeasurement = "°C",
    DeviceClass = "temperature",
    StateClass = "measurement",
});
await sensor.PublishDiscoveryAsync();
await sensor.PublishStateAsync("21.5");

Constructors

Sensor(HaMqttConnection, SensorConfig)

Creates a sensor from the given config.

public Sensor(HaMqttConnection connection, SensorConfig config)

Parameters

connection HaMqttConnection
config SensorConfig