Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phlmn/haah
Home automation at home 🏠
https://github.com/phlmn/haah
home-automation mqtt zigbee zigbee2mqtt
Last synced: 9 days ago
JSON representation
Home automation at home 🏠
- Host: GitHub
- URL: https://github.com/phlmn/haah
- Owner: phlmn
- License: agpl-3.0
- Created: 2020-10-16T16:36:21.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T00:11:02.000Z (28 days ago)
- Last Synced: 2024-10-14T12:19:58.525Z (23 days ago)
- Topics: home-automation, mqtt, zigbee, zigbee2mqtt
- Language: TypeScript
- Homepage:
- Size: 463 KB
- Stars: 5
- Watchers: 4
- Forks: 1
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
> Me: Mom, can we have home automation?
> Mom: No, we have home automation at home
> Home automation at home:# Home automation at home
A library / framework to describe home automation rules as code.Coming from Home Assistant, my roommate and me one day decided that it would be cool to not describe our home automation setup with YAML-files that are created using UI dialogs but rather directly with code.
## Structure / Getting Started
This repository consists of two pieces: the library part of haah (located in `src/`) and the site specific configuration of our flat that also serves as an example of how this library can be used (located in `example/`).If you want to give `haah` a try, simply copy the example folder somewhere and start hacking.
Multiple styles of configuration and multiple things that can be done are used in the example configuration to give you inspiration.
The example configuration mainly uses `zigbee2mqtt` for interacting with the real world and expects that to be started and configured.## Concepts
All home automation is about manipulating some kind of state: If you press a light switch, you change the state of the light. If you turn the knob on your heater, you change its state.Therfore the most central concept of `haah` is a State Slice. State slices can hold state that can be manipulated by sensors (eg. a light switch) and used by actuators (eg. a lamp). So if we want to create a light that can be controlled by a switch, we can do that in the following way with `haah`:
```typescriptconst lampState = state('lampState', {
// ^ this is the name of the state slice
// it must be unique and identifies it
lightOn: false,
// ^ this is the default state.
});mqttSensor('zigbee2mqtt/some_switch', (payload) =>
// ^ this is the mqtt topic of the switch
updateState(lampState, (draft) => {
// ^ we need to call updateState, to notify haah, that we change something.
// this allows haah to automatically execute all Actuators that need to update.
draft.lightOn = !draft.lightOn;
})
)// the mqttActuator is always re-executed, when some state that it uses changed
mqttActuator('zigbee2mqtt/some_lamp/set', () => {
// ^ this is the mqtt topic of the lampif (!lampState.lightOn) {
// the return value is published into the mqtt topic of this actuator
return { state: 'off', brightness: 0, transition: 0 };
} else {
return { state: 'on', brightness: 255, transition: 0 };
}
});
```