Kortex - Kotlin Multiplatform client toolkit for Home Assistant

Hello everyone!

I’d like to introduce Kortex - Kotlin Multiplatform client toolkit for Home Assistant.

The goal of Kortex is to make it easy for Kotlin developers to build reactive Home Assistant clients and tools across multiple platforms such as:

  • Android
  • Desktop
  • iOS
  • Web (future)
  • Embedded devices

It provides a type-safe and observable API for interacting with Home Assistant entities.

Current Features

Even though the project is at the very early stage, it already includes:

  1. Communication via WebSocket API

  2. Service calls

  3. Observable entity model
    Entities expose reactive state updates so you can easily react to changes.

  4. Supported entities

  • BinarySensor
  • Button
  • Calendar
  • Cover
  • DeviceTracker
  • Fan
  • Image
  • Light
  • MediaPlayer
  • Number
  • Person
  • Sensor
  • Switch
  • Timer
  • Zone
  1. Compose Multiplatform integration
    A small helper library that integrates with Compose using collectAsState.

Examples usage:

Native usage:

  startKortexObservable { entities ->
      val lights = entities.lights
      val scope = CoroutineScope(currentCoroutineContext())
      
      val tablePrinter = StatusTablePrinter(lights)

      tablePrinter.render()

      lights.forEach { light ->
          light.onToggled(scope) {
              tablePrinter.updateStatus(entityId, state)
          }
      }
  }

Compose UI:

  KortexApplication(token, host) {

      val state = LocalKortexApplication.current

      when {
          state.error != null -> {
              Text(state.error!!)
          }

          state.isLoading -> {
              Box(
                  modifier = Modifier.fillMaxSize(),
                  contentAlignment = Alignment.Center
              ) {
                  CircularProgressIndicator()
              }
          }

          else -> {
              HomeAssistant(state)
          }
      }
  }

Planned Features

Some ideas for future development:

  • Automation interaction
  • Full WebSocket API coverage
  • More Compose UI components for dashboards

Why Kotlin?

Kotlin Multiplatform allows writing shared code across Android, iOS, desktop, and web. Compose UI support is making it a great fit for building cross-platform Home Assistant tools and dashboards.

Contributions & Feedback

The project is still very early, so feedback, ideas, and contributions are highly welcome.

If you’re interested, check out the repository:

I’d love to hear:

  • what features you would like
  • what would make this useful for your projects
  • suggestions for the API design

Thanks!

1 Like

Hello everyone!

I made few more commits.

Extended supported entities:

  • BinarySensor
  • Button
  • Calendar
  • Climate - support toggleable actions
  • Cover
  • DeviceTracker
  • Fan
  • Image
  • Light
  • MediaPlayer
  • Number
  • Person
  • Select - Compose UI example with Dropdown
  • Sensor
  • Switch
  • Timer
  • Vacuum
  • Zone

It look good for a Multiplatform Companion.

Only allow read values or do you can create sensors/devices too?

So far - only readonly, with state change possibility (callService).
If the create feature is demanded - I will check how to implement it. Should be possible.

How is auth handled

Right now via long-lived token. Here is an info how to generate it. Here is more technical info about it.
Didn’t find a way, how to use login/password pair yet.

So, I added new targets and fixed all non-multiplatform usages.

The biggest problem was configuration. I still use Typesafe Config for JVM. For native targets, I wrote my own solution (not fully tested yet), but it should be sufficient for now.

Kortex now supports:

  • JVM
  • Linux x64 / ARM64
  • MinGW x64
  • macOS x64 / ARM64
  • JS (browser / Node.js)
  • iOS x64 / ARM64
  • iOS Simulator ARM64

I also added a GitHub Action to publish to Maven (tested — it works), but I want to add more entities and tests before the first release.

I would still really appreciate any ideas, suggestions, or contributions.

Hi there!

Finilly had time to improve Kortex.
Changes:

  • Rename Entity to EntityState

Added:

  • New Requests:
    • Devices
    • Entities

So far, requests can be done by developer and don’t happen automatically.

I would still really appreciate any ideas, suggestions, or contributions.

Hi there!

Slightly updated Kortex.
Added:

  • Abstract PressableEntity class
  • New entity InputButton inherited from PressableEntity
  • Add new InputButton tab into ComposeUI Simple Application

Changes:

  • Button inheritens PressableEntity now

I would still really appreciate any ideas, suggestions, or contributions.