Net2HassMqtt adds Home Assistant (HASS) integration to your .NET applications via MQTT. It not a MQTT transport layer but provides an Home Assistant centric fluent configuration interface to map your application's models to Home Assistant devices and entities. Through Home Assistant MQTT Discovery your application devices and entities just appear automatically in Home Assistant.
$ dotnet add package NoeticTools.Net2HassMqttNet2HassMqtt provides Home Assistant (HASS) integration to .NET applications via MQTT. It not a MQTT transport layer. It provides a Home Assistant centric fluent configuration interface to map your application's models to Home Assistant entities.
The devices and entities you configure automatically appear fully configured in Home Assistant (Home Assistant MQTT Discovery). Configure once, use twice & no YAML! :-)
You do not need to code any MQTT publish calls, value conversions, subscriptions, or connection management. It just all happens. Net2HassMqtt layers over MQTT so you do not have to. It is designed to let you work with the "what" (Home Assistant) not the "how" (MQTT).
An example:
// Create a device to hold the entities
var device = new DeviceBuilder().WithFriendlyName("Net2HassMqtt Quick Start Device 1")
.WithId("net2hassmqtt_quick_start_device_01");
// Map model property to an entity
device.HasBatteryChargingBinarySensor(config => config.OnModel(model)
.WithStatusProperty(nameof(QuickStartDemoModel.BatteryChaging))
.WithUnitOfMeasurement(BatteryChargingBinarySensorUoM.None)
.WithFriendlyName("Battery Charging Status")
.WithNodeId("battery_1_charging"));
// Build bridge
var bridge = new BridgeConfiguration().WithMqttOptions(mqttClientOptions)
.HasDevice(device)
.Build();
// Run
await bridge.StartAsync();