Table of Contents

Class Humidifier

Namespace
HaMqttDiscoverable.Entities
Assembly
HaMqttDiscoverable.dll

A humidifier or dehumidifier: on/off with a target humidity, optionally with named modes (e.g. "auto", "sleep"). Set DeviceClass to "humidifier" (the default Home Assistant assumes) or "dehumidifier".

public sealed class Humidifier : HaEntity<HumidifierConfig>, IAsyncDisposable
Inheritance
Humidifier
Implements
Inherited Members

Constructors

Humidifier(HaMqttConnection, HumidifierConfig)

Creates a humidifier from the given config.

public Humidifier(HaMqttConnection connection, HumidifierConfig config)

Parameters

connection HaMqttConnection
config HumidifierConfig

Properties

CurrentHumidityTopic

The topic this humidifier publishes the currently measured humidity to.

public string CurrentHumidityTopic { get; }

Property Value

string

ModeCommandTopic

The topic this humidifier accepts a mode on, or null if Modes is empty.

public string? ModeCommandTopic { get; }

Property Value

string

ModeStateTopic

The topic this humidifier publishes its mode to, or null if Modes is empty.

public string? ModeStateTopic { get; }

Property Value

string

SupportsCommands

Whether this entity type accepts commands from Home Assistant (e.g. switches, numbers). Sensors are read-only and return false.

protected override bool SupportsCommands { get; }

Property Value

bool

TargetHumidityCommandTopic

The topic this humidifier accepts a target humidity on.

public string TargetHumidityCommandTopic { get; }

Property Value

string

TargetHumidityStateTopic

The topic this humidifier publishes its target humidity to.

public string TargetHumidityStateTopic { get; }

Property Value

string

Methods

EnrichDiscoveryPayload(JsonObject)

Allows subclasses to add fields to the discovery payload that aren't part of EntityConfig directly.

protected override void EnrichDiscoveryPayload(JsonObject payload)

Parameters

payload JsonObject

OnCommandReceivedAsync(string)

Called with the raw payload every time a message arrives on CommandTopic. Overridden by controllable entity types.

protected override Task OnCommandReceivedAsync(string payload)

Parameters

payload string

Returns

Task

PublishCurrentHumidityAsync(double, bool, CancellationToken)

Publishes the currently measured humidity (0-100).

public Task PublishCurrentHumidityAsync(double humidity, bool retain = true, CancellationToken cancellationToken = default)

Parameters

humidity double
retain bool
cancellationToken CancellationToken

Returns

Task

PublishModeAsync(string, bool, CancellationToken)

Publishes the humidifier's current mode. Requires Modes to be non-empty.

public Task PublishModeAsync(string mode, bool retain = true, CancellationToken cancellationToken = default)

Parameters

mode string
retain bool
cancellationToken CancellationToken

Returns

Task

PublishStateAsync(bool, bool, CancellationToken)

Publishes the humidifier's current on/off state.

public Task PublishStateAsync(bool isOn, bool retain = true, CancellationToken cancellationToken = default)

Parameters

isOn bool
retain bool
cancellationToken CancellationToken

Returns

Task

PublishTargetHumidityAsync(double, bool, CancellationToken)

Publishes the humidifier's current target humidity (0-100).

public Task PublishTargetHumidityAsync(double humidity, bool retain = true, CancellationToken cancellationToken = default)

Parameters

humidity double
retain bool
cancellationToken CancellationToken

Returns

Task

Events

CommandReceived

Raised when Home Assistant sends a command to turn the humidifier on or off.

public event Func<bool, Task>? CommandReceived

Event Type

Func<bool, Task>

ModeCommandReceived

Raised when Home Assistant sends a new mode. Only raised when Modes is non-empty.

public event Func<string, Task>? ModeCommandReceived

Event Type

Func<string, Task>

TargetHumidityCommandReceived

Raised when Home Assistant sends a new target humidity (0-100).

public event Func<double, Task>? TargetHumidityCommandReceived

Event Type

Func<double, Task>