Making Home Assistant’s Presence Detection not so Binary

In Home Assistant and many other home automation controllers, your home status is either Home or Away. There’s no in-between. 

 

The Problem

So, you’ve got your home automation started, and it’s time to add some cool automations, like turning off everything when you leave, or playing some music when you get home. These can be pretty easy to do with presence detection, but sometimes you need more.

In my Home Assistant setup I’m using Bluetooth presence detection. Every ten seconds my Synology NAS running Home Assistant checks to see what Bluetooth devices it can ‘see’. If it detects my phone, then it knows I’m home.

When I get home, and it’s between a certain time, my house will start playing my Chillout playlist on Spotify through my Sonos speakers. It will only do that, if I arrive home alone, or my fiancée isn’t home. When everyone leaves, Home Assistant will shut everything down – including music, Philips Hue Lights, the TV, heating/cooling etc.

I’m in a two bedroom apartment, and the Bluetooth presence detection works across the entire apartment. There seems to be a blackspot when I’m at my desk with my phone. I’ll be working away, writing my next awesome automation or piece of code, only for Home Assistant to cut the power to my computer monitor and pause my music. A massive first world problem that needs to be solved.

I could increase the timeout which would reduce this from happening (which I’ve done) or even use multiple presence detection options like WiFi and Bluetooth. However this doesn’t solve the problem of my house doing things too quickly.

I’ll wake my phone, place it on the desk and wait for Home Assistant to detect it again. But here comes the problem. After waiting what seems like a lifetime for my phone to be detected again, everything starts as if I have been away for hours. My music is changed to my Chillout playlist again (or starts from the beginning), lights that I don’t need might come back on, I get messages that the dishwasher is done etc. At the moment, Home Assistant doesn’t know that I was home one minute ago, but maybe there’s a way we don’t need to start from scratch each time.

There’s also some times when we might be away from home. Maybe a weekend in the country, or away for work. The house should be able to tell that we’re more than just away for the day, so maybe it shouldn’t send us alerts that a battery needs to be replaced. Or, if I’m away for a long time, but my fiancée is home, maybe send those alerts to her instead.

 

Adding New States To Home Assistant

In my home, I want to track the following states that a person could be.

Just Arrived when someone has just arrived home after being away
HOME The classic Home state
Just Left When someone has just left the house
AWAY The classic Away or not_home state
Extended Away If someone is away for more than 24 hours

I’m using the Home Assistant input select component to track the states of my dishwasher and washing machine. I can re-use the same logic for that here.

 

Making Them Look Nice

Just like I did for my washing machine and dishwasher, I’m going to use a template sensor that will read the value of the drop-down. I can then make it look like a normal device tracker by adding our photos to the sensor.

 

Automating Transitions Between States

In Home Assistant we can see when someone is home or away only. But we now have some more complex states. Like I did for my washing machines, I’m going to use a for: condition. So as soon as someone is marked as away from their device tracker, they’ll be set to “Just Left”. If they are then in the “Just Left” status for five minutes, they’ll be marked as “Away”. The opposite is true when getting home.

However one problem I mentioned was music jumping back to my Chillout playlist. Let’s make sure that if someone is marked as “Just Left” and then their device tracker ‘sees’ them again, instead of marking them as Just Arrived, mark them as Home. This will stop any automations for when you get home for the first time firing off again.

Here’s some code which will do that.

 

We also want to add the special case “Extended Away”. This is useful if someone is away for the house for more than a whole day, like a vacation.

 

The Latest In Your Inbox

Enter your email address below to receive my latest blog posts and videos about Home Automation in your Inbox

 

Using Templates for Multiple People

With the code blocks above, there’s five automations just to go through those states. What if you have two people in your house? That becomes ten automations you need to maintain.

Let’s use Home Assistant templates to make the automations more dynamic. We can use the trigger variable to see which device caused the state to change, and then update the drop-down for the right person. Using templates, our whole automation for today becomes the following.

Note: I’m using bluetooth and WiFi presence detection for my fiancée’s iPhone, which I have in a Home Assistant group. When her iPhone is detected on Bluetooth or WiFi the group Helen will be marked as home.

 

Stopping the Just Arrived State

Update January 2018: Thanks to u/barqers on Reddit for pointing this out. With the code block above, it is possible for you to be marked as Just Left -> Just Arrived -> Home in the matter of a second if your phone disconnects and reconnects quickly. This means any automations you have setup that you want triggered when you enter the Just Arrived state could be triggered when you don’t want them.

You could use a for in your automation to account for this, however this may increase the time for Home Assistant to detect you as Home, which we don’t want.

To cover this edge-case, I’ve made the following changes to my automation, using templates to first check what my previous state was. If my previous state was Just Left, then instead of marking me as Just Arrived it will instead mark me as Home, skipping the Just Arrived state altogether.

 

Some Automations We Can Now Do

Now that we’ve got our new states setup, here’s some examples of automations we can do:

  • Play music when someone is marked as Just Arrived
  • Send dishwasher/washing machine alerts to someone when they are marked as Just Arrived, so the notification doesn’t get sent every time their device is marked as home
  • If everyone is marked as Extended Away, activate vacation mode to automatically turn off/on lights to make it look like someone is home
  • Don’t send alerts/messages to anyone marked as Extended Away for day-to-day operations of the house, like the washing being done or a battery needing to be replaced.
  • If you are marked as Home after being marked as Extended Away, send an email to you with the status of your smart home. What sensors need their battery replaced etc.
  • When someone is marked as Just Arrived and there are people marked as Home, announce who just got home over Text-to-Speech. Great for an announcement to let kids know when a parent is home from work for the day.

 

Additional States

At the moment, these five states work well for me, but i may want to change them in the future. Remember, they may not be the best fit for you but you can tailor them to suit your own home.

I don’t use this feature, but Home Assistant can be used with GPS to identify ‘zones’, such as work or school. These zones are used by Home Assistant instead of “home” or “not home”.

You could also do something similar with the drop-downs. One example would be to add a work option to the drop-down. If you have Home Assistant exposed to the world, you could use Tasker on Android to change the state of the drop-down to work when you connect to your work’s WiFi. If you have something like an Eight Sleep tracker, you could also mark someone as “asleep” when they’re laying in bed.

 

Wrapping Up

By adding additional states for presence, your home gets more information about what is happening. This means your smart home can tell the difference between when you’ve arrived home from a vacation and when you’ve just picked up milk from the shops.

Hopefully this inspires you to think outside the binary constraints of your controller software, to help you build some really smart automations.

Buy me a hot chocolateBuy me a hot chocolate
Recommended Posts
  • pattyland

    Hi, just a quick question: Why are you using Bluetooth detection instead of WiFi? I thought WiFi would me much more wide range than Bluetooth, speaking of repeaters or multiple access points…

    • WiFi would absolutely cover more range. I’ve found that in our house, we tend to turn our WiFi on our phones off quite a bit. Generally 4G is faster than our WiFi here, so if we need to download something quickly we turn WiFi off. My work WiFi sucks, so I generally have to turn WiFi off, and then forget to turn it back on before I’m home.

      WiFi can also be a bit slower. Because phones go to sleep, you have to increase the timeout or “consider home” time to allow for this. So, Home Assistant may not see that we’ve left the house until 10 minutes after we’ve actually left.

      Bluetooth we keep on, as it drains little battery in the background, and doesn’t have the sleep issues that WiFi does.

  • Stephen Arbon

    I believe you should be able to shorten this up significantly if you were to bundle some of the actions together. For instance Mark Person as home could be
    – alias: Mark person as home
    trigger:
    – platform: state
    entity_id: input_select.phil_status_dropdown,input_select.helen_status_dropdown
    to: ‘Just Arrived’
    for:
    minutes: 10
    – platform: state
    entity_id: input_select.phil_status_dropdown,input_select.helen_status_dropdown
    from: ‘Just Left’
    to: ‘Just Arrived’
    action:
    – service: input_select.select_option
    data_template:
    entity_id: >
    {% if trigger.entity_id == ‘input_select.phil_status_dropdown’ %}
    input_select.phil_status_dropdown
    {% else %}
    input_select.helen_status_dropdown
    {% endif %}
    option: Home

  • This is great, thank you 🙂

    As an aside, do you know if it’s possible to overlay the status onto the image, like the regular sensor presence would do?

    • Thanks!

      I think it might be possible. Think you would have to create your own custom UI component for it though, which I am not sure exactly where to point you for that.

    • teachingbirds

      See my comment to see how to get a “real” device_tracker!

  • David Pickel

    hey, thank you for sharing your solution!
    you did great job 🙂 and the guide was very helpful
    i have problem,
    why my People Status wont show the status? and how can i hide the input_select box?

    thanks phil

    https://uploads.disquscdn.com/images/5f930372073e89963034a0a8a286fff5424ed8e8c3261bf6fd5c71eccccdcf31.png

    • David Pickel

      hey, somehow i managed to show the state , but didnt manage to hide the input select. can you help?
      thanks

      • Hey David,

        I’m guessing this is showing on your default view?

        You might be able to do this in your customize.yaml file to hide those

        That should hide the dropdowns on the home assistant UI for you.

        You may also be able to do this from the interface. Configuration -> Customize -> (Select Dropdown) -> Pick An Attribute to Override -> Hidden

        • David Pickel

          phil you are the man!
          thanks for the quick response
          thank you 🙂

    • Jimmy Berglund

      Ive come to a problem i have not been able to resolve.

      Verry often Maria is Marked as being Home or away and wont change status. Ive looked @ the configs back and forth for over 2 months not can i cant seem to grasp were it goes wrong. The device for maria is correct everytime. when the Inputselect is not.

      – alias: Mark person as just arrived
      trigger:
      – platform: state
      entity_id: device_tracker.jimmy
      from: ‘not_home’
      to: ‘home’
      – platform: state
      entity_id: device_tracker.maria
      from: ‘not_home’
      to: ‘home’
      action:
      – service: input_select.select_option
      data_template:
      entity_id: >
      {% if trigger.entity_id == ‘device_tracker.jimmy’ %}
      input_select.jimmy_status_dropdown
      {% else %}
      input_select.maria_status_dropdown
      {% endif %}
      option: >
      {% if trigger.entity_id == ‘device_tracker.jimmy’ %}
      {% if states.input_select.jimmy_status_dropdown.state == ‘Gick just hemifrån’ %}
      Hemma
      {% else %}
      Kom nyss hem
      {% endif %}
      {% else %}
      {% if states.input_select.maria_status_dropdown.state == ‘Gick just hemifrån’ %}
      Hemma
      {% else %}
      Kom nyss hem
      {% endif %}
      {% endif %}

      – alias: Mark person as home
      trigger:
      – platform: state
      entity_id: input_select.jimmy_status_dropdown
      to: ‘Kom nyss hem’
      for:
      minutes: 10
      – platform: state
      entity_id: input_select.maria_status_dropdown
      to: ‘Kom nyss hem’
      for:
      minutes: 10
      – platform: state
      entity_id: input_select.jimmy_status_dropdown
      from: ‘Gick just hemifrån’
      to: ‘Kom nyss hem’
      – platform: state
      entity_id: input_select.maria_status_dropdown
      from: ‘Gick just hemifrån’
      to: ‘Kom nyss hem’
      condition:
      action:
      – service: input_select.select_option
      data_template:
      entity_id: >
      {% if trigger.entity_id == ‘input_select.jimmy_status_dropdown’ %}
      input_select.jimmy_status_dropdown
      {% else %}
      input_select.maria_status_dropdown
      {% endif %}
      option: Hemma

      – alias: Mark person as just left
      trigger:
      – platform: state
      entity_id: device_tracker.jimmy
      from: ‘home’
      to: ‘not_home’
      – platform: state
      entity_id: device_tracker.maria
      from: ‘home’
      to: ‘not_home’
      action:
      – service: input_select.select_option
      data_template:
      entity_id: >
      {% if trigger.entity_id == ‘device_tracker.jimmy’ %}
      input_select.jimmy_status_dropdown
      {% else %}
      input_select.maria_status_dropdown
      {% endif %}
      option: Gick just hemifrån

      – alias: Mark person as away
      trigger:
      – platform: state
      entity_id: input_select.jimmy_status_dropdown
      to: ‘Gick just hemifrån’
      for:
      minutes: 10
      – platform: state
      entity_id: input_select.maria_status_dropdown
      to: ‘Gick just hemifrån’
      for:
      minutes: 10
      action:
      – service: input_select.select_option
      data_template:
      entity_id: >
      {% if trigger.entity_id == ‘input_select.jimmy_status_dropdown’ %}
      input_select.jimmy_status_dropdown
      {% else %}
      input_select.maria_status_dropdown
      {% endif %}
      option: Borta

      – alias: Mark person as extended away
      trigger:
      – platform: state
      entity_id: input_select.jimmy_status_dropdown
      to: ‘Borta’
      for:
      hours: 24
      – platform: state
      entity_id: input_select.maria_status_dropdown
      to: ‘Borta’
      for:
      hours: 24
      action:
      – service: input_select.select_option
      data_template:
      entity_id: >
      {% if trigger.entity_id == ‘input_select.jimmy_status_dropdown’ %}
      input_select.jimmy_status_dropdown
      {% else %}
      input_select.maria_status_dropdown
      {% endif %}
      option: Borta länge

      – alias: Mark jimmy as away when home assistant starts
      trigger:
      – platform: homeassistant
      event: start
      condition:
      condition: and
      conditions:
      – condition: state
      entity_id: device_tracker.jimmy
      state: ‘not_home’
      action:
      – service: input_select.select_option
      data:
      entity_id: input_select.jimmy_status_dropdown
      option: Borta

      – alias: Mark Maria as away when home assistant starts
      trigger:
      – platform: homeassistant
      event: start
      condition:
      condition: and
      conditions:
      – condition: state
      entity_id: device_tracker.maria
      state: ‘not_home’
      action:
      – service: input_select.select_option
      data:
      entity_id: input_select.maria_status_dropdown
      option: Borta

      ###########Maria kommer hem###########
      – alias: Wife Home
      trigger:
      platform: state
      entity_id: input_select.maria_status_dropdown
      from: ‘Borta’ # note that this may be ‘on’ depnding on your sensor config #
      to: ‘Kom nyss hem’ # note that this may be ‘off’ depnding on your sensor config #
      condition:
      condition: time
      after: ’08:00:00′
      before: ’23:00:00′
      action:
      – service: notify.ios_jimmy
      data:
      message: “Maria är hemma!”
      data:
      push:
      sound: “US-EN-Alexa-Wife-Is-Arriving.wav”
      – service: notify.ios_maria
      data:
      message: “Välkommen hem Maria <3"
      data:
      push:
      sound: "US-EN-Alexa-Welcome-Home.wav"
      – service: light.turn_on
      data:
      entity_id: light.vardagsrum
      brightness: 150
      – service: light.turn_on
      data:
      entity_id: light.koket
      brightness: 150
      – service: switch.turn_on
      entity_id: switch.hallen
      – service: switch.turn_on
      entity_id: switch.vardagsrum_fonster
      # – service: switch.turn_on
      # entity_id: switch.kontoret
      # – service: tts.google_say
      # entity_id: media_player.kodi
      # data:
      # message: 'Welcome home Maria'
      ###########Maria kommer hem###########
      ###########Jimmy kommer hem###########
      – alias: Jimmy Home
      trigger:
      platform: state
      entity_id: input_select.jimmy_status_dropdown
      from: 'Borta' # note that this may be 'on' depnding on your sensor config #
      to: 'Kom nyss hem' # note that this may be 'off' depnding on your sensor config #
      condition:
      condition: time
      after: '08:00:00'
      before: '23:00:00'
      action:
      – service: notify.ios_jimmy
      data:
      message: "Välkommen hem Jimmy!"
      data:
      push:
      sound: "US-EN-Alexa-Welcome-Home.wav"
      – service: light.turn_on
      data:
      entity_id: light.vardagsrum
      brightness: 150
      – service: light.turn_on
      data:
      entity_id: light.koket
      brightness: 150
      – service: switch.turn_on
      entity_id: switch.hallen
      – service: switch.turn_off
      entity_id: switch.vardagsrum_fonster
      # – service: switch.turn_on
      # entity_id: switch.kontoret
      # – service: tts.google_say
      # entity_id: media_player.kodi
      # data:
      # message: 'Welcome home Jimmy'
      ###########båda lämnar hem###########
      #- alias: All leaves home
      # trigger:
      # – platform: state
      # entity_id: group.allafamiljoguest
      # to: 'not_home'
      # for:
      # minutes: 10
      #- alias: both leaves home
      # trigger:
      # – platform: state
      # entity_id: input_select.jimmy_status_dropdown
      # to: Borta
      # – platform: state
      # entity_id: input_select.jimmy_status_dropdown
      # to: Borta
      # action:
      # – service: switch.turn_off
      # entity_id: light.vardagsrum
      # – service: light.turn_off
      # entity_id: light.koket
      # – service: switch.turn_off
      # entity_id: switch.hallen
      # – service: switch.turn_off
      # entity_id: switch.kontoret
      # – service: switch.turn_off
      # entity_id: switch.sovrum_hoger
      # – service: switch.turn_off
      # entity_id: switch.sovrum_vanster
      # – service: switch.turn_off
      # entity_id: switch.sovrum_vanster
      # – service: switch.turn_off
      # entity_id: switch.malvinas_rum
      # – service: input_select.select_option
      # entity_id: input_select.living_room_tv
      # data_template:
      # option: "Stäng av"
      # – service: input_select.select_option
      # entity_id: input_select.freetoair
      # data_template:
      # option: "Välj Kanal"

      • I can’t see anything wrong here. Which is strange.

        If you look at your activity log in Home Assistant, is there anything that could be changing the value?

        You might need to setup an automation which fires every x minutes to update the input_dropdown to the correct state

        • Jimmy Berglund

          I think i found the problem. But I need to test it more to see. But the home assistant app had made 2 phones out of my wife’s phone in the files. So basically I just reset homeassistant files and reconfigurated he app and wola!

        • Jimmy Berglund

          Do you have any suggestions on how to do this? ive seen further upp the chain that my problem has been on the table before by you acualy. and seems your restarting your homeassistant to deal with it. Im using hassio today so dono is that even a possebility. I did not have this problem before and thats propably cause i was allso restarting my Rasberry every 12 hour. So now im stuck @ the problem you allso had. With that sometime people are stock on home or stuck on away.

          Its generally when the automasation switch from Just arrived to just left then either going home or away. Then it get stuck.
          Its generally the same outcome everytime. its just a matter of if it goes stuck on away or home when doing this.

          Do you have a suggestion on how a automation that would check that state would look like?

          On a note more problem happens like every 3rd day or so.

          • Not really.

            My suggestion would be to see if the device trackers are being marked as not_home correctly, and each automation has the right references.

            There could be a race condition, which you might be able to solve using a for like the following example

            Also, in your States panel, are the automation.mark_person_as_just_arrived and automation.mark_person_as_just_left turned on? They may have been switched off by a HASS restart

          • Jimmy Berglund

            Thx for your reply.

            Ive added the
            for:
            seconds: 5

            See if that does anything.
            And sadly all devices are always report the right status. And all the automation states are on. Atleast right now. But i just restarted. But that rules out that its off by restarting.

            The only thing i can see that has any link to the problem is that Marias_status does the following before getting stuck
            And that is that it goes “has just left” to “has just arrived” and then get stuck on home or away.

            And like you say. Maby the 5 sek thing will do something for that. BUT. Its only Maria that gets this problem. Mine “Jimmy” Works flawlessly.
            and mine works after 3-4 days when Maria starts failing. And i cant wrap my head around it by looking @ the code over and over again.

            Again The device_trackers are showing correct status so -,- But i mean i did see That Homeassistant has registerd MArias phone 2 times before. But thats gone. I resetted the whole Thing to see of i ould get it working.

            But one thing. Are you still restarting your Homeassistant everyday?

          • It is very strange. I can’t see why the dropdown would select “has just arrived”. The rules are that if your dropdown is “Just Left”, and your device tracker is marked as coming home, you should immediately go straight to the home state.

            I don’t restart my HomeAssistant daily anymore. Sometimes I have it running for a week between restarts, and everything has been ok so far.

          • Jimmy Berglund

            Hi Phil! Just wanted to let you know it seems like it was a race condition. I added the 5 sec to my Wife and now she worked flawlessly and my device started eventually failing 🙂 So now ive added that to me aswell. And im hopeing that will be the end of the problem. I think you should add that to the automasation above so others might not run in to the same problem. Thx for the help so far!

          • Nice one!

            I would say to change your time, so one person should be 5 seconds, and maybe the other person 7 seconds or something?

          • Jimmy Berglund

            Im mind blowned… I still have problem. Cause now my own device Input select is failing. and my wifes works flawless….. Do you maby have github so i can look in to your config your using today? then maby i can see what im missing…

          • I don’t have Git, but here’s my package file which handles all my presence detection like this post: https://hastebin.com/jacikuvunu.cs

            Maybe something in there will jump out at you?

  • doune

    Hi,

    How do you handle the state “all people are away” OR “all people are home” ?
    Because, being home is (or can be) the following 3 states :
    – “home”
    – “just arrived”
    – “just left”

    and being away can be the 3 following states :
    – “away”
    – “extended away”
    – “just left”

    Thanks for your help 🙂

    • For that, I use the regular Home Assistant group functionality of device trackers.

      So, in my groups YAML file I have

      Then let’s say I want an automation for when everyone has left the house to turn off my study lamp, the automation could be done in two ways. First using my dropdowns

      With the above, as soon as a dropdown changes to Away, the conditon against

      will ensure everyone is away.

      Another option could be to use a

      in the trigger against the all people group, like so

      Where the number of minutes is equal to the same

      you use in your automations between states.

      • Glenn Delmotte

        Hey Phill,

        When one of us is still at home nothing happens and that is is fine. When someone is already away and the other one leaves also everything works as it should. But when Both of us leave at the same time or within 10 minutes of each other the automation triggers twice. Do you know a way to prevent this from happening?

        • Hey Glenn,

          Sure, you’ve got two options. I’m guessing you have an automation setup something like this?

          You can either add a condition, so that the automation only fires once within x minutes, using a template condition. So, the example above would be:

          Another option is to instead use the default Home Assistant group behaviour of device trackers. So, once everyone is marked as not home, like this:

          That requires you have a group with all of your device trackers (not the input_select’s) in a Home Assistant group.

          Hope that helps!

          • Glenn Delmotte

            Thanks!

  • Jorge Assunção

    Hi Phil, great job you’ve done! I’m having a small problem on the automation because i need to track three persons. I’ve changed:

    entity_id: >
    {% if trigger.entity_id == ‘input_select.jorge_status_dropdown’ %}
    input_select.jorge_status_dropdown
    {% else %}
    input_select.lara_status_dropdown
    {% endif %}

    into this:

    entity_id: >
    {% if trigger.entity_id == “input_select.jorge_status_dropdown” %}
    input_select.jorge_status_dropdown
    {% elif trigger.entity_id == “input_select.lara_status_dropdown” %}
    input_select.lara_status_dropdown
    {% else %}
    input_select.bia_status_dropdown
    {% endif %}

    But i get this automation error in Home Assistant log:

    ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: Expected an expression, got ‘end of statement block’) for dictionary value @ data[‘action’][0][‘data_template’][‘entity_id’]. Got None.

    What am i doing wrong?

    • Hey Jorge,

      That’s so strange. So I copied your template into my Home Assistant to check that the syntax was correct, and it seems fine to me.

      In your config.yaml is your spacing correct?

      • Jorge Assunção

        yes it is. It stopped giving error when i wrapped it inside comas.

        entity_id: >
        “{% if trigger.entity_id == ‘input_select.jorge_status_dropdown’ %}
        input_select.jorge_status_dropdown
        {% elif trigger.entity_id == ‘input_select.lara_status_dropdown’ %}
        input_select.lara_status_dropdown
        {% else %}
        input_select.bia_status_dropdown
        {% endif %}”

        but i don’t know if it is working because state doesn’t change…

        If i check the syntax inside Developer Tools – Templates gives me the error (Error rendering template: UndefinedError: ‘trigger’ is undefined).

        • So in the developer tools, it will error because trigger is only available inside automations, so that makes sense. I replaced trigger with state, just to check the syntax.

          I have a feeling that using the double quote ” might have been the issue here. In your first example you had

          In your second example, using

          seemed to do the trick.

          So, now I’m looking at the code you’ve supplied and I’m not sure what it is trying to do. I think it should be

          You want to change the input_select based on what device_tracker entity gets updated. In your code. Try that out, and if it still doesn’t work can you post your automation?

          • Jorge Assunção

            Hi Phill. Thank you for your answer. It’s all working now!

  • Andrey Laptev

    Hello Phil.

    How do you keep persistence of template sensor during reboot?

    • So that’s a tricky one actually. For some reason Home Assistant is meant to remember the state of the dropdowns on reboot, but for some reason it doesn’t quite work for these.

      Yesterday I was doing some config changes remotely and restarting Home Assistant when I noticed we were being marked as Home, even though we were both away at work. I ended up adding an automation for each person to cover it. For example I added this automation so when HA boots, I am marked as away if my device tracker is “not_home”.

      You could also add another one to mark you as Home when it reboots.

      • Andrey Laptev

        Do you use initial attribute in your input_select config?
        I think it overrides remembered state.
        I have it in config and every time Hass reboots input_select goes to initial value.

        • So, I have one setup for me, but not one setup for my SO. So it seems it doesn’t matter if I use initial_state of not against the input_select it always seems to default people to Home for some reason.

  • – wιlғred

    Hi Phil,

    Nice approach! Question: why do you use entity_id: group.helen instead of something like entity_id: device_tracker.helen on row 61 of automation.yaml?

    • That’s an easy one 🙂

      I use multiple device trackers for my SO’s phone. She has an iPhone, which goes to sleep frequently so her Bluetooth and Wifi aren’t reliable.

      I track her iPhone with both WiFi and Bluetooth. So, if her bluetooth chip goes to sleep, the WiFi tracker will still “see” her as home, because her phone would still be connected to the WiFi.

      So, I have her group setup as

  • Mark Rennie

    I just wanted to say thanks Phil, this is genius and is working a treat on my system. I was always wanting to use something like this, now I can 🙂
    I also have grafana working following your guide, after failing a few months ago. I love stats!!

  • sangve

    Awesome work Phil!

  • Mark Reyes

    This is Awesome Phil! I’m adding to my HA config and looking forward to adding notifications based on state.
    I noticed some depreciation messages when testing in my dev instance:

    2018-01-24 01:04:15 WARNING (MainThread) [homeassistant.components.sensor.template] The 'entity_id' option (with value 'input_select.mark_status_dropdown') is deprecated, please remove it from your configuration.

    To clear this message, comment out the entity_id in the sensor template:

    mark_status:
    value_template: '{{ states.input_select.mark_status_dropdown.state }}'
    friendly_name: 'Mark'
    # entity_id: input_select.mark_status_dropdown

    Thanks again for the detailed walk through!

    • Hey Mark!

      Thanks so much for pointing that out. It seems as though that has been deprecated in the latest release. So I’ll update the code above for future readers!

      • Mark Reyes

        Hey Phil,
        I noticed another ‘edge case’ scenario: If the device tracker used to trigger the input_select.status_dropdown is out of range and HASS is restarted. Since the input_select is set with initial state of ‘home’ and there is no state change to trigger, then sensor.mark_status never transitions from ‘home’ even when device is not home.

        Steps to recreate: turn off your device’s wifi, restart HASS.
        IE: if you’re out for a week vacation, and your power resets, HASS will act as if devices are present.
        Possible solution: automation for a ‘backup-timmer’: if device_tracker is away for longer than +1hour, place into Away status…?
        (i’m checking into it too)

        • Oooh. That’s a good point. I’m usually restarting Home Assistant when everyone is home, so haven’t seen it. However your case of there being an unscheduled restart of HASS makes sense.

          I like your solution. I actually overcame this by adding another automation into the mix, which might be overkill. However adding another “for” trigger as you suggested might be cleaner.

          • Mark Reyes

            Awesome Phil! I think i’m going to merge that start trigger in, it’s cleaner than a running backoff timer. Thanks again!

          • Mark Rennie

            I was just back here to say exactly the same thing as I am going away shortly and, was wondering of there was anyway to retain the “extended away” status after a reboot. This would work fine, but it would need to wait another 24 hours for it to be extended away again, therefore run my away on holiday scripts..

          • Ah that’s a conundrum.

            When you restart home assistant, its internal timers for how long each device has been in a state will be reset.

            You could have it so when people are marked as Extended Away, an input Boolean is turned on. When home assistant restarts, it will check if that is turned on. If it is, then everyone is marked as Extended Away instead of away.

  • Eduard Antonyan

    Thanks, this is great! FYI I used https://github.com/rogro82/hass-variables instead for a cleaner implementation that also retains status across restarts.

    • That looks like a handy component! Thanks for sharing

    • Vince M

      could you show how you interpreted Phil’s presence detection using the above variable component?

      • Eduard Antonyan

        After creating the variable phil_status, basically just search replace input_select.phil_status_dropdown with variable.phil_status, input_select.phil_status_dropdown with phil_status, and input_select.select_option with variable.set_variable.

        Because the variable state is preserved correctly across restarts you won’t need the restore automation (which only works partially anyway with the dropdown).

  • That’s awesome!

  • That’s awesome!

    • Vince M

      what exactly does this do?

      • teachingbirds

        Makes a device_tracker entity for the combined trackers.

        • wobbles

          I think i added it according to your link, but I’m not sure what to do to access it! Not listed as an entity..

  • Mauricio Bonani
  • How do you manage to show your photo at the sensor? Whatever I do with me it does not work 🙁

  • Fernando Tapia

    Hi, just read the post, very good tutorial, can you help to track 3 people, don’t know much about templates, thank you

    • You can use an else if where needed, so as an example

      Then apply that logic where needed.

  • Nikiya

    got some help from the discord and they cleaned it up a bit for multiple people


    - alias: Mark person as home
    trigger:
    - platform: state
    entity_id:
    - group.nikiya
    - device_tracker.amandaiphonelan
    - device_tracker.jacksiphonelan
    - device_tracker.iphonelan
    - device_tracker.mandysiphone8lan
    - device_tracker.iphonelan_2
    to: 'Just Arrived'
    for:
    minutes: 10
    action:
    - service: input_select.select_option
    data_template:
    entity_id: >
    {% set map = {
    'group.nikiya': 'input_select.nikiya_status_dropdown',
    'device_tracker.amandaiphonelan': 'input_select.amanda_status_dropdown',
    'device_tracker.jacksiphonelan': 'input_select.jack_status_dropdown',
    'device_tracker.iphonelan': 'input_select.alexa_status_dropdown',
    'device_tracker.mandysiphone8lan': 'input_select.mandy_status_dropdown',
    'device_tracker.iphonelan_2': 'input_select.steve_status_dropdown'
    } %}
    {{ map[trigger.entity_id] }}
    option: Home

    so I thought I’d pass it along to help

    • Nikiya

      formatting got messed up as I don’t know how to format code on here

    • Nice one!

      Just a heads up. I found that when I grouped my devices together like that in the trigger, sometimes only one of the group would fire if we got home at the same time.

      I haven’t personally used the map function yet. However, in your trigger, how will device_tracker.amandaiphonelan be marked as “Just Arrived”? The device_tracker will only ever be either home, or not_home, so that trigger will never fire?

      • Nikiya

        Yeah I’m finding that I still have corrections to be made in my setup, but the concept is good all the same, as I typed that it looks like I got the remainder of my kinks worked out

      • bisschopsr

        Hi Phil,
        Found your blog. it’ s awesome! I tried using this instructions for a three person household. And as you already mentioned, when two people leave together, only one will trigger the automation. This is caused by the if-elif-else. Did you find a way to fix this?

        Thanks

        Ralph

        • Thanks!

          I think one of the easiest ways might be to use different for timings, for example


          trigger:
          - platform: state
          entity_id: device_tracker.person_1
          to: 'not_home'
          - platform: state
          entity_id: device_tracker.person_2
          to: 'not_home'
          for:
          seconds: 10
          - platform: state
          entity_id: device_tracker.person_2
          to: 'not_home'
          for:
          seconds: 30

          This way if all three people leave at the same time, the automations will fire at slightly different times.

          • bisschopsr

            Thanks Phil. I had the same line of thinking, was curious if there was another way.

  • Jakob Tewes

    Brilliant idea! Looks really nice to me! Unfortunately the grouping of my sensors does not work :-(. The status of the group sensor is always “unknown”.
    Anyone an idea on how to fix this? Got everything in one “package” file:

    input_select:
    presence_status_jakob:
    name: Jakob
    options:
    – Home
    – Just Arrived
    – Just Left
    – Away
    – Extended Away
    initial: Home
    presence_status_katharina:
    name: Katharina
    options:
    – Home
    – Just Arrived
    – Just Left
    – Away
    – Extended Away
    initial: Home

    sensor:
    – platform: template
    sensors:
    presence_jakob:
    value_template: ‘{{ states.input_select.presence_status_jakob.state }}’
    friendly_name: ‘Jakobs Status’
    presence_katharina:
    value_template: ‘{{ states.input_select.presence_status_katharina.state }}’
    friendly_name: ‘Katharinas Status’
    presence_others:
    value_template: ‘{{ states.input_select.presence_status_others.state }}’
    friendly_name: ‘Others Status’

    group:
    presence_status_residents:
    name: Präsenz Status Bewohner
    entities:
    – sensor.presence_jakob
    – sensor.presence_katharina

    automation:
    – alias: Presence mark as just arrived
    trigger:
    – platform: state
    ……

    Thanks and regards,

    Jakob

    • Chad Derksen

      First, thank you Phil, this is really great, thank you!

      I basically have everything working except that the people_status group continues to indicate unknowm. Child person_status is ok. So the same as with Jacob. So I was wondering @Jakob Tewes did you solve this? Or @Phil Hawthorne , do you know where I am going wrong?

      Thnx up front for the reply! 🙂

  • Sylvia Wei

    Thanks for the tip.
    I did it in AppDaemon like this:
    https://gist.github.com/Sylph/7a2776e71e335cb52a3dcb2b32ebc0bc

  • Bradley

    Hey @teachingbirds:disqus, I just set your device tracker script up, it’s great to have the location info like a real tracker, thanks!

    It took me a while to get it working (had to figure out how to enable python scripts in home assistant), but now it’s up and running I have a few things I can’t seem to sort out.

    First of all, the devices don’t appear in the UI until there’s a change detected, so they disappear if I restart Home Assistant. Not sure if you have a better solution but I’ve created a script to trigger the python script, passing the data for each person, and I can use an automation to run it after a restart I guess, but that leads me to the second issue.

    After a restart custom images don’t appear unless I go in to customizations, remove them and add them again… and they are gone again after another restart. Any ideas on how I can resolve this?

    • teachingbirds

      Your solution with running an automation is the way to go I think. And I think the images have to be added in the python script as attribute to show up, since it basically overwrites the device tracker each update.

  • Marvyn

    Thanks for the post, it’s very userful! Now, I’m using two device_trackers on my phone(Wi-Fi and Bluetooth), the ‘mark person as just left’ automation will be triggered twice when I left home, which seems unnecessary. The status of input_select.person1_status_dropdown will be changed to ‘Just Left’ after the first automation is executed. But I am not sure after the second time it gets triggered, what will happen to the status of input_select.person1_status_dropdown? I know the status will definitely stay as ‘Just Left’, but how about the time it’s been tagged ‘Just Left’? If the time of the status ‘Just Left’ gets reset as 0 after the second execution, the automation ‘Mark person as home’ will be delayed. So if this is what will happen, we’d better add a condition to the automation.

    • Hmm if you’re using two device trackers, I would suggest using a group, then just use the group to track your state. Otherwise, you get a bit tricky with the scenario you described.

  • Hi Phil and fiorst of all thanks for a great intro and examples. I am currently running a test where I in adition us a Bayesian sensor to determine if we are home or not. I have a challenge though – when using the code described in the “Stopping the just arrived state” section, the code breaks after a reboot or a few occurances. What happens is that my kode is littered with n’s all over the place, leaving my YAML file unreadable. I am running hassio on a RPI 3, and I am running out of ideas here. Al the other automations are working flawlessly, but the “Just arrived” animation is causing me to pull my hair out .
    Best regards,
    Runar

    • Hey Runar,

      So are the n’s causing the YAML to break? If so, there might be a line-endings issue from your editor. For example if you’re editing in Windows -> HassIO and the line endings aren’t right, that might cause some headaches.

      • Hey Phil, I dove in here for some inspiration: https://yaml-multiline.info/ and tried to double quote the yaml. So far so good. It looks like it is working. Now I just have to figure out stability and detection issues in my Bayesian sensor. Thanks!

  • Dave

    Hi Phil

    Firstly, love the work and can see how this works in theory however my question is for multiple persons, and using A Better Presence as I believe this would be better combining the device_trackers in a group more effectively.

    So my question;

    I have adjusted the first automation corectly but somehow seem to not be able to get my head round the jinja template needed for the remainder of the automations and I was hoping you could help me out here, this is all what I have done so far;

    - alias: Mark person as just arrived
    trigger:
    - platform: state
    entity_id: device_tracker.dave_presence
    from: 'not_home'
    to: 'home'
    - platform: state
    entity_id: device_tracker.angel_presence
    from: 'not_home'
    to: 'home'
    - platform: state
    entity_id: device_tracker.dani_presence
    from: 'not_home'
    to: 'home'
    action:
    - service: input_select.select_option
    data_template:
    entity_id: >
    {% if trigger.entity_id == 'device_tracker.dave_presence' %}
    {% if states.input_select.dave_status_dropdown.state == 'Just Left' %}
    Home
    {% else %}
    Just Arrived
    {% endif %}
    {% elif trigger.entity_id == 'device_tracker.angel_presence' %}
    {% if states.input_select.angel_status_dropdown.state == 'Just Left' %}
    Home
    {% else %}
    Just Arrived
    {% endif %}
    {% else %}
    {% if states.input_select.dani_status_dropdown.state == 'Just Left' %}
    Home
    {% else %}
    Just Arrived
    {% endif %}
    {% endif %}

    Trying to work out the other parts of the automations I constantly get errors regarding the jinja code and just can’t work it out – can you help me?

    Also, best place to learn Jinja – thoughts anyone??

    Thanks in Advance

    Dave

    • Hey Dave,

      Just checking that automation. It looks like your setting the entity_id to the status. So you’re trying to update the entity ID to “Just Arrived” for example. Maybe a copy-paste issue?

      • Dave

        The code I pasted up there, granted not in-line, however correct and working for the ‘Mark Person as Just Arrived’ automation, what I’m struggling with the most is the other ‘Mark person as home’, ‘Mark person as just left’, ‘Mark person as away’ and ‘Mark person as extended away’ automations.

        Reading from the posts on here and the tip you gave Fernando Tapia, I managed to get the first automation working but not the other ones as it’s always a problem with the jinja I’m entering (of which I don’t really understand – reason for me asking where to learn it).

        I basically used this code;

        {% if trigger.entity_id == ‘device_tracker.person_one’ %}
        {% if states.input_select.person_one_status_dropdown.state == ‘Just Left’ %}
        Home
        {% else %}
        Just Arrived
        {% endif %}
        {% elif trigger.entity_id == ‘device_tracker.person_two’ %}
        {% if states.input_select.person_two_status_dropdown.state == ‘Just Left’ %}
        Home
        {% else %}
        Just Arrived
        {% endif %}
        {% else %}
        {% if states.input_select.person_three_status_dropdown.state == ‘Just Left’ %}
        Home
        {% else %}
        Just Arrived
        {% endif %}
        {% endif %}

        Modifying it accordingly and it works fine – just now, as I lack jinja template knowledge, not sure how to go about adjusting the other automations so it works. Admittedly I did copy/paste to get your version of making things look and feel more fluent, shame on me for not having more knowledge in the jinja templating language…

        Hopefully you understand what my issue is now more clearly (I don’t do jinja) and fingers crossed I get to understand more jinja 🙂

        • Interesting.

          For jinja resources I rely heavily on the template test section in Home Assistant itself. Then of course the official jinja2 docs.

          For the other automations, I am not sure where you’re running into issues. The code in the post looks correct to me, so you should just have to replace Phil and Helen with your entity IDs, and they should work.

          Perhaps seeing someone elses code might help? This looks like a good repo which has three people tracked using my method

          https://github.com/DubhAd/Home-AssistantConfig/blob/master/automation/people/people_status_left.yaml

  • Asaf Davidof

    hi
    just added this code to my HA
    i done that outside my home (from work)
    so, now my sensor show i home cuz it waiting to the trigger > juft left.
    can some thing be done about it?

    • Sure, from the dropdowns in your UI either select “Just Left” or “Away”. Alternatively from Developer Tools -> States change the value from there against your input_select elements.

      • Asaf Davidof

        thank you! i meant maybe to add automation that check it against the device tracker current mode…

        • Oh right. Here is what I use which is triggered when Home Assistant is started

  • Sprint

    Hi Phil, I have tried to use your creation of presence detection as my household has two people too.
    I copied everything and changed variables, names etc. to my devices, trackers and so on. My device got showed reliable but my wife’s not. My wife is everytime unknown because the second dropdown seems to fail and will not created. So my dropdown is present and get the infos from my device tracker but I don’t know what to do with my wife. Can you help me out?
    Thanks dennis

    • Hey Dennis,

      Are you able to put your config for the dropdowns in a hastebin or post here so I can see? Sounds like the dropdown has some issues which is throwing everything off

      • Sprint

        input_select:
        dennis_status_dropdown:
        name: Dennis
        options:
        – Home
        – Just Arrived
        – Just Left
        – Away
        – Extended Away
        initial: Home

        sensor:
        – platform: template
        sensors:
        dennis_status:
        value_template: ‘{{ states.input_select.dennis_status_dropdown.state }}’
        friendly_name: ‘Dennis’
        sabrina_status:
        value_template: ‘{{ states.input_select.sabrina_status_dropdown.state }}’
        friendly_name: ‘Sabrina’
        I need two dropdowns to manage two people right? Why is there only one input select template? Sorry for no right format but it’s all over my mobile, a little bit clumsy

        • Yep your code is missing a second input_select.. Try this

          • Sprint

            Yes that does the trick. Thank you for fast response.

  • Perc3val

    Really nice thank you very much!

  • Mark Ghali

    Phil,

    This is great thank you! Instead of using device trackers can we use the person.xxxx entity? Currently I have myself and wife as person.entity tied to device_tracker.mobile_apps which track work zone, home and away.

    Thanks for this great write-up

  • Trevor Watt

    I actually applied this methodology to a bed sensor.
    added states for:
    – Just Laid Down
    – Asleep
    – Just Left Bed
    – Back to Bed
    – Bed Empty
    Works great!

  • Benjamin Piraro

    https://uploads.disquscdn.com/images/f933aa3db8bca24589e1ebe0accdbff70bf7676b51447b614b295f5fb3d57402.png Tried implementing this…. realize this write up is a couple years old and some things have changed.
    I’m able to get the “People Status” card up and populated…. however it has a huge lag in updating as compared to the using the of the box entities card.
    Also noticed the code required in the automations.yaml is different now…. it does accept the old style, but it will reformat it once saved.

    Wondering if it would be possible to revise this to fit in the new HA standards?

    • Hey Ben,

      Not sure why there is a delay. Guess it depends on how you’ve setup the automations.

      Yeah this article will probably need a do-over soon, especially since how much Home Assistant has matured and grown since I wrote this.

      • Benjamin Piraro

        Thanks for the quick reply!…. have also been trying to keep up with all the comments, I see you updated your write-up once, just unsure if there are bits/pieces still lingering in the comments to fish out? Would definitely appreciate a makeover on this. Its the most indepth/informative I have come across.

  • O.M. G.

    Hi,
    thanks for your tutorial. 🙂

    I’ve got a questions regarding the group sensor. In my case it’s always “unknown” no matter what the states of both members is. From my understanding groups for device tracker either have the status “home” or “not home”. In case one member is home the status of the group sensor is “home”. How is this supposed to work with five different states for each member?

  • Martijn van der Pol

    Hi Phil,

    Stumbled upon your post. I really liked the idea, but with all the developments in Home Assistant it can be done using a template sensor now 🙂

    So I wrote this sensor, maybe it can be helpful for others as well:
    A few issues however:
    If your restart Home Assistant or the template entities while in another state as ‘Home’ or ‘Away’, the state will become ‘Home’ or ‘Away’ (depending on the state of the person entity)
    If you visit another zone within 10 minutes after leaving home, the sensor will stay in the state ‘Just left’, but I think you solution has the same issue.

    template:
    trigger:
    - platform: state
    entity_id: person.thefes
    to: "home"
    id: just_arrived
    - platform: state
    entity_id: person.mthefes
    to: "home"
    for:
    minutes: 10
    id: home
    - platform: state
    entity_id: person.thefes
    from: "home"
    to: "not_home"
    id: just_left
    - platform: state
    entity_id: person.thefes
    from: "home"
    to: "not_home"
    for:
    minutes: 10
    id: away
    - platform: state
    entity_id: person.thefes
    to: "not_home"
    for:
    hours: 24
    id: extend_away
    - platform: homeassistant
    event: start
    id: refresh
    - platform: event
    event_type: event_template_reloaded
    id: refresh
    sensor:
    - name: Home Status TheFes
    unique_id: ddcf1fc6-fd1d-465f-90c3-82818290595d
    state: >
    {% if trigger.id == 'just_arrived' and is_state('sensor.home_status_thefes', 'Just Left') %}
    Home
    {% elif trigger.id == 'just_arrived' %}
    Just Arrived
    {% elif trigger.id == 'home' %}
    Home
    {% elif trigger.id == 'just_left' %}
    Just Left
    {% elif trigger.id == 'away' %}
    Away
    {% elif trigger.id == 'extended_away' %}
    Extended Away
    {% elif is_state('person.thefes', 'home') %}
    Home
    {% else %}
    Away
    {% endif %}
    icon: mdi:human-male

  • Dick Pluim

    Hi, great implementation. Modified it to my needs… And also you use only an {% else %} but this will assume always the status of Helen has changed when it’s not your status who changed, at least that was happened here when I had put 4 people in, so I added another elif for the last person as well and an empty else (or no else at all).

    One thing though. Currently my wife is away and that was shown nicely but after some modifications in HA I restarted it a couple of times but after a restart the sensor says that she’s at home. Her device is still away as well as she is actually. What can cause the change of presence after a restart?

  • Cowboysdude

    I can’t even get a boring old presense sensor to work without trying to do this LOL This is REALLY good though!! Thank you, I’ll circle around to this when I can get a simple thing done….. 🙂

  • Mudd

    Just implemented this after returning from node red. Modified it slightly and will post for anyone who wants it. Prerequisites for my use is that the entity_ids which trigger are person entities named person.aname and input_selects named input_select.status_aname. The names need to correspond from the person to the input select. One of the benefits of this is that once you create the person and input select, there is little modification needed to the actual automation other than adding the entities to the entity_id list of each trigger (as opposed to having 5 triggers for each person you add.

    alias: 1 Better Presence
    description: ''
    trigger:
    - platform: state
    entity_id:
    - person.aname
    - person.bname
    from: not_home
    to: home
    id: Just Arrived
    variables:
    name: '{{ trigger.entity_id | replace (''person.'', '''') }}'
    - platform: state
    entity_id:
    - input_select.status_aname
    - input_select.status_bname
    id: Just Arrived
    to: Just Arrived
    for:
    hours: 0
    minutes: 10
    seconds: 0
    variables:
    name: '{{ trigger.entity_id | replace (''input_select.status.'', '''') }}'
    - platform: state
    entity_id:
    - person.aname
    - person.bname
    id: Just Left
    from: home
    to: not_home
    variables:
    name: '{{ trigger.entity_id | replace (''person.'', '''') }}'
    - platform: state
    entity_id:
    - input_select.status_aname
    - input_select.status_bname
    id: Away
    to: Just Left
    for:
    hours: 0
    minutes: 10
    seconds: 0
    variables:
    name: '{{ trigger.entity_id | replace (''input_select.status.'', '''') }}'
    - platform: state
    entity_id:
    - input_select.status_aname
    - input_select.status_bname
    id: Extended Away
    to: Away
    for:
    hours: 24
    minutes: 0
    seconds: 0
    variables:
    name: '{{ trigger.entity_id | replace (''input_select.status.'', '''') }}'
    condition: []
    action:
    - choose:
    - conditions:
    - condition: trigger
    id: Just Arrived
    sequence:
    - choose:
    - conditions:
    - condition: or
    conditions:
    - condition: template
    value_template: >-
    {{ is_state('input_select.status_' ~ name, 'Just
    Left') }}
    - condition: template
    value_template: >-
    {{ is_state('input_select.status_' ~ name, 'Just
    Arrived') }}
    sequence:
    - service: input_select.select_option
    data:
    option: Home
    target:
    entity_id: '{{ ''input_select.status_'' ~ name }}'
    default:
    - service: input_select.select_option
    data:
    option: Just Arrived
    target:
    entity_id: '{{ ''input_select.status_'' ~ name }}'
    - conditions:
    - condition: trigger
    id: Just Left
    sequence:
    - service: input_select.select_option
    data:
    option: Just Left
    target:
    entity_id: '{{ ''input_select.status_'' ~ name }}'
    - conditions:
    - condition: trigger
    id: Away
    sequence:
    - service: input_select.select_option
    data:
    option: Away
    target:
    entity_id: '{{ ''input_select.status_'' ~ name }}'
    - conditions:
    - condition: trigger
    id: Extended Away
    sequence:
    - service: input_select.select_option
    data:
    option: Extended Away
    target:
    entity_id: '{{ ''input_select.status_'' ~ name }}'
    default: []
    mode: parallel

    • Nice one!

    • bartoszx

      Hi Mudd

      Can you explain “rerequisites for my use is that the entity_ids which trigger are person entities named person.aname and input_selects named input_select.status_aname.’

      I cant make it to work. As I understand aname bname is just example so in my example it should looks like


      alias: 1 Better Presence
      description: ""
      trigger:
      - platform: state
      entity_id:
      - person.bart
      - person.magda
      from: not_home
      to: home
      id: Just Arrived
      variables:
      name: "{{ trigger.entity_id | replace ('person.', '') }}"
      - platform: state
      entity_id:
      - input_select.status_bart
      - input_select.status_magda
      id: Just Arrived
      to: Just Arrived
      for:
      hours: 0
      minutes: 10
      seconds: 0
      variables:
      name: "{{ trigger.entity_id | replace ('input_select.status_', '') }}"
      - platform: state
      entity_id:
      - person.bart
      - person.magda
      - person.ola
      id: Just Left
      from: home
      to: not_home
      variables:
      name: "{{ trigger.entity_id | replace ('person.', '') }}"
      - platform: state
      entity_id:
      - input_select.status_bart
      - input_select.status_magda
      id: Away
      to: Just Left
      for:
      hours: 0
      minutes: 10
      seconds: 0
      variables:
      name: "{{ trigger.entity_id | replace ('input_select.status_', '') }}"
      - platform: state
      entity_id:
      - input_select.status_bart
      - input_select.status_magda
      id: Extended Away
      to: Away
      for:
      hours: 24
      minutes: 0
      seconds: 0
      variables:
      name: "{{ trigger.entity_id | replace ('input_select.status_', '') }}"
      condition: []


      input_select:
      status_bart:
      name: Bart
      options:
      - Home
      - Just Arrived
      - Just Left
      - Away
      - Extended Away
      initial: Home

      status_magda:
      name: Magda
      options:
      - Home
      - Just Arrived
      - Just Left
      - Away
      - Extended Away
      initial: Home


      sensor:
      - platform: template
      sensors:
      bart_status:
      value_template: '{{ states.input_select.status_bart.state }}'
      friendly_name: 'Bart'
      magda_status:
      value_template: '{{ states.input_select.status_magda.state }}'
      friendly_name: 'Magda'

      • Mudd

        Correct, aname and bname are just spaceholders. Looking at what you pasted (assuming yaml format is correct), it seems overall fine. You do have a person.ola which is not being used in all the triggers and you dont havean input select for. Additionally, did you copy over the actions part as well?

        Have you looked at the show trace to see where its breaking down?

        • bartoszx

          Hi. Now I understand everything 🙂 Sensor is triggered by state of person. Everybody was at home because there was no change in state. After few days everything seem to work as expected except one thing. After HA restart everybody are at home again. Is there any way to update sensor after restart?

          • Mudd

            This was my implementation to fix that problem. Sorry tried posting a month ago but kept detecting as spam for some reason. Youll see I added a trigger for home assistant reboot and an associated sequence and seems to work for me.

  • Cowboysdude

    Everything works great!! Thank you but there is one small issue…… it says ‘Home’ instead of just Home….. how do I fix that?

  • Phil, Your blog is great!
    Check my version of the automation. It’s more compact and simple:
    https://github.com/KotBayun69/not-binary-presence

    • This is awesome! Thanks for sharing.

      It’s been so long since the original version and I’m still using the basics as described in my blog post. There’s so many new ways to skin this cat now

Start typing and press Enter to search