For your convenience, Hassle comes with a lot of predefined factory functions, data classes, observers and more for generic entity types.
Helpers in home assistant are part of the automation integrations. Some of those are represented as entities, therefore you can use them in Hassle.
The input_boolean integration allows the user to define boolean values that can be controlled via the frontend and can be used within conditions of automation. See home assistant documentation for more.
Element | Name | Source | KDocs |
---|---|---|---|
Factory | HomeAssistantApiClient::InputBoolean | Link | Link |
State | SwitchableState | Link | Link |
StateValue | SwitchableValue | Link | Link |
Attributes | InputBooleanAttributes | Link | Link |
Example:
val client = homeAssistantApiClient(...)
val sleepMode: InputBoolean = client.InputBoolean(ObjectId("sleep_mode"))
sleepMode.attachObserver { //this:Actuator<InputBooleanState,SwitchableSettableState>
if (state.value == SwitchableValue.ON) {
//... turn off lights, close covers, activate the alarm, etc.
}
}
val <S : State<SwitchableValue>> Actuator<S, *>.isOn
Is true when the actual state value is equal to SwitchableValue.ON
.
val <S : State<SwitchableValue>> Actuator<S, *>.isOff
Is true when the actual state value is equal to SwitchableValue.OFF
.
suspend fun Actuator<*, SwitchableSettableState>.turnOn()
Since in Home Assistant InputBoolean states are ON and OFF, you can "turn on" the InputBoolean-Helper by calling this method resulting in a state change.
suspend fun Actuator<*, SwitchableSettableState>.turnOff()
Since in Home Assistant InputBoolean states are ON and OFF, you can "turn off" the InputBoolean-Helper by calling this method.
inline fun <S : State<SwitchableValue>> Actuator<S, *>.onTurnedOn(
crossinline f: Actuator<S, *>.(Switchable) -> Unit,
)
The passed lambda gets executed when the state of the InputBoolean entity switches from OFF to ON. Inside the lambda you have access to all properties and members of your entity.
inline fun <S : State<SwitchableValue>> Actuator<S, *>.onTurnedOff(
crossinline f: Actuator<S, *>.(Switchable) -> Unit,
)
The passed lambda gets executed when the state of the InputBoolean entity switches from ON to OFF. Inside the lambda you have access to all properties and members of your entity.
The input_number integration allows the user to define values that can be controlled via the frontend and can be used within conditions of automation. The frontend can display a slider, or a numeric input box. Changes to the slider or numeric input box generate state events. These state events can be utilized as automation triggers as well. See home assistant documentation for more.
Element | Name | Source | KDocs |
---|---|---|---|
Factory | HomeAssistantApiClient::InputNumber | Link | Link |
State | InputNumberState | Link | Link |
StateValue | Double | - | - |
SettableState | InputNumberSettableState | Link | Link |
Example:
val client = homeAssistantApiClient(...)
val maxVolume: InputNumber = client.InputNumber(ObjectId("max_volume"))
val googleHomeKitchen: MediaReceiver = client.MediaReceiver(ObjectId("google_home_kitchen"))
googleHomeKitchen.attachObserver { //this:Actuator<InputNumberState, InputNumberAttributes>
if (state.value <= 10.0) {
//... turn off lights, close covers, activate the alarm, etc.
}
}
The input_text integration allows the user to define values that can be controlled via the frontend and can be used within conditions of automation. Changes to the value stored in the text box generate state events. These state events can be utilized as automation triggers as well. It can also be configured in password mode (obscured text). See home assistant documentation for more.
...
...
...
The input_select integration allows the user to define a list of values that can be selected via the frontend and can be used within conditions of automation. When a user selects a new item, a state transition event gets generated. This state event can be used in an automation trigger. See home assistant documentation for more.
...
...
...
The input_datetime integration allows the user to define date and time values that can be controlled via the frontend and can be used within automations and templates. See home assistant documentation for more.
...coming soon!
...coming soon!