Hoping to get some help extending an alarm automation (additional conditions?)

Can someone help me extend the automation below just a bit. I’m hoping to get it to differentiate “armed_night” and “armed_away”; right now whether I leave home or gets late at night (in my setup, it is 11pm), the alarm always goes to “armed_night”.

In my instance, I would like it to go to “armed night” at 11 pm if everyone is home and to “armed_away” if everyone is “not_home”.

Thank you all for your help on this!

  - id: sentry_mode_enabled
    alias: Sentry Mode Enabled Announcement
    initial_state: true
    trigger:
      - platform: state
        entity_id: input_boolean.sentry_mode
        from: "off"
        to: "on"
    action:
      - choose:
          - conditions:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: group.external_doors
                    state: 'on'
                  - condition: state
                    entity_id: group.garage_doors
                    state: open
            sequence:
              - service: input_boolean.turn_off
                entity_id: input_boolean.sentry_mode
              - service: input_boolean.turn_on
                entity_id: input_boolean.lockdown_issue
              - service: script.text_notify
                data:
                  who: "parents"
                  message: "Unable to lock down Turner House due to issue"
              - service: script.speech_engine
                data_template:
                  # who: "kitchen"
                  message: >
                    {{ [
                    "I was unable to activate barn door protocol due to an open door.",
                    "You may want to check the external doors. I was unable to secure them all.",
                    "My systems check has failed. Please check the external doors.",
                    "Someone has left the pod bay doors open."
                    ] | random }}
        default:
          - service: script.speech_engine
            data_template:
              # who: "kitchen"
              message: >
                {{ [
                "Barn door protocol has been activated.",
                "Turner House has been secured! ",
                "Sentry Mode is active. ",
                "I am now monitoring the doors and will let you know if anyone attempts to access.",
                "Turner House Shields are up."
                ] | random }}
          - service: alarmo.arm
            data:
              entity_id: alarm_control_panel.alarmo
              code: '1131'
              mode: armed_night
          - service: script.turn_on
            entity_id: script.reset_front_door_motion_count

There’s quite a bit of fundamental things you need to do this though.

You need home presence nailed. You don’t want to be arming your system away when you’re home or visa versa. Do you have that nailed? IMO simply using whether a phone is home or not isn’t enough in my house. I use a house presence to determine who is home and whether they are upstairs, etc.

@calisro

I agree

Luckily for now, there are just 2 of us and the phone presence only is working very well (they are pretty much always with each of us if we are gone); what are some thoughts you were having though, I’m all ears.

@calisro Thank you for the help you have given me in the past and responding here.

**EDIT: Also, the above was stolen code that I am trying to adapt for my situation.

Heck, I stole the whole home assistant setup from the youtuber slackerlabs (github repo)

This is how I manage auto-arming my alarm when the house is vacant. It incorporates quite a bit into the house_occupied group including phone presense, wasp sensors, and such. In your case, you’d probably substitute that for your own trigger.

alias: Ring Auto Arm Away v4
description: ''
trigger:
  - platform: state
    entity_id: group.house_occupied
    from: 'on'
    to: 'off'
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition:
  - condition: state
    entity_id: input_boolean.auto_arm_away
    state: 'on'
  - condition: state
    entity_id: alarm_control_panel.tampa_alarm
    state: disarmed
  - condition: state
    entity_id: group.house_occupied
    state: 'off'
