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!