GithubHelp home page GithubHelp logo

cybernetics / khome Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dennisschroeder/khome

0.0 2.0 0.0 1.19 MB

Khome is a smart home automation library for Home Assistant written in Kotlin.

License: MIT License

Kotlin 100.00%

khome's Introduction

GitHub Actions status LINE

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 first approach. See more about this in the "Safety's first Section".

Simple Example:

val KHOME = khomeApplication()

val LivingRoomMotion = KHOME.LuminanceSensor("livingRoom_motion")
val LivingRoomMainLight = KHOME.SwitchableLight("livingRoom_main_light")

fun main() {
    LivingRoomMotion.attachObserver { //this: Sensor<SwitchableState,MotionSensorAttributes>
        if (measurement.value == SwitchableValue.ON) {
            LivingRoomMainLight.desiredState = SwitchableState(ON)
        }
    }

    KHOME.runBlocking()
}

In this little example, we observed the motion sensor in the living room and when the sensors motion alarm turns to on, 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. To achieve the same result than shown above, we can also use Khomes higher-level API which lets you write concise code.

val KHOME = khomeApplication()

val LivingRoomMotion = KHOME.LuminanceSensor("livingRoom_motion")
val LivingRoomMainLight = KHOME.SwitchableLight("livingRoom_main_light")

fun main() {
    LivingRoomMotion.onMotionAlarm { //this: LuminanceSensor
        LivingRoomMainLight.turnOn()
    }

    KHOME.runBlocking()
}

Home Assistant

HA is an open-source home-automation platform written in Python 3 that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.

If you're not already familiar with Home Assistant, you find all you need on the Getting Started page.

Warning

This project is in an early state. You can't rely on it yet. But I encourage you to test it and report issues. Changes in the API, removal of features, or other changes will occur. Of course, contributions are also very welcome.

If you are from...

... the Kotlin World:

Since Home Assistant is written in Python 3, you may ask yourself if you need to write Python code on the Home Assistant side. But you don't have to. All you need to do is configuring it via .yaml files and/or the user interface. But you need to install and run it on your own server. There is plenty of information and tutorials on the web to support you with that. Google will help you. Also, there is a Discord channel to get in touch easily with the community.

... the Python World:

Yes, you need to learn Kotlin. It is definitely worth a try. In my opinion, it is worth even more. But that's a different story. Probably the fastest way for you to get into Kotlin is the Kotlin for Python Introduction from the official Kotlin documentation. Here is a list of the most important Kotlin online resources.

Installation

Home Assistant

Further information on this topic is available on the official Home Assistant Documentation page.

Khome

For now, you can use Jitpack to install Khome locally. Just add the following lines to your build.gradle or maven file.

Gradle

repositories {
    // ...
    maven { url "https://jitpack.io" }
}
dependencies {
    // ...
    implementation 'com.github.dennisschroeder:khome:${replace with a version}'
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
        <groupId>com.github.dennisschroeder</groupId>
        <artifactId>khome</artifactId>
        <version>${replace with a version}</version>
</dependency>

Documentation

Khome has no opinion on how you want to run your application, what other libraries or pattern you choose, or what else is best for what you like to build. All Khome needs is a Kotlin environment to run properly.

Again, if you are new to Kotlin, you might check out Getting Started with IntelliJ IDEA or Working with the Command Line Compiler. I recommend using Kotlin with Intellij IDEA to get started. It's the best way to get into it. You can download the free Community Edition from JetBrains.

Working with Khome

Credits

Even though the idea to build Khome and the implementation was made by me, you'll find the word "we" quite often in the documentation. That is because I had the pleasure to work with Tobias Hermann on this project who served me as a sparring partner by challenging my ideas and design decisions, introducing new ideas and designs, reviewing some parts of the code, and an overall consultant in the field of software engineering. So using I in the documentation would just be incorrect.

Therefore, a special thank goes out to Tobias.

Check out his awesome work, especially frugally-deep, functionalPlus, and his thoughts on programming. Oh and leave a star or two ;-).

khome's People

Contributors

dennisschroeder avatar dobiasd avatar renovate-bot avatar renovate[bot] avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.