From 5d2e6da0522fe96644800cadb055519571b19396 Mon Sep 17 00:00:00 2001 From: Przemek Grondek Date: Wed, 31 Jul 2024 19:59:47 +0200 Subject: [PATCH] Set alarm code --- configuration/automations/alarm.yaml | 39 +++++++++++++-------------- configuration/automations/vacuum.yaml | 6 ++--- configuration/configuration.yaml | 1 + home-assistant.yml | 8 ++++++ localhost.yml | 25 ----------------- scripts/70.vacuum.yaml | 6 ++--- templates/scripts/alarm.yaml.j2 | 26 ++++++++++++++++++ 7 files changed, 58 insertions(+), 53 deletions(-) delete mode 100644 localhost.yml create mode 100644 templates/scripts/alarm.yaml.j2 diff --git a/configuration/automations/alarm.yaml b/configuration/automations/alarm.yaml index 22ca2ce..921054f 100644 --- a/configuration/automations/alarm.yaml +++ b/configuration/automations/alarm.yaml @@ -39,9 +39,9 @@ - service: notify.home_assistant data: message: > - ALARM. Pending to disarm - Motion in hallway - {{ state_attr(trigger.entity_id, 'friendly_name') }} - @everyone + ALARM. Pending to disarm + Motion in hallway - {{ state_attr(trigger.entity_id, 'friendly_name') }} + @everyone target: [ "1070507369164984372" ] data: images: @@ -72,12 +72,12 @@ - platform: state entity_id: binary_sensor.office_sensor_motion to: 'on' -# - platform: state -# entity_id: binary_sensor.kitchen_tabletop_motion_detection -# to: 'on' -# - platform: state -# entity_id: binary_sensor.kitchen_sink_motion_sensor -# to: 'on' + # - platform: state + # entity_id: binary_sensor.kitchen_tabletop_motion_detection + # to: 'on' + # - platform: state + # entity_id: binary_sensor.kitchen_sink_motion_sensor + # to: 'on' # Use open/close sensors - platform: state entity_id: binary_sensor.dining_window_1_open_close @@ -108,7 +108,7 @@ {{ state_attr(trigger.entity_id, 'friendly_name') }} data: entity_id: camera.living_room - url: "/lovelace-tablet/security" + url: "/lovelace-tablet/security" - service: camera.snapshot data: filename: /config/www/cctv/living_room.jpg @@ -196,16 +196,16 @@ - platform: state entity_id: binary_sensor.bathroom_motion_occupancy to: 'on' -# - platform: state -# entity_id: binary_sensor.bedroom_motion_occupancy -# to: 'on' + # - platform: state + # entity_id: binary_sensor.bedroom_motion_occupancy + # to: 'on' - platform: state entity_id: binary_sensor.bathroom_shower_sensor_motion to: 'on' # Use open/close sensors -# - platform: state -# entity_id: binary_sensor.bedroom_window_open_close -# to: 'on' + # - platform: state + # entity_id: binary_sensor.bedroom_window_open_close + # to: 'on' condition: - condition: state entity_id: alarm_control_panel.home_alarm @@ -219,7 +219,7 @@ message: > {{ state_attr(trigger.entity_id, 'friendly_name') }} data: - url: "/lovelace-tablet/security" + url: "/lovelace-tablet/security" - id: alarm_night alias: '[Alarm] Trigger alarm at night' @@ -255,7 +255,7 @@ message: > {{ state_attr(trigger.entity_id, 'friendly_name') }} data: - url: "/lovelace-tablet/security" + url: "/lovelace-tablet/security" - id: alarm_arm_away alias: '[Alarm] Arm away' @@ -265,8 +265,7 @@ zone: zone.home event: leave action: - - service: alarm_control_panel.alarm_arm_away - entity_id: alarm_control_panel.home_alarm + - service: script.alarm_arm_away - id: alarm_pending alias: '[Alarm] Send notification when alarm triggered' diff --git a/configuration/automations/vacuum.yaml b/configuration/automations/vacuum.yaml index 2d0f236..44b2a8f 100644 --- a/configuration/automations/vacuum.yaml +++ b/configuration/automations/vacuum.yaml @@ -31,10 +31,8 @@ entity_id: alarm_control_panel.home_alarm state: 'armed_home' sequence: - - service: alarm_control_panel.alarm_disarm - entity_id: alarm_control_panel.home_alarm - - service: alarm_control_panel.alarm_arm_away - entity_id: alarm_control_panel.home_alarm + - service: script.alarm_disarm + - service: script.alarm_arm_away - id: vacuum_daily_reset alias: '[Vacuum] Reset daily cleaning' diff --git a/configuration/configuration.yaml b/configuration/configuration.yaml index e932e09..f87ed3b 100644 --- a/configuration/configuration.yaml +++ b/configuration/configuration.yaml @@ -236,6 +236,7 @@ influxdb: alarm_control_panel: - platform: manual name: Home Alarm + code: !secret alarm_code delay_time: 30 arming_time: 30 trigger_time: 120 diff --git a/home-assistant.yml b/home-assistant.yml index 15ea0bf..5c7ac6b 100644 --- a/home-assistant.yml +++ b/home-assistant.yml @@ -1,6 +1,9 @@ --- - hosts: home-assistant tasks: + - name: Include secrets + include_vars: + file: configuration/secrets.yaml - name: Remove automations directory file: path: '{{ pwd_config }}/automations' @@ -125,6 +128,11 @@ dest: './scripts/check-unavailable.yaml' vars: entities: "{{ availability }}" + - name: Build alarm script + delegate_to: localhost + template: + src: scripts/alarm.yaml.j2 + dest: './scripts/alarm.yaml' - name: Concat scripts ansible.builtin.assemble: remote_src: no diff --git a/localhost.yml b/localhost.yml deleted file mode 100644 index 74b6c84..0000000 --- a/localhost.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- hosts: localhost - tasks: - - name: Build lights automations - template: - src: lights.yaml.j2 - dest: configuration/automations/lights.yaml - vars: - lights: - - entityId: light.bathroom_lights - name: Bathroom Lights - - entityId: light.kitchen_lights - name: Kitchen Lights - - entityId: light.shower_lights - name: Shower Lights - - entityId: light.couch_lights - name: Couch Lights - - entityId: light.desk_lightbar - name: Desk Lightbar - - entityId: light.office - name: Office lamp - - name: Concat scripts - ansible.builtin.assemble: - src: scripts - dest: configuration/scripts.yaml diff --git a/scripts/70.vacuum.yaml b/scripts/70.vacuum.yaml index 601556b..f698ed0 100644 --- a/scripts/70.vacuum.yaml +++ b/scripts/70.vacuum.yaml @@ -18,10 +18,8 @@ vacuum_today: entity_id: alarm_control_panel.home_alarm state: 'arming' sequence: - - service: alarm_control_panel.alarm_disarm - entity_id: alarm_control_panel.home_alarm - - service: alarm_control_panel.alarm_arm_home - entity_id: alarm_control_panel.home_alarm + - service: script.alarm_disarm + - service: script.alarm_arm_stay - service: vacuum.start entity_id: vacuum.valetudo_valetudos5 diff --git a/templates/scripts/alarm.yaml.j2 b/templates/scripts/alarm.yaml.j2 new file mode 100644 index 0000000..8b2f680 --- /dev/null +++ b/templates/scripts/alarm.yaml.j2 @@ -0,0 +1,26 @@ +alarm_arm_stay: + alias: '[Alarm] arm stay' + mode: single + icon: mdi:weather-night + sequence: + - service: alarm_control_panel.alarm_arm_home + entity_id: alarm_control_panel.home_alarm + data: + code: "{{ alarm_code }}" + +alarm_arm_away: + alias: '[Alarm] arm away' + mode: single + sequence: + - service: alarm_control_panel.alarm_arm_away + entity_id: alarm_control_panel.home_alarm + data: + code: "{{ alarm_code }}" + +alarm_disarm: + alias: '[Alarm] disarm' + sequence: + - service: alarm_control_panel.alarm_disarm + entity_id: alarm_control_panel.home_alarm + data: + code: "{{ alarm_code }}"