Need a little help with an alarm automation (with conditions)

Hello all,

Below is my current code.

The issue I see with it currently is that if someone were to come through the back door at night and trigger the alarm, they would immediately get picked up with the “gym motion sensor” and it would kick into “dog mode” and the alarm would get disarmed for 20 minutes.

Is there anyway to get the order of events to matter inside of a home assistant automation. If so, or if another idea presents itself to someone, can someone show me how to modify my instance to make it happen. Essentially if the “gym motion sensor” were to go to state on and then any of the doors were to open that would be fine and I would want the dog mode section to run (disabling alarm, 20 min delay and then enabling back) but if the door were to go to “on” first, I wouldn’t want it go into the dog mode sequence and I would want it to trigger the alarm.

My hopes would be to modify the below in some way and keep all of the other logic intact.

Thank you all for any help/ guidance you can provide!!

  - id: dog_mode_activated
    alias: Dog Mode Activated
    mode: single
      - platform: state
        entity_id: binary_sensor.gym_motion_sensor
        to: 'on'
      - platform: state
        entity_id: input_boolean.dog_mode
        to: 'on'
      - choose:
          - conditions:
              - condition: template
                value_template: '{{ trigger.to_state.attributes.friendly_name == "Dog Mode" }}'
              - service: script.text_notify
                  who: parents
                  message: Dog Mode has been enabled manually
              - service: script.dog_mode_lighting_on
              - delay:
                  minutes: 20
              - service: input_boolean.turn_off
                entity_id: input_boolean.dog_mode
          - conditions:
              - condition: state
                entity_id: input_boolean.sentry_mode
                state: 'on'
              - condition: state
                state: home
              - condition: state
                entity_id: group.external_doors
                state: 'off'
              - service: input_boolean.turn_on
                entity_id: input_boolean.dog_mode
              - service: script.jarvis_alert
                  message: Turning on Dog Mode.
              - service: script.dog_mode_lighting_on
              - service: alarm_control_panel.alarm_disarm
                  code: '1131'
                  entity_id: alarm_control_panel.alarmo
              - delay:
                  minutes: 20
              - service: input_boolean.turn_off
                entity_id: input_boolean.dog_mode
              - service: alarmo.arm
                  entity_id: alarm_control_panel.alarmo
                  code: '1131'
                  mode: armed_night

You have asked something like this before, right? IIRC I’ve seen a very similar question a few weeks/days ago. :slight_smile: I read that as well, and can’t get my head around, what you’re actually trying to do.

So let’s see this as a mix between guessing and trying. :rofl:

Why don’t you just react on the door? The door seems to be the trigger you’d need. If the door opens (trigger), check if the dog_mode is on (condition) and then react (action = alarm or not). This should offer what you want.

The handling of the dog_mode should be on a different automation/script. If the gym_sensor turns on, check the conditions that make sure it’s the dog, and turn on dog_mode. The first automation checks for that and you’re good to go.

But maybe I misinterpreted that and you want something else. :slight_smile:

Gracious, I’ve asked so many questions about all of this stuff haha. Yeah, it was revolving around the same automation and now I’ve essentially found another hole in it which is where this question came from.

Haha, I’ve definitely been hot and heavy with regards to asking for guidance on some automations lately, that’s a definite.

I hadn’t got to read your post fully yet, when I get home tonight, I will reply to it in full.

And to be honest, I keep a list of things I would like to know how to do and I already have another one that revolves around this also (essentially trying to tie, the code that was used in entering the home to disarming the alarm—- separate subject for sure but related to alarm automation)

We’ll keep this one specific to my original post and if I can’t figure out the above secondary thing, I’ll create a new post.

Thank you for your response @paddy0174 and I’ll respond in full when I get back home tonight.

1 Like

:slight_smile: We’re all here to get help and learn in some kind, so it’s always intersting to see, how others handle these things. I wasn’t sure about your other post, but it sounded “familiar” :rofl: :rofl:

Take your time, and if necessary tell in detail what you want to achieve. Sometimes you loose sight of the forest for the trees. :rofl:

Disabling the alarm code is very trivial, at least in Alarmo you can just send a service call with your credentials and off it goes. Or you can change the alarm state to a different one, eg. from armed-homed to armed-away. Useful for home office / work-from-home: if the Zoom / Teams call starts, set the house on “armed_home” so you can disable the motion sensors inside and only listen for the window and door contacts… :smiley:

I’m such a monkey, sometimes I completely over complicated things. What I ended up doing was exactly as you said, I added a condition to the automation of the all of the doors being closed when the motion sensor was triggered. If this is the case, more than likely the motion came from inside the house. It then allows “dog mode” to be triggered as the motion came internal to the house.

