Phone tracking to disable Home Assistant Manual Alarm?

Hi There,

New to the Forum and playing about with IOT devices.

So Currently I have setup a nice little ESP 8266 with a relay to act as a self monitored and smart home alarm. I have managed to configure the manual alarm and set a code to arm and disarm the alarm

My next question though is a toughie for me. I am by no means a developer so forgive me if I do or say something dumb.

I know that home assistant can track both mine and my partners phones. I want it to be able to arm the alarm if both our phones are outside the radius of the home location and to disarm when atleast one device is home.

From my reading I understand I need to group the two phones and then set a state for the group either in(if atleast one device is home) or out(if both devices are gone). then get that to trigger the activation of the alarm. is there anyone out here who could help me with this. I am going a little insane reading through so many posts for the last week and a half. here is what I have in my configuration.yaml thus far.

Blockquote

Loads default set of integrations. Do not remove.

default_config:

Text to speech

tts:

  • platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
customize:
zone.home:
radius: 30

alarm_control_panel:

  • platform: manual
    name: Home Alarm
    code: “****”
    arming_time: 30
    delay_time: 20
    trigger_time: 4
    disarmed:
    trigger_time: 0
    armed_home:
    arming_time: 0
    delay_time: 0
    automation:
  • alias: ‘Send notification when alarm triggered’
    trigger:
    • platform: state
      entity_id: alarm_control_panel.home_alarm
      to: “triggered”
      action:
    • service: notify.notify
      data:
      message: “ALARM! The alarm has been triggered”
      automation:
  • alias: ‘Send notification when alarm is Disarmed’
    trigger:
    • platform: state
      entity_id: alarm_control_panel.home_alarm
      to: “disarmed”
      action:
    • service: notify.notify
      data:
      message: “ALARM! The alarm is Disarmed at {{ states(‘sensor.date_time’) }}”
      automation:
  • alias: ‘Send notification when alarm is Armed in Away mode’
    trigger:
    • platform: state
      entity_id: alarm_control_panel.home_alarm
      to: “armed_away”
      action:
    • service: notify.notify
      data:
      message: “ALARM! The alarm is armed in Away mode {{ states(‘sensor.date_time’) }}”

Blockquote

Hi! Welcome to the forum. You should give this a quick read when you get a minute. Specifically, formatting your code properly makes it much easier for people to help you. (Select any code in your message and click this button/).

image

As for your question, first thing to consider is are you sure you want your alarm to automatically disarm when a phone enters a zone without any other user intervention? That will mean that if you happen to drop your phone on the sidewalk or somebody who knows how it works gets their hands on your phone they can easily bypass your alarm system. Just make sure you understand that.

So there are several ways to skin this cat. I personally think the easiest would be to create a template sensor that evaluates to true when a phone is home and false when none are. This is a very simple example of such a sensor.

template:
  - binary_sensor:
    - name: "Somebody Home"
      state: >
        {{ is_state('device_tracker.phone_1','home')
            or is_state('device_tracker.phone_2','home') }}

This will create an entity called binary_sensor.somebody_home which you can now use as a trigger for your arm/disarm automations.

trigger:
  - platform: state
    entity_id: binary_sensor.someone_home
    to: 'on'
    from: 'off'
1 Like

I do understand the risk, the house is currently monitored via CCTV and 2 pitbulls so I guess if someone really wants to get in then yeah they got to risk it. I just want to simplify when I forget to arm that it will actually do it for me. Ill give this a try and see.

Thank you

Thanks, But I clearly dont know what exactly I am doing.

So Ive added the template above into the configuration.yaml file I now have a bar next to the alarm panel and it shows my phone name

Then Ive added the trigger section but it does nothing. Does not set the alarm to armed.

@jazzyisj are you on the discord channel?

Isn’t there a service call that is arm/disarm the alarm?
If you look at the disarm example, doesn’t that service call work?

The group you created does the same thing as the template sensor posted in the previous comment.
It’s the same thing, just use one of them.

1 Like

Would I be doing it correct this like this?

template:
- house_state:
    - name: 'someone_home'
      state: is_state('device_tracker.mornephone','home')
  trigger:
  - platform: state
    entity_id: binary_sensor.someone_home
    to: 'on'
    from: 'off'
  condition:
    - condition: state
      entity_id: alarm_control_panel.home_alarm
      state: armed_away

I have an automation that does this. Security concerns aside, it works fairly well.

You don’t need templates or binary entities that are set based on other entities. Just use the zone enter trigger for a person or device tracker in the trigger section of the automation. Keep it simple.

  - id: disable_alarm_away
    alias: 'Disable Alarm Away'
    trigger:
      - platform: zone
        entity_id:
          - person.b
          - person.r
        zone: zone.home
        event: enter
    condition:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state:
          - 'arming'
          - 'armed_away'
    action:
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id: alarm_control_panel.ha_alarm
          code: !secret alarm_code
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id:
            - alarm_control_panel.aarlo_m
            - alarm_control_panel.aarlo_o

Agree with this.
Except I would create a group and use that since it’s easier to manage.

But yes a simple automation is all that is needed.

Simpler is better,

