Khome - New kid on the block (home automation library written in Kotlin)

There is a new kid on the block in matters of coding your home assistant automation instead of configuring them via YAML or the user-interface. Let me proudly introduce you to Khome.

Khome is a smart home automation library for Home Assistant, written in Kotlin. It enables you to write your own Home Assistant automation applications, that can observe state changes, listen to events, and much more. Khome was written with safeness in mind. That means we wrote Khome with a fail early approach.

Simple Example:

val KHOME = khomeApplication()

val LivingRoomLuminance = KHOME.LuminanceSensor("livingRoom_luminance")
val LivingRoomMainLight = KHOME.SwitchableLight("livingRoom_main_light")

fun main() {
    LivingRoomLuminance.attachObserver { //this: Actuator<LuminanceState,LuminanceAttributes>
        if (actualState.value < 3.0) {
            LivingRoomMainLight.desiredState = SwitchableState(ON)
        }
    }

    KHOME.runBlocking()
}

In this little example, we observed the luminance sensor in the living room and when the measurement of the luminance drops under 3 lux, we change the state of the main light in the living room to ON. As you can see here, Khome encourages you to think in states rather than services you have to call. This is less error-prone and helps the developer to stay in the mindset of states. This distinguishes Khome from most other automation libraries.

Khome comes with a lot of predefined factory functions, data classes, observers and more for generic entity types but also with a low-level API that lets you develop your own custom entities as needed.

I offer a personal introduction via video chat for those who are interested in Khome to get you started quickly. Just send me a PN. Any constructive critics are welcome. Have a nice weekend all and stay healthy!

5 Likes

Love it, can’t wait to have a play when I can find the time :+1:

1 Like

Hi Dennis, nice impressive work. Can I ask you how to work with mqtt in khome? Should i add any mqtt client library and work with mqtt in classic way or should i use somehow khome rather?

Thx
H.

Hey Honza, thanks for the props. Feel free to add your mqtt lib of choice. Khome wants to be as unopinionated as possible…! Would you see any advantage in having Khome directly integrate MQTT?

May be I’m too young for HA, but how to integrate khome into HA? By creating a jar and wrapping with Docker?