action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.arm_away_trigger
    data: {}
  - service: timer.start
    data:
      duration: '120'
    target:
      entity_id: timer.auto_arm_time
  - service: script.tts_no_interrupt
    data:
      target: group.all_speakers_n_kids
      message: Alarm will be arming soon.  Say Google Dont Arm to disable.
      volume: 1
  - wait_for_trigger:
      - platform: state
        entity_id: input_boolean.arm_away_trigger
        from: 'on'
        to: 'off'
    timeout: '20'
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.arm_away_trigger
            state: 'on'
        sequence:
          - service: notify.phone_notifications
            data:
              title: >-
                Auto Arm Alarm activates at
                {{state_attr('timer.auto_arm_time','finishes_at')| as_datetime |
                as_timestamp | timestamp_custom("%I:%M %p") }} .
              message: Select Alarm Action
              data:
                tag: Ring-General
                group: Ring
                timeout: >-
                  {{(as_timestamp(state_attr('timer.auto_arm_time','finishes_at'))-as_timestamp(now()))|int}}
                ttl: 0
                priority: high
                color: yellow
                notification_icon: mdi:shield-sync-outline
                actions:
                  - action: alarm-disable-autoarm
                    title: Disable Auto Arm Away
                chronometer: true
                when: >-
                  {{(as_timestamp(state_attr('timer.auto_arm_time','finishes_at')))|int(0)}}
    default: []
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 1
  - repeat:
      while:
        - condition: state
          entity_id: timer.auto_arm_time
          state: active
        - condition: state
          entity_id: input_boolean.auto_arm_away
          state: 'on'
        - condition: state
          entity_id: input_boolean.arm_away_trigger
          state: 'on'
      sequence:
        - parallel:
            - service: script.tts_no_interrupt
              data:
                target: group.all_speakers_n_kids
                message: >-
                  The alarm is arming  {% if
                  states.timer.auto_arm_time.attributes.finishes_at %}
                    in {{(as_timestamp(state_attr('timer.auto_arm_time','finishes_at'))-now().timestamp())|round}} seconds.
                  {% else %}
                     very soon. 
                  {% endif %} To stop auto arm, Tell Google Dont Arm.. or walk
                  in front of an alarm motion sensor..  Or open and close an
                  exterior door.
                volume: 1
        - service: homeassistant.turn_on
          data: {}
          target:
            entity_id: switch.tampa_siren
        - delay:
            hours: 0
            minutes: 0
            seconds: 0
            milliseconds: 300
        - service: homeassistant.turn_off
          data: {}
          target:
            entity_id: switch.tampa_siren
        - wait_for_trigger:
            - platform: state
              entity_id: group.house_presense
            - platform: state
              entity_id: group.house_occupied
              to: 'on'
            - platform: state
              entity_id: input_boolean.auto_arm_away
              to: 'off'
              from: 'on'
            - platform: state
              entity_id: input_boolean.arm_away_trigger
              to: 'off'
              from: 'on'
          timeout: '20'
        - choose:
            - conditions:
                - condition: template
                  value_template: '{{ wait.trigger == None }}'
              sequence: []
          default:
            - service: timer.finish
              target:
                entity_id: timer.auto_arm_time
              data: {}
            - service: input_boolean.turn_off
              target:
                entity_id: input_boolean.arm_away_trigger
              data: {}
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.arm_away_trigger
            state: 'on'
        sequence:
          - parallel:
              - service: script.tts_no_interrupt
                data:
                  target: group.all_speakers_n_kids
                  message: Auto Arming Alarm Now.
                  volume: 1
              - service: script.alarm_arm_away
                data: {}
              - service: input_boolean.turn_off
                target:
                  entity_id: input_boolean.arm_away_trigger
                data: {}
              - service: notify.phone_notifications
                data:
                  title: Auto Arm Alarm Arming.
                  message: Auto Arming Alarm Now.
                  data:
                    tag: Ring-General
                    group: Ring
                    timeout: 300
                    color: red
                    ttl: 0
                    priority: high
                    notification_icon: mdi:shield-check-outline
    default:
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 500
      - parallel:
          - service: script.tts_no_interrupt
            data:
              target: group.all_speakers_n_kids
              message: Auto Arm Disabled.  Will Not Arm Alarm.
          - service: notify.phone_notifications
            data:
              title: Auto Arm Alarm was disabled.
              message: Alarm will not arm
              data:
                tag: Ring-General
                group: Ring
                timeout: 300
                ttl: 0
                priority: high
                color: yellow
                notification_icon: mdi:shield-off-outline
mode: single

I basically broadcast in the house just incase someone is there when I try to arm away and if no one disables the auto-arm-away, it turns it on. Works well for me incase I left a kid home and presence didn’t detect them for some reason. They can simply disable it with their voice or by walking in front of a sensor.

I use something different for when we are home.

alias: Ring Auto Arm Home v3
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.auto_arm_home
    to: 'on'
  - platform: time
    at:
      - '22:30:00'
      - '23:00:00'
      - '23:30:00'
      - '00:00:00'
      - '00:30:00'
    enabled: false
  - platform: state
    for:
      hours: 0
      minutes: 0
      seconds: 30
    entity_id: sensor.master_bed_state
    to: Occupied
  - platform: time_pattern
    minutes: /15
condition:
  - condition: state
    entity_id: group.house_occupied
    state: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 30
  - condition: state
    entity_id: input_boolean.auto_arm_home
    state: 'on'
  - condition: state
    entity_id: alarm_control_panel.tampa_alarm
    state: disarmed
  - condition: state
    entity_id: group.downstairs_occupied
    state: 'off'
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - condition: state
    entity_id: sensor.master_bed_state
    state:
      - Occupied
  - condition: time
    after: '21:29:00'
    before: '05:00:00'
  - condition: state
    entity_id: media_player.living_room_shield
    state:
      - standby
      - 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 30
  - condition: state
    entity_id: input_boolean.company
    state: 'off'
  - condition: state
    entity_id: media_player.backyard_tv
    state:
      - standby
      - 'off'
    for:
      hours: 0
      minutes: 0
      seconds: 30
action:
  - service: script.alarm_arm_home
    data: {}
mode: single

Well now you have more. lol

Ahh, I understand the necessity now. Thank you for sharing you’re approach at this. The thing I was having difficulty with was differentiating between night and away with what I have. The only way I could think to do it was to use “choose” with one path being the condition of time and the other path, being the condition of who’s home???

Thank you for this one also. It will be good for me to review other people’s approaches at these things. This was about the last thing I wanted to correct before I could say I am at a good minimum requirement base once I moved over from smartthings.

Haha, makes me happy. Don’t mind it a bit haha.

@calisro Rob, I hate to ask you another question but this one has been bugging me a bit and I just figured I would throw it out there to you as I can tell you know what you’re doing. So:

Is there a benefit to having the scripts and automations built strictly in yaml packages or in yaml in general?

To be honest, I don’t see a benefit other than possibly some organization that you get with packages. And with me being a noncoder, it seems like a nightmare for myself to build automations outside of the GUI.-- I’ve considered pulling everything out of “yaml” only but I don’t know if it’s a good idea and was wandering some others opinions on this (maybe I should start another thread)

What are your thought on this? For now, since, I stole most of my setup from a more capable individual, almost everything is in packages. What is your opinion of this whole situation?

Thank you Rob!

It’s preference. I haven’t used packages much but they do help keep things organized. A package is nothing but a group of related things.

It we’re being upfront, I probably would have used packages if I knew more about HA back when I started. There’s some functionality that would have been nice to have just in one place.

But it’s really just organization preference.

I don’t really use the gui much anymore now that I know the syntax. I use the editor UI but typically write in the yaml editor.