I dont really know what I am doing here with everything and for the next maybe 10 years we will be the only people with phones in the house

So would be great to just be able to copy and paste something here.

what I posted is an automation. It must be added into your configuration YAML file under the automation: heading and properly indented. change the entity names accordingly for your install. And if you only have one alarm panel, then delete the second alarm panel disarm service call from my automation. My automation also requires you have at least one device tracker tied to a person.

Ok Ive changed it to this.

Currently only tracking my own phone.
Will add my fiance’s later. just want to get it to work right now.

# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
  customize:
    zone.home:
      radius: 30

alarm_control_panel:
  - platform: manual
    name: Home Alarm
    code: "****"
    arming_time: 30
    delay_time: 20
    trigger_time: 4
    disarmed:
      trigger_time: 0
    armed_home:
      arming_time: 0
      delay_time: 0
automation:
  - alias: 'Send notification when alarm triggered'
    trigger:
      - platform: state
        entity_id: alarm_control_panel.home_alarm
        to: "triggered"
    action:
      - service: notify.notify
        data:
          message: "ALARM! The alarm has been triggered"
automation:
- alias: 'Send notification when alarm is Disarmed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.home_alarm
      to: "disarmed"
  action:
    - service: notify.notify
      data:
        message: "ALARM! The alarm is Disarmed at {{ states('sensor.date_time') }}"
automation:
- alias: 'Send notification when alarm is Armed in Away mode'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.home_alarm
      to: "armed_away"
  action:
    - service: notify.notify
      data:
        message: "ALARM! The alarm is armed in Away mode {{ states('sensor.date_time') }}"

automation:
  - id: disable_alarm_away
    alias: 'Disable Alarm Away'
    trigger:
      - platform: zone
        entity_id:
          - mornephone
        zone: zone.home
        event: enter
    condition:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state:
          - 'arming'
          - 'armed_away'
    action:
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id: alarm_control_panel.ha_alarm
          code: "****"
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id:
            - alarm_control_panel.aarlo_m

Your config will fail validation. you have the automation: heading in your configuration yaml 4 times. you already have a separate automation yaml file. put all your automations in there. also the entity you’re tracking for the zone enter needs to be either person. or device_tracker.. what you have now is not a valid entity.

Haha, then I will break the entire thing… :frowning: this is difficult…

Why would that break anything?

You can also redo the automation using the GUI.
Just read the yaml line by line and choose the appropriate settings in the GUI

and make sure you change the alarm entity to the name of your alarm. you still have my alarm name in the entity ID. and remove the second service call to disarm in the action section, unless you do actually have an Arlo panel using the Aarlo 3rd-party integration and it is called aarlo_m. :open_mouth:

You don’t need to use them which is why I said there is more than one way to do it.

When you realize that someone being home or not is going to be the basis for many of your automations you’ll be repeating that in many places and if you ever need to change it you’ll need to change it everywhere.

Also if you use a template sensor you can easily add additional elements to the template such as a boolean override for testing your automations or when you want to actually leave your house without your phone, you lose your phone etc. etc.

speaking of making it simpler…

A group does not care about the entity type, you can mix device trackers, booleans and persons and you don’t need to specify the state.
If either of them is “positive” they are considered home.
So if you want to make it simple then a group is the better choice.

And broken… getting errors now… and I dont know what to do.

I give up

Once you get this figured out once, it gets much easier. Hang in there!

So where are you at now. What do the logs say? What happens?

so what I have done is I stripped the configuration.yaml back to this


# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

homeassistant:
  customize:
    zone.home:
      radius: 30

alarm_control_panel:
  - platform: manual
    name: Home Alarm
    code: "MECODE"
    arming_time: 30
    delay_time: 20
    trigger_time: 4
    disarmed:
      trigger_time: 0
    armed_home:
      arming_time: 0
      delay_time: 0

I have then added the following into my automation.yaml

automation:
  - alias: 'Send notification when alarm triggered'
    trigger:
      - platform: state
        entity_id: alarm_control_panel.home_alarm
        to: "triggered"
    action:
      - service: notify.notify
        data:
          message: "ALARM! The alarm has been triggered"
automation:
- alias: 'Send notification when alarm is Disarmed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.home_alarm
      to: "disarmed"
  action:
    - service: notify.notify
      data:
        message: "ALARM! The alarm is Disarmed at {{ states('sensor.date_time') }}"
automation:
- alias: 'Send notification when alarm is Armed in Away mode'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.home_alarm
      to: "armed_away"
  action:
    - service: notify.notify
      data:
        message: "ALARM! The alarm is armed in Away mode {{ states('sensor.date_time') }}"
automation:
  - id: disable_alarm_away
    alias: 'Disable Alarm Away'
    trigger:
      - platform: zone
        entity_id:
          - mornephone
        zone: zone.home
        event: enter
    condition:
      - condition: state
        entity_id: alarm_control_panel.ha_alarm
        state:
          - 'arming'
          - 'armed_away'
    action:
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id: alarm_control_panel.ha_alarm
          code: MECODE
      - service: alarm_control_panel.alarm_disarm
        data:
          entity_id:
            - alarm_control_panel.aarlo_m

So now it seems fine. But I am not at home and its not arming the alarm.