Notify when someone is home or not home


I am now beginning to play around with automation. This first thing I would like to test is notification when someone is home or left the house. This is what I have at the moment…

- alias: 'Home notification'
    platform: state
    entity_id: device_tracker.ben
    from: 'not_home'
    to: 'home'
      message: 'Ben is home'

It works as expected. But the problem is I have a lot of members in the house. I can duplicate the same code for every members but it is very tedious. Imagine 100 members to track. I am wondering what is the most efficient way?

1 Like

Check the Template trigger and the Template condition docs.

thanks. sorry but i am truely a noob in this. i stared at that pages and couldn’t make any sense out of it. can you help me or perhaps give me some examples on how everything (trigger, template, conditions, etc…) connects?

Hey @masterkenobi, did you figure out how to do this? I’m also interested in getting notified on “who” arrived home and I don’t want to duplicate the code…

You can try this…

- alias: 'Device State Change Alert'
    platform: state
    entity_id: device_tracker.user1, device_tracker.user2, device_tracker.user3, device_tracker.user4
    - service: notify.notify
        message: >
          {{ trigger.to_state.attributes.friendly_name }} is {% if trigger.to_state.state == 'home' %}back{% else %}away{% endif %}.
        title: ""


I’m trying to set up the notification for when someone comes home and have copied your example as the basis for this. My presence updates correctly on the HASS homepage and my notifications work for other events, but for some reason I can’t get this to work.

My automation looks like:

  - alias: Notify Bob at Home
      - platform: state
        entity_id: device_tracker.Bob
        from: 'not_home'
        to: 'home'
      service: notify.pushbullet
        message: 'Bob is at home.' 

If you have any suggestions to what I am missing or have wrong, I’d be very grateful!

looks fine to me

Thanks - glad I am not missing something obvious. I’ll keep playing around,…

You can try to isolate the issue by using the ui to trigger the automation. Remote-> domain:automation ->service:trigger ->data: {“entity_id”:“automation.notify_bob_at_home”}

If you get a notification then you know for sure it’s the trigger not working properly.

Thanks - that works so I will look at the trigger.

However, I have just upgraded to 0.45.1 and now NMAP doesn’t seem to be running so my presence status does not update. I guess I need to fix that first…

Okay - post upgrade issue now sorted. I still can’t figure out the issue with my trigger. Can I check that in the line “device_tracker.Bob” I should be using the device name from my knowndevices.yaml file, i.e Bob?

Thanks again

I started out using from & to but had better luck with zone ‘enter’ and ‘leave’ events. Worth trying out.

- platform: zone
  entity_id: device_tracker.Bob
  zone: zone.home
  event: leave

Thanks. I will have a look at that, but I assume that needs me to track presence via GPS? At the moment I use nmap to scan whether two phones are on my home network.

Ah yes sorry. I tried NMAP way at the beginning of my HA days and found it too unreliable (iphone puts wifi to sleep often and couldn’t get a buffer time that worked for me). GPS isn’t perfect but where I’m at works pretty well.

Maybe try home/not_home without quotes? This works for me…

- alias: 'Empty House'
      platform: state
      from: home
      to: not_home
    - condition: state
      entity_id: input_boolean.justrestarted
      state: 'off'
    - service: script.turn_on
      entity_id: script.left_home

I know this topic is old, but I just created this automation and I receive notifications all the time, not just when the status of the devices changes, do you know if I can I include a condition to receive the notifications just when the status changes?

I just figured it out, this condition do the magic:

  - condition: template
    value_template: '{{ trigger.from_state.state != trigger.to_state.state }}'