nf.HomeAssistant.MqttDiscovery 1.0.1

dotnet add package nf.HomeAssistant.MqttDiscovery --version 1.0.1
                    
NuGet\Install-Package nf.HomeAssistant.MqttDiscovery -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="nf.HomeAssistant.MqttDiscovery" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="nf.HomeAssistant.MqttDiscovery" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="nf.HomeAssistant.MqttDiscovery" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add nf.HomeAssistant.MqttDiscovery --version 1.0.1
                    
#r "nuget: nf.HomeAssistant.MqttDiscovery, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package nf.HomeAssistant.MqttDiscovery@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=nf.HomeAssistant.MqttDiscovery&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=nf.HomeAssistant.MqttDiscovery&version=1.0.1
                    
Install as a Cake Tool

nanoFramework.HomeAssistant.MqttDiscovery

Easily integrate your .NET nanoFramework devices with Home Assistant using MQTT Auto Discovery.
This library lets your devices automatically register entities like sensors and switches without any manual configuration in Home Assistant.


Features

  • Home Assistant MQTT Auto Discovery support
  • Simple API for defining sensors, switches, and other entities
  • Built-in support for state updates and command handling
  • Supports MQTT authentication
  • Compatible with .NET nanoFramework for ESP32 and similar devices

Installation

You can install the package via NuGet:

nuget install nf.HomeAssistant.MqttDiscovery

Example usage

using nanoFramework.HomeAssistant.MqttDiscovery;
using System.Device.Gpio;

// Create the Home Assistant client
var homeassistant = new HomeAssistant(
    "Second Test",
    "192.168.88.172",
    username: "homeassistant",
    password: "password");

// Example: Add a switch entity
var relay = homeassistant.AddSwitch("Switch number 1", "OFF");
relay.OnChange += (s, e) =>
{
    if (e == "ON")
    {
        relayPin.Write(PinValue.High);
    }
    else
    {
        relayPin.Write(PinValue.Low);
    }
};

// Example: Add a temperature sensor
var temperatureSensor = homeassistant.AddSensor("Temperature", "°C", "18", DeviceClass.Temperature);
temperatureSensor.OnChange += (s, e) =>
{
    Console.WriteLine($"Temperature changed to {e}");
};

// Example: Add select options
var dayOfWeek = homeassistant.AddOption("Day of week", new [] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" } , "Tuesday");
dayOfWeek.OnChange += (s, e) =>
{
    Console.WriteLine($"Day of week changed to {e}");
};

// Connect to home assistant
homeassistant.Connect();

// Set the relay to off
relay.SetState("OFF"); // This publishes an MQTT event to the switch's state topic. Home assistant will show the new state of off.
relayPin.Write(PinValue.Low);

Thread.Sleep(Timeout.Infinite);

This example:

  • Creates a Home Assistant connection over MQTT
  • Adds a switch that responds to Home Assistant commands
  • Adds a temperature sensor that reports values automatically

Configuration

Make sure your Home Assistant installation has the MQTT integration enabled and is configured to allow Auto Discovery.

You can verify this by checking Configuration → Devices & Services → MQTT.

For more details: Home Assistant MQTT Discovery Docs

Entity Types Supported

License

This project is licensed under the MIT License.

Contributing

Contributions, issues, and feature requests are welcome!

Feel free to open an issue or pull request on the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 163 10/9/2025
1.0.0 162 10/8/2025