If the door was opened and then the motion sensor triggered, it doesn’t meet the criteria and as such, doesn’t trigger dog mode but would trigger the alarm. (i.e the motion sensor would capture the motion before the door closed and it has like a 3-5 minute timeout period so the alarm would go off for that amount of time at the least.

I believe this is good enough for me. It’s not great but workable I guess.

Essentially, this automation is to make sure our alarm doesn’t go off in the middle of the night if we have to take the dog out to use the bathroom. Sorry for never explaining what it was actually for.

Of course, if the door were opened first and then the motion sensor triggered (which would be the case with intrusion), I would want the alarm to scream and hopefully not be triggered back to off if the intruder walked back passed the motion sensor after the cooldown period with the door closed.

Do you know of anyway to tie the unlocking of the door by a certain door code to disarming the alarm security system?–> I am trying to get away from geofencing for arming/ disarming the security system and I feel like this would be a good method if its doable.

If you have any ideas, I would love to hear them. Thank you for giving me some ideas on the original question, I think what I have will be good enough to serve its purpose.

What alarm do you use? I’d take a look at Alarmo, if I were you. :smiley: It does exactly what you want, and is imho easier to use as the standard alarm in HA.

If you want to use the code from a door (I assume you mean something like a smart lock), nothing easier than that. You can react on the door lock being correctly opened. This woukld be the trigger for an automation that sends the disarm code to Alarmo. That’s it, whatever you want to do with that information, is up to you. If you open the door, the media_player can react and play some nice intro for you, if others open, you can ask for someting else, like a speach that says “Clean your shoes, before you come in!” :rofl: :rofl:

Take a look at Alarmo, it makes things easier, I could setup a complete alarm system within an afternoon. As the sensors were already configured, it was really an easy task, and in my case it works as it should. I had only one “wrong alarm” in the beginning, but I tested it with just a notification for a few days, so no harm done. :slight_smile:

Coming back to your initial question. You need to differentiate between trigger and condition. Trigger is always a state that changes to something. A condition is always an actual state. Like the difference between the opening of a door and the door is open. It doesn’t matter for the condition, how long it already is in that state, it just cares about that second it is checked.

In your case it shouldn’t even be possible, to “un-trigger” the alarm from the motion sensor. Once the alarm is triggered, it should be on, until someone with a code (and therefor permission) disables the alarm. I know, I said it before, but take a look at Alarmo. It takes this logic a step further, and you can configure it for such cases. I can really recommend it, it saved a lot of time for me, setting up an alarm system. And for now I haven’t had any problems with it.

My idea would for you would be: when the “armed_night” state is set, meaning the alarm is on, but only triggered by “exterior” sensors, you can do an automated “getting up for the dog” sensor. I’d use some kind of bed sensors, to see if someone got up to go and open the door. You can even use the motion sensors for this.

If the motion sensor triggers, check what state the alarm is in, if no exterior sensors were triggered, it is likely you and the dog, so disable the alarm for X minutes, and turn it back on after that time. If eg the door stays open the whole time while the dog is out, it would be a nice trigger. Door closed again, re-arm the alarm. Idk if I said it before, take a look at Alarmo :rofl: :rofl:

I’m curious what you come up with, let me know! :slight_smile:

I use Alarmo currently.

Yeah, this would be simple for sure. I think I was making this one more than what it needed to be. (Although, I would still love to know if I could tie a specific door code being used to an automation)—> I definitely understand, I can tie a successful code entry to an automation but by specific code would be even better-- and really what I was after.

Yeah, this went quickly and was very easy to take care of like you said.

This makes perfect sense.

I agree, I don’t like this idea either but I’m running into a “wants” versus capabilities issue. haha. I know what I want, I just don’t know how to physically do it/ code it.

So, the untrigger concept I was talking of isn’t even an issue like I thought it would be with my current setup? I now see, as you said, there is an option to have Alarm trigger for 30 minutes and then stop. Again though, based on my automation I posted above, a walk passed the motion sensor after its cool off period- if an intruder were to get into the house- would disarm the alarm. Am I right in thinking this with my current automation?—> I have rewritten the automation just a bit (you may want to take a second look at it before responding)

In my instance I don’t have any exterior motion sensor that are worth anything. Is it possible to disable the gym motion sensor if the back door is opened with the alarm on? I’m really trying to do this with the single motion sensor and “order of operations” if possible.

Thank you for helping me understand and work through this Patrick.