Testing for multiple state conditions of a device tracker

I would like to have an automation fire only if I am not home. Trying a template that looks at is_state not_home which works fine if I am not at work. When I am there the state changes to keith_work and the automation condition is not triggered. Does anyone know of a method to test for all conditions while not home?

is_not_state “home” type of thing.

Why not using a condition?

automation:
- alias: "When not home"
  trigger:
  # here your trigger
  condition:
  platform: state
  entity_id: your_entity.id
  state: 'not_home'
  action:
  #your action here

Hi,

Thats essentially what I am doing. The problem was that the “not_home” state changed to “keith_work” when I get to the office. I was reading the Alexa page and saw that they had an if statement with an “and” situation in it. On a whim I tried the following and it works. Good thing I only have a couple of zones to deal with. If I had more than a few this would become a real issue. Again I wish that there was a way to do something like “is_state != home”. This would be a much cleaner way of excluding everything except “home”. Anyway, heres how I solved this issue.

condition:

  • platform: template
    value_template: “{{ is_state(‘device_tracker.keith_keithsphone’, ‘not_home’) or is_state(‘device_tracker.keith_keithsphone’, ‘keith_work’) }}”

I didn’t know you could use templating with device trackers. Could I use a method like this to change the displayed values of “home” and “away” to something like “on” and “off”? Could you possibly show an example? (I’m still new to HA but learning. Even started taking an intro Python course so I can understand better and possibly contribute)

So here is the condition that I am now using for testing for all situations where I am away from “home”. Note that its using the new HA 19.0 format and if yo only need to test for a couple of conditions using the new “and” or the new “or” formats for conditions might get you what you need.

condition:

  • condition: template
    value_template: “{% if states(‘device_tracker.keith_keithsphone’) != ‘home’ %}true{% else %}false{% endif %}”

To answer your question about changing the name of the zone I think you could create a zone and name it “on” instead of “home” and specify the GPS coordinates for that zone and get what you want. Only I can’t think of a way to rename the “not_home” default. All my zones are named and when I enter them the state gets that name, but when I am outside of any predefined zones its always “not_home”.