diff --git a/containers/home-assistant.nix b/containers/home-assistant.nix index c4bcd43..6c19ac5 100644 --- a/containers/home-assistant.nix +++ b/containers/home-assistant.nix @@ -58,6 +58,13 @@ coreutils git ffmpeg bash runit ]; }; + ensureSomething.create."media" = { + type = "directory"; + mode = "755"; + owner = "home-assistant"; + dst = "/media"; + persistent = true; + }; }; services.home-assistant = { @@ -87,18 +94,40 @@ unit_system = "metric"; time_zone = "\${TIME_ZONE}"; internal_url = "http://localhost:8123/"; + whitelist_external_dirs = [ + "/mnt/cctv" + ]; + media_dirs = { + local = "/mnt/cctv"; + }; }; 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/retriggered.nix) (import ./home-assistant/automations/alarm/motion-detected.nix) (import ./home-assistant/automations/alarm/motion-detected-away.nix) ]; alarm_control_panel = import ./home-assistant/alarm_control_panel.nix; frontend.themes = { }; + sensor = [ + { + platform = "time_date"; + display_options = [ + "time" + "date" + "date_time" + "date_time_utc" + "date_time_iso" + "time_date" + "time_utc" + "beat" + ]; + } + ]; }; package = (pkgs.home-assistant.override diff --git a/containers/home-assistant/alarm_control_panel.nix b/containers/home-assistant/alarm_control_panel.nix index 53708fe..4db7258 100644 --- a/containers/home-assistant/alarm_control_panel.nix +++ b/containers/home-assistant/alarm_control_panel.nix @@ -4,9 +4,9 @@ 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. + arming_time = 0; # Time to leave the house after arming. + delay_time = 30; # Time to turn off after entering the house. + trigger_time = 3600; # How long the alarm goes off for. disarmed = { trigger_time = 0; # Can't be triggered when disarmed. }; diff --git a/containers/home-assistant/automations/alarm/disarmed.nix b/containers/home-assistant/automations/alarm/disarmed.nix index 4900549..1606d36 100644 --- a/containers/home-assistant/automations/alarm/disarmed.nix +++ b/containers/home-assistant/automations/alarm/disarmed.nix @@ -13,6 +13,10 @@ { data = { message = "Alarm Disarmed"; + data = { + channel = "Motion"; + importance = "high"; + }; }; service = "notify.mobile_app_redrum"; } diff --git a/containers/home-assistant/automations/alarm/motion-detected-away.nix b/containers/home-assistant/automations/alarm/motion-detected-away.nix index 2717d4b..17fa173 100644 --- a/containers/home-assistant/automations/alarm/motion-detected-away.nix +++ b/containers/home-assistant/automations/alarm/motion-detected-away.nix @@ -2,11 +2,18 @@ alias = "Alarm - Trigger when motion detected - Away"; id = "b16e988f-2ee0-4596-a14d-0fda1a95ac2d"; - trigger = { - platform = "state"; - entity_id = "binary_sensor.motion_sensor_occupancy"; - to = "on"; - }; + trigger = [ + { + platform = "state"; + entity_id = "binary_sensor.motion_sensor_occupancy"; + to = "on"; + } + { + platform = "state"; + entity_id = "binary_sensor.sensor_entry_door_contact"; + to = "on"; + } + ]; condition = { condition = "or"; conditions = [ diff --git a/containers/home-assistant/automations/alarm/motion-detected.nix b/containers/home-assistant/automations/alarm/motion-detected.nix index f384cbb..f2a5f7f 100644 --- a/containers/home-assistant/automations/alarm/motion-detected.nix +++ b/containers/home-assistant/automations/alarm/motion-detected.nix @@ -1,12 +1,14 @@ { - alias = "Alarm - Trigger when motion detected - Home/Away"; + alias = "Alarm - Trigger when motion detected - Home"; id = "972bccd8-a68c-48fc-ac90-ebbeb87c64b9"; - trigger = { - platform = "state"; - entity_id = "binary_sensor.sensor_entry_door_contact"; - to = "on"; - }; + trigger = [ + { + platform = "state"; + entity_id = "binary_sensor.sensor_entry_door_contact"; + to = "on"; + } + ]; condition = { condition = "or"; conditions = [ @@ -15,11 +17,6 @@ entity_id = "alarm_control_panel.home_alarm"; state = "armed_home"; } - { - condition = "state"; - entity_id = "alarm_control_panel.home_alarm"; - state = "armed_away"; - } ]; }; action = [ diff --git a/containers/home-assistant/automations/alarm/pending.nix b/containers/home-assistant/automations/alarm/pending.nix index a30588a..1d94588 100644 --- a/containers/home-assistant/automations/alarm/pending.nix +++ b/containers/home-assistant/automations/alarm/pending.nix @@ -12,7 +12,13 @@ ]; action = [ { - data = { message = "Alarm Pending - Intruder Detected!"; }; + data = { + message = "Alarm Pending - Intruder Detected!"; + data = { + channel = "Motion"; + importance = "high"; + }; + }; service = "notify.mobile_app_redrum"; } ]; diff --git a/containers/home-assistant/automations/alarm/retriggered.nix b/containers/home-assistant/automations/alarm/retriggered.nix new file mode 100644 index 0000000..d26076e --- /dev/null +++ b/containers/home-assistant/automations/alarm/retriggered.nix @@ -0,0 +1,35 @@ +{ + alias = "Alarm - ReTriggered"; + id = "2f4942bc-3538-4888-bc52-84171e0b040f"; + + trigger = [ + { + platform = "state"; + entity_id = "binary_sensor.motion_sensor_occupancy"; + to = "on"; + } + ]; + + condition = { + condition = "or"; + conditions = [ + { + condition = "state"; + entity_id = "alarm_control_panel.home_alarm"; + state = "triggered"; + } + ]; + }; + + action = [ + { + service = "camera.record"; + target.entity_id = "camera.mirror_camera"; + data = { + lookback = 30; + duration = 30; + filename = "/mnt/cctv/cctv-{{ states('sensor.date_time_iso') }}.mp4"; + }; + } + ]; +} diff --git a/containers/home-assistant/automations/alarm/triggered.nix b/containers/home-assistant/automations/alarm/triggered.nix index 2aea838..452efd6 100644 --- a/containers/home-assistant/automations/alarm/triggered.nix +++ b/containers/home-assistant/automations/alarm/triggered.nix @@ -10,9 +10,22 @@ } ]; action = [ + { + service = "camera.record"; + target.entity_id = "camera.mirror_camera"; + data = { + lookback = 30; + duration = 30; + filename = "/mnt/cctv/cctv-{{ states('sensor.date_time_iso') }}.mp4"; + }; + } { data = { message = "Alarm Triggered - Motion Detected!"; + data = { + channel = "Motion"; + importance = "high"; + }; }; service = "notify.mobile_app_redrum"; } diff --git a/nomad/regions/homelab-1/job/home-assistant.hcl b/nomad/regions/homelab-1/job/home-assistant.hcl index ff4bd83..27e8e2f 100644 --- a/nomad/regions/homelab-1/job/home-assistant.hcl +++ b/nomad/regions/homelab-1/job/home-assistant.hcl @@ -209,6 +209,12 @@ EOF access_mode = "single-node-writer" } + volume "cctv" { + type = "host" + read_only = false + source = "cctv" + } + service { name = "home-assistant" port = "8123" @@ -284,6 +290,12 @@ EOF read_only = false } + volume_mount { + volume = "cctv" + destination = "/mnt/cctv" + read_only = false + } + template { data = <