"NOT" in conditions?

In the condition section of an automation you can combine conditions with AND and OR. But having googled hard, I can’t find any way to handle “not”.

My specific case is I’m trying to implement an automation that should run when someone goes out (trigger) leaving nobody home. So the triggers are I leave the home zone or the missus leaves the home zone. But the condition has to be that I am NOT in the home zone and the missus is also NOT in the home zone. I dont care where else we are, just that we are NOT in the home zone.

How do I express this?


I’d just use a template, specify the condition you want and then stick a not at the beginning.
Though I guess you are fairly new so this won’t mean a lot.
Can you post your automation and we’ll give it a go at transforming it.
Make sure you list relevant entities even if you have to list them separately

Thanks Mutt - yes, first weekend with HAss. I’ve approximated the configuration through the web interface, and here’s what’s in the automations.yaml file (excerpt):

- id: '1581280981013'
  alias: Everyone Goes Out
  description: ''
  - entity_id: device_tracker.life360_gordon
    event: leave
    platform: zone
    zone: zone.fhc
  - entity_id: device_tracker.life360_sharon
    event: leave
    platform: zone
    zone: zone.fhc
  - condition: zone
    entity_id: device_tracker.life360_gordon
    zone: zone.fhc
  - condition: zone
    entity_id: device_tracker.life360_sharon
    zone: zone.fhc
  - service: rest_command.alllightsoff
  - service: rest_command.heatingoff

now, I need to change the condition section above to implement
“gordon is NOT in zone FHC AND sharon is NOT in zone FHC”
but I can’t find any syntax that will deliver that.

Are you saying that using a template that is something like IF gordon is in zone FHC THEN FALSE ELSE TRUE ? I can see that might work, but it’s a lot of work for a NOT!


I use a group for that.

    name: People & Devices
      - device_tracker.me
      - device_tracker.her

The group is ‘home’ as long as one of us is home and it’s ‘not_home’ only if both of us are not at home.

I’ve never worked with zones, but as the principle is the same for switches, etc. I assume you should be able to replicate it there, too.

Ouch !
Can you please read : -

This is the sticky at the top of the forum, that everyone should read.

