Harmony.HomeAssistant
0.1.3
dotnet add package Harmony.HomeAssistant --version 0.1.3
NuGet\Install-Package Harmony.HomeAssistant -Version 0.1.3
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="Harmony.HomeAssistant" Version="0.1.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Harmony.HomeAssistant" Version="0.1.3" />
<PackageReference Include="Harmony.HomeAssistant" />
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 Harmony.HomeAssistant --version 0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Harmony.HomeAssistant, 0.1.3"
#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 Harmony.HomeAssistant@0.1.3
#: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=Harmony.HomeAssistant&version=0.1.3
#tool nuget:?package=Harmony.HomeAssistant&version=0.1.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Harmony.HomeAssistant
Nowoczesna / modern .NET 8 library for Home Assistant (WebSocket + REST + Streaming).
Features
- WebSocket: authentication, full state snapshot, individual & all-event subscriptions, call_service, fire_event, config flows, ping keep-alive, reconnect
- REST: states CRUD, services, events, config, history, logbook, template, intent, calendars, system health, registries (area/device/entity/zone/person), config entries, statistics, energy, camera snapshot & MJPEG
- SSE:
/api/streamevent stream alternative - Camera: MJPEG streaming (
IAsyncEnumerable<byte[]>) - Typed registry model helpers (Area, Device, Entity, Zone, Person)
Instalacja
Install-Package Harmony.HomeAssistant
Quick start
var parameters = new ConnectionParameters
{
WebSocketEndpoint = new Uri("ws://homeassistant.local:8123/api/websocket"),
AccessToken = "LONG_LIVED_TOKEN"
};
var services = new ServiceCollection()
.AddLogging(b => b.AddConsole())
.AddHomeAssistant(parameters)
.BuildServiceProvider();
var client = services.GetRequiredService<IHomeAssistantClient>();
await client.ConnectAsync();
await client.CallServiceAsync("light", "turn_on", new JsonObject { ["entity_id"] = "light.kitchen" });
Streaming (MJPEG)
await foreach (var frame in rest.GetCameraStreamAsync("camera.front")) { /* handle frame */ }
SSE
var stream = services.GetRequiredService<IHomeAssistantEventStream>();
await foreach (var evt in stream.ReadEventsAsync()) Console.WriteLine(evt.Type);
Typed registries
var zones = (await rest.ListZonesAsync()).ToZones();
Documentation
Additional focused docs:
- Configuration:
docs/configuration.md - Resilience:
docs/resilience.md - Observability:
docs/observability.md - Testing:
docs/testing.md
Roadmap (summary)
- Typed History / Logbook / Statistics helpers
- Service invocation documentation & examples
Optional: Resilience + metrics
Enable retry + metrics:
services.AddHomeAssistantClient(p =>
{
p.WebSocketEndpoint = new Uri("ws://homeassistant.local:8123/api/websocket");
p.AccessToken = token;
}, opts =>
{
opts.EnableResilience = true; // domyślnie true
opts.HttpRetryCount = 5; // exponential backoff (2^n * base)
opts.HttpRetryBaseDelay = TimeSpan.FromMilliseconds(150);
opts.EnableMetrics = true; // domyślnie true
});
Metrics (System.Diagnostics.Metrics):
- ha_rest_calls (Counter) tags: endpoint, method, status
- ha_rest_call_latency_ms (Histogram)
- ha_service_calls (Counter) tags: domain, service
- ha_service_call_latency_ms (Histogram)
OpenTelemetry integration example:
services.AddOpenTelemetry()
.WithMetrics(b => b
.AddMeter("Harmony.HomeAssistant")
.AddPrometheusExporter());
Tracing (ActivitySource / OpenTelemetry)
Default enabled unless you set EnableTracing = false.
Spans:
- ha.rest (Client) – tags: http.method, ha.endpoint, ha.result.size (optional), status
- ha.service.call (Client) – tags: ha.domain, ha.service, ha.result.success
Register source in OTEL:
services.AddOpenTelemetry()
.WithTracing(b => b
.AddSource("Harmony.HomeAssistant")
.AddConsoleExporter());
Default options (HomeAssistantClientOptions)
| Option | Default | Description |
|---|---|---|
| EnableResilience | true | Enables retry (+ circuit breaker if enabled). |
| HttpRetryCount | 3 | Retry attempts (exponential backoff). |
| HttpRetryBaseDelay | 200ms | Base delay for first retry. |
| EnableCircuitBreaker | true | Adds circuit breaker. |
| CircuitBreakerFailures | 5 | Failures to open circuit. |
| CircuitBreakerDuration | 30s | Open duration. |
| EnableMetrics | true | Emits Meter instruments. |
| EnableTracing | true | Emits ActivitySource spans. |
| SharedMeter | null | Inject external Meter. |
| SharedActivitySource | null | Use external ActivitySource. |
You can override only what you need via the configureOptions delegate.
Versioning (SemVer)
- 0.1.0 Public preview
- 0.1.x Bugfix + minor typed models / docs
- 0.2.0 Additional typed layers / enhancements
Changelog
See CHANGELOG for detailed version history.
Contributing
See CONTRIBUTING.md:
- Fork + branch
dotnet testmust pass- Tag
vX.Y.Ztriggers publish workflow (requiresNUGET_API_KEYsecret)
License
MIT (see LICENSE)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Polly (>= 8.2.0)
- Polly.Extensions.Http (>= 3.0.0)
- System.Reactive (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.