diff options
| author | Joe Mou <dev@mou.fo> | 2026-07-06 02:47:17 -0400 |
|---|---|---|
| committer | Joe Mou <dev@mou.fo> | 2026-08-11 07:17:05 -0400 |
| commit | 3d06200aff7594e597a9c450bec52bf7cf6ede56 (patch) | |
| tree | c83ee74d2eeaa0751b26575c4877267538c3d909 /hostnix/elmo | |
| parent | 8803fc919c62c813bc595a16daece978856b5b1a (diff) | |
nixfmt home-assistant.nix
Diffstat (limited to 'hostnix/elmo')
| -rw-r--r-- | hostnix/elmo/home-assistant.nix | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/hostnix/elmo/home-assistant.nix b/hostnix/elmo/home-assistant.nix index 4867cc1..80b99a9 100644 --- a/hostnix/elmo/home-assistant.nix +++ b/hostnix/elmo/home-assistant.nix @@ -1,17 +1,62 @@ { lib, pkgs, ... }: +let + + ha = { + trigger = { + at = time: { + platform = "time"; + at = time; + }; + }; + + action = { + on = entity: { + service = "${lib.head (lib.strings.splitString "." entity)}.turn_on"; + target.entity_id = entity; + }; + + off = entity: { + service = "${lib.head (lib.strings.splitString "." entity)}.turn_off"; + target.entity_id = entity; + }; + + toggle = entity: { + service = "${lib.head (lib.strings.splitString "." entity)}.toggle"; + target.entity_id = entity; + }; + }; + + button = entity_id: action: { + inherit action; + alias = "Button ${entity_id}"; + trigger = { + inherit entity_id; + platform = "state"; + to = "on"; + }; + }; + }; + +in { services.postgresql = { ensureDatabases = [ "hass" ]; - ensureUsers = [{ - name = "hass"; - ensureDBOwnership = true; - }]; + ensureUsers = [ + { + name = "hass"; + ensureDBOwnership = true; + } + ]; }; services.home-assistant = { enable = true; - extraPackages = ps: with ps; [ aiohomekit psycopg2 ]; + extraPackages = + ps: with ps; [ + aiohomekit + psycopg2 + ]; extraComponents = [ "apple_tv" "esphome" @@ -26,36 +71,7 @@ tuya_local ]; - config = let - - ha = { - trigger = { - at = time: { - platform = "time"; - at = time; - }; - }; - - action = { - on = entity: { - service = "${lib.head (lib.strings.splitString "." entity)}.turn_on"; - target.entity_id = entity; - }; - - off = entity: { - service = "${lib.head (lib.strings.splitString "." entity)}.turn_off"; - target.entity_id = entity; - }; - - toggle = entity: { - service = "${lib.head (lib.strings.splitString "." entity)}.toggle"; - target.entity_id = entity; - }; - }; - }; - - in - { + config = { default_config = { }; http = { server_host = "::1"; @@ -77,7 +93,7 @@ "light.panel_light" ]; # Parameters modeled at https://basnijholt.github.io/adaptive-lighting/ - min_color_temp = 2700; # lower bound of panel light + min_color_temp = 2700; # lower bound of panel light max_color_temp = 4300; sunrise_offset = 60 * 60; brightness_mode = "linear"; @@ -133,20 +149,7 @@ } ]; - automation = let - - button = entity_id: action: { - inherit action; - alias = "Button ${entity_id}"; - trigger = { - inherit entity_id; - platform = "state"; - to = "on"; - }; - }; - - in - [ + automation = [ { alias = "Depart"; trigger = { @@ -229,7 +232,7 @@ ]; "then" = [ (ha.action.off "climate.bedroom_cool") - { delay = 5; } # allow effect on air_conditioner_1 to settle + { delay = 5; } # allow effect on air_conditioner_1 to settle ]; } @@ -299,7 +302,7 @@ action = [ (ha.action.off "switch.wakko") ]; } - (button "binary_sensor.bedroom_button_1" [ + (ha.button "binary_sensor.bedroom_button_1" [ (ha.action.toggle "light.panel_light") { service = "fan.set_percentage"; @@ -307,8 +310,7 @@ data.percentage = 66; } ]) - (button "binary_sensor.bedroom_button_2" - (ha.action.toggle "switch.wakko")) + (ha.button "binary_sensor.bedroom_button_2" (ha.action.toggle "switch.wakko")) { alias = "Fridge door ajar"; |