Amongst other things it tells you how to format your code using “</>” (10th button in from the left above the text entry box (the thing I’m typing in right now)
This actually allows us to read your code better and comment upon spacing (essential in yaml)
What chairstacker says is correct as the ‘group’ of people is ‘home’ as long as any one individual is ‘home’ (BTW the antithesis of ‘home’ is ‘not_home’ despite what you might think and what the frontend shows you)
But this is not very flexible and ‘may’ cause you problems later on
Regardless you may wish to use this for the time being.

Untill you format you code correctly I can’t comment on that.
(hint: edit the post, highlight the section of code, unmark it (with whatever you marked it with) and with it still hightlighted hit the </> button

Issues you might face :-
What if you have contractors in to do some work/paint walls etc.
What if you have guests, can they not have heat or light if you pop out to collect the kids from school ?
So I normally have overrides : -

  1. Wife leaves phone at home, when we are 60 klicks away and heating is still on - Answer, Evict Wife (not literally just so her phone is not counted)
  2. Guests/Contractors are in the house, no heat or light - Answer, Force House Occupied

A not condition may look like this : -

      - condition: template
        value_template: "{{ not ((is_state('device_tracker.life360_sharon', 'home') and is_state('input_boolean.ib_occupied_sharon_evict', 'off')) or (is_state('device_tracker.life360_gordon', 'home') and is_state('input_boolean.ib_occupied_gordon_evict', 'off')) or is_state('input_boolean.ib_occupied_force_on', 'on')) }}"

This is a LONG line and I normally break this up into 2 binary sensors (for use elsewhere) and then amalgamate then into a similar condition.

Note how this uses : - not, and + or
This is just an example


Thanks Mutt.

Reformatted the config snippet above.

The intention of this automation (as with all of them I guess) is to automatically do what is generally right. Of course I have manual overrides for special situations/malfunctions.

Thanks for the template example. I’ll give that a go. I might also look at @chairstacker 's groups idea. Thank you both.

Not having “not” available through the web front end does seem like a bit of an oversight though!

Thanks all


Create a Feature Request if you want to see them.

Okay, keep us posted with anything that crops up.

The frontend Automation Editor is pretty much brand new.
It is a work in progress intended to help newbies with very basic automations. It will get better over time.
I started with HA long before it existed and a lot of the old hands (ie experienced not necessarily good :rofl: (but they usually are :smiley: ) ) distain it’s use as it’s not very flexible, does not cater for certain things and introduces new, apparently, unnecessary terms and orders them alphabetically rather than logically. But it’s a bullet we will ALL have to bite at some point as how can we help newbies unless we are familiar with the landscape ?
We tend to use text editors in varying degrees of complexity from notepad to applications like Visual Studio Code which looks at your whole environment. Different people, different strokes.
You will also find people who demand a higher level of language, so go the AppDaemon or Python route (a lot of commonality) or NodeRed which allows programming using blocks and links like lego - the blocks have different functions and you connect them from nodes on the blocks to other blocks to compare times or set values. These are all viable but do introduce an extra layer of software/overhead, many argue that if it can be done in pure yaml (basic and always supported) you should. I can and do, never met a challenge I couldn’t eventually get to work :crazy_face: But some of the guys here can write templates to do amazing things in only 3 lines of code :alien:

There are those here too who are obsessed with hardware (and who doesn’t like a bit of hardware :crazy_face: ) but they will ague that you need a NUC or other computer ‘so ditch the pi’. HA has been designed to run at the level to allow ‘most’ users entry at minimal cost (minimum pi 3) but you will get lots of opinions on many issues. Take all with a pinch of salt and make your own decisions, this is yor journey and it will probably consume a lot of your time, perfecting just ‘one more automation’

Welcome and Good Luck

P.S. Be careful about posting feature requests, the devs are mainly volunteers (a couple of them are paid by nebu casa funding but most just want to help) They have a finite amount of time to get a mountain of work done so will concentrate their efforts where they feel will yield the most results. Especially if there is a commonly used method to achieve the same result.
And remember that HA has not yet reached release candidate 1 yet, it is all a work in progress and we have to ensure that we don’t burden our ‘Awesome’ developers with detritus. :+1:

1 Like

Sorry, forgot to say : -

  1. Thanks for reformatting the code, the spacing is as much a part of the coding as the text.
  2. Are you happy with the creation of input_booleans etc. ?
  3. Do you need help construction the whole automation or do you need more assistance in some other way ?
  4. Try to use the search facility in the header, it will pay dividends and people will appreciate that you have spent some time and effort trying to sort your problem yourself rather than ‘demand a solution’

Thanks again Mutt.
The front end being a WIP makes a lot of sense. The automations I’m looking to create are pretty basic so shouldn’t really require learning ninja level YAML, but I’m getting there with notepad ++, much Google and some cargo cult debugging.

I’ve used groups for the “everyone has gone out” condition, and I’m hoping to test “only put the heating on when someone comes home if it’s cold out” tomorrow… when I get home. (lost an hour of “debugging” since it seems that the “execute” in the automation section of the UI runs the action even if the conditions aren’t met, rather than just triggering and evaluating the conditions).

I’ll dig into input text a little later - as a way to abstract my IFTTT key and to switch stuff off and on.

Thanks for your help.

Testing triggers sometimes requires setting the trigger just to turn on an input boolean.
It’s also advisable to have a couple of input booleans around and you can use one of them as a trigger so that you can properly test conditions and actions

I have so many automations based on location, that I built some specific sensors for each of my zones, here’s the one for my wife/I for HOME:

      friendly_name: "A & M Google Maps Home Sensor"
      value_template: >-
        {% if is_state('device_tracker.XXX', 'home') and is_state('device_tracker.YYY', 'home') %}
        {% elif is_state('device_tracker.XXX', 'home') %}
        {% elif is_state('device_tracker.YYY', 'home') %}
        {% else %}
        {% endif %}

      friendly_name: "A or M Google Maps Home Sensor"
      value_template: >-
        {% if is_state('device_tracker.XXX', 'home') or is_state('device_tracker.YYY', 'home') %}
        {% else %}
        {% endif %}

This creates both AND and OR sensors that I can then leverage in automations for triggers and/or conditions.

I replicated these for WORK, CHURCH, etc.

HA always has multiple ways to skin a cat, and this is the one that I’ve found that works for me. Realize this is solved, but wanted to show a different perspective.


For reference, nowadays it is easier. You can use the NOT condition in the visual editor. :slight_smile: