Repository navigation
Configuration
You have two options for configuring HaKafkaNet in your program.cs. The example app shows both methods.
The first option is to copy the appsettings.json file from the example app into your project. When you do that, registration in your 'proram.cs' should look as follows:
HaKafkaNetConfig config = new HaKafkaNetConfig();
builder.Configuration.GetSection("HaKafkaNet").Bind(config);
services.AddHaKafkaNet(config);Below is an example of what your appsetting.json file might look like. NLog is included for log tracing.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"MyHome": "Debug"
}
},
"NLog":{
"rules":[
{
"logger": "Microsoft.*",
"minLevel": "Warn",
"finalMinLevel":"Warn"
},
{
"logger": "System.Net.*",
"minLevel": "Warn",
"finalMinLevel":"Warn"
},
{
"logger": "HaKafkaNet.*",
"minLevel": "Debug",
"finalMinLevel": "Debug"
},
{
"logger": "MyHome.*",
"minLevel": "Debug",
"finalMinLevel":"Debug"
},
]
},
"AllowedHosts": "*",
"HaKafkaNet": {
"KafkaBrokerAddresses": ["<ip of your kafka instance>:9094"],
"KafkaTopic": "home_assistant_states",
"ExposeKafkaFlowDashboard" : true,
"UseDashboard": true,
"StateHandler":{
"GroupId": "hakafkanet-consumer-example",
"BufferSize" : 5,
"WorkerCount": 5
},
"HaConnectionInfo":{
"BaseUri": "http://<ip of your HA instance>:8123",
"AccessToken": "YOUR_LONG_LIVED_HA_ACCESSTOKEN"
}
}
}
Alternatively, you can configure your instance programmatically. When you choose this option you must provide your own configuration.
services.AddHaKafkaNet(options =>{
//minimum amount of config
options.KafkaBrokerAddresses = ["your kafka instance"];
options.HaConnectionInfo.AccessToken = "your access token";
options.HaConnectionInfo.BaseUri = "your Home Assistant location";
//set additional options
});The above snippet demonstrates the minimum amount of configuration needed. You can override any defaults listed below.
Below are the definitions of the HaKafaNet config object
string[] - required - defaults to ["localhost:9094"]
An array of addresses in your cluster. Only one is needed as demonstrated in the example.
string - required
This is the topic that HaKafkaNet will read from. It should be the same as configured in the Home Assistant Kafka integration.
bool - defaults to true
When set to true, the Kafkaflow endpoint is set up at ~/kafkaflow
bool - defaults to false
When set to true, the HaKafakaNet dashboard is set up at ~/dasboard.html
object
Settings used by the State Handler
string - defaults to "hakafkanet-consumer"
Change this value if you want to have multiple environments running against the same cluster
int - defaults to 5
int - defaults to 5
See KafkaFlow documentation for details.
object - required
Note: this used to be labled
API. Please useHaConnectionInfoinstead. Future versions will not support the old name.
string - required
The URI for your Home Assistant instance. e.g. http://homeassistant.local:8123
string - required
A long lived access token for connecting to Home Assistant.