From bd3c7c090eea5c88836946bb1b4425ffbba295a9 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Mon, 17 Jan 2022 04:04:07 +0000 Subject: [PATCH] totoro: add HA config --- ops/nixos/totoro/home-assistant.nix | 83 +++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/ops/nixos/totoro/home-assistant.nix b/ops/nixos/totoro/home-assistant.nix index 08cb1ae5cd..72417e4374 100644 --- a/ops/nixos/totoro/home-assistant.nix +++ b/ops/nixos/totoro/home-assistant.nix @@ -35,6 +35,89 @@ in { cast = {}; plex = {}; default_config = {}; + + google_assistant = { + project_id = "malden-homeassistant"; + service_account = secrets.homeAssistant.googleServiceAccount; + report_state = true; + exposed_domains = [ + "light" + ]; + }; + + scene = let + bedroomOverhead = x: ({ + color_mode = "color_temp"; + brightness = 255; + color_temp = 316; + } // x); + bedroomRing = x: ({ + color_mode = "color_temp"; + brightness = 69; + color_temp = 142; + } // x); + entityDefs = ring: overhead: let o = bedroomOverhead { state = overhead; }; in { + "light.bedside_lamp" = bedroomRing { state = ring; }; + "light.overhead_left_1" = o; + "light.overhead_left_2" = o; + "light.overhead_left_3" = o; + "light.overhead_left_4" = o; + "light.overhead_right_1" = o; + "light.overhead_right_2" = o; + "light.overhead_right_3" = o; + "light.overhead_right_4" = o; + }; + in [{ + name = "Bedroom Reset"; + entities = entityDefs "off" "on"; + } { + name = "Bedroom Off"; + entities = entityDefs "off" "off"; + }]; + + automation = let + base = extra: alias: webhook_id: ({ + inherit alias; + trigger = [{ + inherit webhook_id; + platform = "webhook"; + }]; + } // extra); + toggleEntity = entity_id: base { + action = [{ + service = "homeassistant.toggle"; + target.entity_id = entity_id; + }]; + }; + playPauseEntity = entity_id: base { + action = [{ + service = "media_player.media_play_pause"; + target.entity_id = entity_id; + }]; + }; + scene = scene_entity_id: base { + action = [{ + service = "scene.turn_on"; + target.entity_id = scene_entity_id; + data.transition = 1.0; + }]; + }; + in [ + (toggleEntity "light.bedroom_lights" "Desk LHS Switch press - toggle room" "flic_desk_lhs") + (scene "scene.bedroom_reset" "Desk LHS Switch hold - reset room" "flic_desk_lhs_hold") + + (toggleEntity "light.bedside_lamp" "Desk RHS Switch press - toggle bedside" "flic_desk_rhs") + + (toggleEntity "light.bedroom_lights" "Bed LHS Switch press - toggle room" "flic_bed_lhs") + (scene "scene.bedroom_reset" "Bed LHS Switch dblpress - reset room" "flic_bed_lhs_dbl") + (scene "scene.bedroom_off" "Bed LHS Switch dblpress - reset room" "flic_bed_lhs_hold") + + (playPauseEntity "media_player.nebula" "Bed RHS Switch press - play/pause nebula" "flic_bed_rhs") + + (toggleEntity "light.bedroom_lights" "Bedroom Door Switch press - toggle room" "flic_bedroom_door") + (scene "scene.bedroom_off" "Bedroom Door Switch dblpress - room off" "flic_bedroom_door_dbl") + (scene "scene.bedroom_off" "Bedroom Door Switch hold - room off" "flic_bedroom_door_hold") + ]; }; lovelaceConfig = { title = "117 Malden Road";