Kafka ensures automations are durable and state is restored between restarts.
Special note regarding Home Assistant 2024.8:
The latest release brings a couple big kafka improvements. To take full advatage of these new features, some breaking changes are being added to HaKafkaNet.
See : Version 8 and Home Assistant 2024.8
It was created with the following goals:
- Create Home Assistant automations in .NET / C# with abilities to:
- track/retrieve states of all entities in Home Assistant
- respond to Home Assistant state changes
- call Home Assistant RESTful services
- Enable all automation code to be fully unit testable
Example of multiple durable automations. See Tutorial for more examples.
registrar.RegisterMultiple(
_factory.SunRiseAutomation(
cancelToken => _api.TurnOff("light.night_light", cancelToken)),
_factory.SunSetAutomation(
cancelToken => _api.TurnOn("light.night_light", cancelToken),
TimeSpan.FromMinutes(-10))
);
- Documentation
- Nuget package
- Join the new Discord Server
- Strongly typed access to entities
- Durable - Automations that survive restarts. See also Event Timings
- Fast - Automations run in parallel and asynchronously.
- UI to manage your automations and inspect Kafka consumers.
- Observability through
- Pre-built automations
- Extensible framework - create your own reusable automations
- Extend automation factory with extension methods
- Create your own automamtions from scratch
- Automation builder with fluent syntax for quickly creating automations.
- Full unit testability and componet level testing with Test Harness
- MIT license
This is an image of the dashboard from the example app. See UI for additional details.
- State changes are sent from Home Assistant to a Kafka topic
- HaKafkaNet reads all state changes
- States for every entitiy allowing for faster retrieval later. It also allows us to have some knowledge about which events were not handled between restarts and which ones were. The framework will tell your automation about such timings to allow you to handle messages appropriately.
- It then looks for automations which want to be notified.
- If the entity id of the state change matches any of the
TriggerEntityIds
exposed by your automation, and the timing of the event matches your specified timings, then theExecute
method of your automation will be called with a newTask
. - It is up to the consumer to handle any errors. The framework prioritizes handling new messages speedily over tracking the state of individual automations. If your automation errors, an ILogger message will be written indicating the error.
- If the entity id of the state change matches any of the
I have made my personal repository public so that users can see working examples of some moderately complex automations.
If you have some examples you would like to share, please start a discussion. I'd be happy to link it here.
Happy Automating!