Help to set input.select based on device_tracker

I have been using device tracker to indicate home or away for a while now. Using Phil Hawthorne’s code https://philhawthorne.com/making-home-assistants-presence-detection-not-so-binary/

I have now add life360 and want to use the zones function to show where I am. This all works well but it has broken the startup automation.

There are 2 automations triggered at startup one for home and one for not_home that set the input select to Home or Away

- alias: set me home at startup
  trigger:
  - platform: homeassistant
    event: start
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: 'device_tracker.me'
        state: 'home'
  action:
  - service: input_select.select_option
    data_template:
      entity_id: input_select.me_status_dropdown
      option: Home

Now with zones the Device tracker state can be home or (any number of zone names)

My automation is now

- alias: set me home at startup
  trigger:
  - platform: homeassistant
    event: start
  action:
  - service: input_select.select_option
    data_template:
      entity_id: input_select.me_status_dropdown
      option: Home

How can I change the option: line to select Home when the device tracker is ‘home’ and Away for any other value

I tried this

      option: "{%if device_tracker.me == 'home' %}\n Home\n\
        {% else %}\n Away\n{%endif}\n"

but it just give an error when I check the config.

you can always use the template editor to test your templates.
What breaks here are the \n
Also you’re missing a % at the end of your endif

option: "{% if device_tracker.me == 'home' %}Home{% else %}Away{% endif %}"

Together we will get there.

still missing single speech marks around device_tracker.me

"{% if 'device_tracker.me' == 'home' %}Home{% else %}Away{% endif %}"

Found using template editor.

You’re not getting the state. You need to use the states() method or states object to get the state. Also, you can use the is_state() method to check the current state.

anyways, try

option: "{{ 'Home' if is_state('device_tracker.me','home') else 'Away' }}"

I really need to stop helping people between 2 calls at work :laughing:

Don’t worry, we all do it!

1 Like