Project template for developing a Home Assistant add-on in C# .
Application to deliver device and sensor to MQTT integration
There are three different methods
- Use Docker images registered in GitHub Container Registory
- Copy
/_from_ghcr.io(config.yaml only) to HA-OS (/addons/example-mqtt)
- Copy
- .NET apps pre-compiled and then build a Docker image on HA-OS
- Run
./_compile_self/dotnet_publish.ps1. - Copy
/_compile_selfto HA-OS (/addons/example-mqtt)
- Run
- .NET apps at the same time as building Docker images on HA-OS
- Copy
srcand/_build_on_haosto HA-OS (/addons/example-mqtt) - If the HA-OS machine is not powerful, the build (& installation) will take a very long time.
(At RasPi3B+, it takes more than 30 minutes.)Not recommended.
- Copy
./_compile_self/dotnet_publish.ps1
docker build `
"./_compile_self" `
-t ghcr.io/EXAMPLE_GIT_HUB_USER/examplemqtt-aarch64:1.0.3 `
--build-arg BUILD_FROM="ghcr.io/home-assistant/aarch64-base:latest" `
--build-arg BUILD_ARCH="aarch64" `
--progress=plain `
--label org.opencontainers.image.source=https://github.com/EXAMPLE_GIT_HUB_USER/examplemqtt-mqtt
docker build `
"./_compile_self" `
-t ghcr.io/EXAMPLE_GIT_HUB_USER/examplemqtt-amd64:1.0.3 `
--build-arg BUILD_FROM="ghcr.io/home-assistant/amd64-base:latest" `
--build-arg BUILD_ARCH="amd64" `
--progress=plain `
--label org.opencontainers.image.source=https://github.com/EXAMPLE_GIT_HUB_USER/examplemqtt-mqtt
docker build `
"./_compile_self" `
-t ghcr.io/EXAMPLE_GIT_HUB_USER/examplemqtt-armv7:1.0.3 `
--build-arg BUILD_FROM="ghcr.io/home-assistant/armv7-base:latest" `
--build-arg BUILD_ARCH="armv7" `
--progress=plain `
--label org.opencontainers.image.source=https://github.com/EXAMPLE_GIT_HUB_USER/examplemqtt-mqtt
echo EXAMPLE_GIT_HUB_PERSONAL_ACCESS_TOKEN | docker login ghcr.io -u EXAMPLE_GIT_HUB_USER --password-stdin
docker push ghcr.io/EXAMPLE_GIT_HUB_USER/examplemqtt-aarch64:1.0.3
docker push ghcr.io/EXAMPLE_GIT_HUB_USER/examplemqtt-amd64:1.0.3
docker push ghcr.io/EXAMPLE_GIT_HUB_USER/examplemqtt-armv7:1.0.3| Key | Default | Description |
|---|---|---|
| Interval | 00:01:10 |
TimeSpan(HH:mm:ss) |
| Mqtt:UseAutoConfig | true | Add-on users using the default Home Assistant Mosquitto integration can set this value to True, as connection details can be detected via the Home Assistant Supervisor API. |
| Mqtt:Host | - | |
| Mqtt:Port | - | |
| Mqtt:Id | - | |
| Mqtt:Pw | - | |
| Mqtt:Tls | - | |
| LogLevel | Trace |
Trace,Debug,Information,Warning,Error,Critical,None |
- This add-on simply brings the .NET runtime into the Home Assistant base image and launches the .NET console application.
- The application itself can be run on Windows.
- The sln file can be opened in VisualStudio and debugged.
- On Windows, you probably do not have access to the add-on configuration file(
/data/options.json), so configure them inappsettings.Development.jsoninstead. - Can also be configured from environment variables and command line arguments.
See. .NET Generic Host Default builder settings



