From ae174de04da8b8a11bf9c155ed7f2c07ea1eb9bb Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Fri, 26 Aug 2022 17:45:13 +0200 Subject: [PATCH] Home Assistant security system bringup Signed-off-by: Magic_RB Update flake.lock Signed-off-by: Magic_RB wip!! Signed-off-by: Magic_RB wip!!! Signed-off-by: Magic_RB wip!!! Signed-off-by: Magic_RB wip!!!! Signed-off-by: Magic_RB wip!!!!! Signed-off-by: Magic_RB wip!!!!!! Signed-off-by: Magic_RB wip!!!!!!! Signed-off-by: Magic_RB --- containers/home-assistant.nix | 9 +++++- .../home-assistant/alarm_control_panel.nix | 17 ++++++++++ .../automations/alarm/disarmed.nix | 20 ++++++++++++ .../automations/alarm/motion-detected.nix | 31 +++++++++++++++++++ .../automations/alarm/pending.nix | 19 ++++++++++++ .../automations/alarm/triggered.nix | 20 ++++++++++++ flake.lock | 24 +++++++------- 7 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 containers/home-assistant/alarm_control_panel.nix create mode 100644 containers/home-assistant/automations/alarm/disarmed.nix create mode 100644 containers/home-assistant/automations/alarm/motion-detected.nix create mode 100644 containers/home-assistant/automations/alarm/pending.nix create mode 100644 containers/home-assistant/automations/alarm/triggered.nix diff --git a/containers/home-assistant.nix b/containers/home-assistant.nix index fd60100..5f722d3 100644 --- a/containers/home-assistant.nix +++ b/containers/home-assistant.nix @@ -29,7 +29,7 @@ nglib.makeSystem { sha256 = "sha256-RSIJqsbgnktl7zNaxAKUoMjbkrJ1aJTej0vjlCgstJ8="; } + "/custom_components/xiaomi_gateway3"; }; - config = with { inherit (builtins) toString; }; + config = { default_config = {}; http = { server_port = "8123"; @@ -48,6 +48,13 @@ nglib.makeSystem { internal_url = "http://localhost:8123/"; }; automation = "!include automations.yaml"; + "automation static" = [ + (import ./home-assistant/automations/alarm/pending.nix) + (import ./home-assistant/automations/alarm/disarmed.nix) + (import ./home-assistant/automations/alarm/triggered.nix) + (import ./home-assistant/automations/alarm/motion-detected.nix) + ]; + alarm_control_panel = import ./home-assistant/alarm_control_panel.nix; frontend.themes = { }; }; diff --git a/containers/home-assistant/alarm_control_panel.nix b/containers/home-assistant/alarm_control_panel.nix new file mode 100644 index 0000000..53708fe --- /dev/null +++ b/containers/home-assistant/alarm_control_panel.nix @@ -0,0 +1,17 @@ +{ + platform = "manual"; + name = "Home Alarm"; + code = "\${ALARM_CODE}"; + code_arm_required = false; # Don't need code to arm. + disarm_after_trigger = false; # Leave alarm armed after triggering. + arming_time = 30; # Time to leave the house after arming. + delay_time = 60; # Time to turn off after entering the house. + trigger_time = 600; # How long the alarm goes off for. + disarmed = { + trigger_time = 0; # Can't be triggered when disarmed. + }; + armed_home = { + arming_time = 0; # Arm instantly when at home. + delay_time = 0; # Trigger instantly when at home. + }; +} diff --git a/containers/home-assistant/automations/alarm/disarmed.nix b/containers/home-assistant/automations/alarm/disarmed.nix new file mode 100644 index 0000000..4900549 --- /dev/null +++ b/containers/home-assistant/automations/alarm/disarmed.nix @@ -0,0 +1,20 @@ +{ + alias = "Alarm - Disarmed"; + id = "a8c26d1c-3a71-4a99-b0f3-dc799495a706"; + + trigger = [ + { + entity_id = "alarm_control_panel.home_alarm"; + platform = "state"; + to = "disarmed"; + } + ]; + action = [ + { + data = { + message = "Alarm Disarmed"; + }; + service = "notify.mobile_app_redrum"; + } + ]; +} diff --git a/containers/home-assistant/automations/alarm/motion-detected.nix b/containers/home-assistant/automations/alarm/motion-detected.nix new file mode 100644 index 0000000..d65e1b1 --- /dev/null +++ b/containers/home-assistant/automations/alarm/motion-detected.nix @@ -0,0 +1,31 @@ +{ + alias = "Alarm - Trigger when motion detected"; + id = "972bccd8-a68c-48fc-ac90-ebbeb87c64b9"; + + trigger = { + platform = "state"; + entity_id = "binary_sensor.sensor_entry_door_contact"; + to = "on"; + }; + condition = { + condition = "or"; + conditions = [ + { + condition = "state"; + entity_id = "alarm_control_panel.home_alarm"; + state = "armed_home"; + } + { + condition = "state"; + entity_id = "alarm_control_panel.home_alarm"; + state = "armed_away"; + } + ]; + }; + action = [ + { + service = "alarm_control_panel.alarm_trigger"; + entity_id = "alarm_control_panel.home_alarm"; + } + ]; +} diff --git a/containers/home-assistant/automations/alarm/pending.nix b/containers/home-assistant/automations/alarm/pending.nix new file mode 100644 index 0000000..a30588a --- /dev/null +++ b/containers/home-assistant/automations/alarm/pending.nix @@ -0,0 +1,19 @@ +{ + alias = "Alarm - Pending"; + id = "e4771f5a-1205-4fbe-9142-6a56600d7bd4"; + + trigger = [ + { + entity_id = "alarm_control_panel.home_alarm"; + from = "armed_away"; + platform = "state"; + to = "pending"; + } + ]; + action = [ + { + data = { message = "Alarm Pending - Intruder Detected!"; }; + service = "notify.mobile_app_redrum"; + } + ]; +} diff --git a/containers/home-assistant/automations/alarm/triggered.nix b/containers/home-assistant/automations/alarm/triggered.nix new file mode 100644 index 0000000..2aea838 --- /dev/null +++ b/containers/home-assistant/automations/alarm/triggered.nix @@ -0,0 +1,20 @@ +{ + alias = "Alarm - Triggered"; + id = "6b9c6dac-2c6b-4add-b499-8e2b134e5d9c"; + + trigger = [ + { + entity_id = "alarm_control_panel.home_alarm"; + platform = "state"; + to = "triggered"; + } + ]; + action = [ + { + data = { + message = "Alarm Triggered - Motion Detected!"; + }; + service = "notify.mobile_app_redrum"; + } + ]; +} diff --git a/flake.lock b/flake.lock index 371507e..655732c 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1650374345, - "narHash": "sha256-YprUqDDomOackDUuVvXSeVQwjekXtoZSjLi0x2XjKes=", - "ref": "master", - "rev": "bc20eb7c20b906ee4fc6a936da7370d00f2c2739", - "revCount": 42, + "lastModified": 1641345147, + "narHash": "sha256-2DwiEp/pxQ/gIMlJyYOM/q2sEXaJ4LYqhdvW9TrFjpA=", + "ref": "refs/heads/master", + "rev": "67759ba6aede849780dcedcc3b316ccc1c0084b0", + "revCount": 39, "type": "git", "url": "https://gitea.redalder.org/ThyW/camptules" }, @@ -75,11 +75,11 @@ ] }, "locked": { - "lastModified": 1659246221, - "narHash": "sha256-+d2E6e9So3swU3N5l6Dylb02qiwizevip6wPiWLDRSs=", + "lastModified": 1659247306, + "narHash": "sha256-7HnMAj+OzChKVZWp5bqnTTXfKsGSIymryLOHek0bDBE=", "owner": "nix-community", "repo": "NixNG", - "rev": "7f30b8b20f5a4bcdf4b6350be22da623da237fb4", + "rev": "043a9a5353501b017adaa3730f09074d2f4c9514", "type": "github" }, "original": { @@ -107,11 +107,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1659077768, - "narHash": "sha256-P0XIHBVty6WIuIrk2DZNvLcYev9956y1prT4zL212H8=", + "lastModified": 1661361016, + "narHash": "sha256-Bjf6ZDnDc6glTwIIItvwfcaeJ5zWFM6GYfPajSArdUY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "2a93ea177c3d7700b934bf95adfe00c435f696b8", + "rev": "b784c5ae63dd288375af1b4d37b8a27dd8061887", "type": "github" }, "original": { @@ -190,7 +190,7 @@ "locked": { "lastModified": 1641601042, "narHash": "sha256-Nqz5fYUaCdrj7GmpONqsMxKP3GM/11btYEPtbm0p66w=", - "ref": "master", + "ref": "refs/heads/master", "rev": "9a678533ce1d3a550ccba39fc6cc86b1d3e3de3d", "revCount": 36, "type": "git",