![]() |
VOOZH | about |
dotnet add package nf.HomeAssistant.MqttDiscovery --version 1.0.6
NuGet\Install-Package nf.HomeAssistant.MqttDiscovery -Version 1.0.6
<PackageReference Include="nf.HomeAssistant.MqttDiscovery" Version="1.0.6" />
<PackageVersion Include="nf.HomeAssistant.MqttDiscovery" Version="1.0.6" />Directory.Packages.props
<PackageReference Include="nf.HomeAssistant.MqttDiscovery" />Project file
paket add nf.HomeAssistant.MqttDiscovery --version 1.0.6
#r "nuget: nf.HomeAssistant.MqttDiscovery, 1.0.6"
#:package nf.HomeAssistant.MqttDiscovery@1.0.6
#addin nuget:?package=nf.HomeAssistant.MqttDiscovery&version=1.0.6Install as a Cake Addin
#tool nuget:?package=nf.HomeAssistant.MqttDiscovery&version=1.0.6Install as a Cake Tool
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.
You can install the package via NuGet:
nuget install nf.HomeAssistant.MqttDiscovery
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);
// Report the current temperature to Home Assistant
var currentTemperature = GetCurrentTemperature();
temperatureSensor.SetState($"{currentTemperature}");
Thread.Sleep(Timeout.Infinite);
This example:
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
This project is licensed under the MIT License.
Contributions, issues, and feature requests are welcome!
Feel free to open an issue or pull request on the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net net is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.