Home Assistant Community

NOT condition


With “and” and “or” we could have real logic.

My primary use would be for device tracking with multiple zones. If I have the zones “home”, “not_home” (whatever that is in this case) and “work”, I don’t want to check for
from: home
to: not_home
I really want to check for
condition: not
state: home
Because in some cases, depending on the speed of the state tracker, it might skip not_home and go directly to work, not triggering my automation.


That happened to me too. He often skips home and go straight to not_home
I want either a

- condition: state
  entity_id: device_tracker.iphone
  state: ! 'home'


- condition: state
  entity_id: device_tracker.iphone
  not_state: 'home'


- condition: not_state
  entity_id: device_tracker.iphone
  state: 'home'

I solved this by creating a templated sensor called “someone_home”. This is either “true” or “false”. You can easily add more devices to this sensor.


  - platform: template
        name: 'Is someone home?'
        entity_id: device_tracker.lorentz_iphone
        value_template: '{% if states("device_tracker.lorentz_iphone") != "home" %}false{% else %}true{% endif %}'


- alias: 'Turn off all lights if nobody is home'
    platform: state
    entity_id: sensor.someone_home
    from: 'true'
    to: 'false'
    condition: state
    entity_id: input_boolean.lights_away_auto_off
    state: 'on'
    service: script.kill_all_lights
1 Like

This would be good! I assume no updates yet?


I’m also looking for a IS NOT condition.


Ditto, I’d like a “not condition” as well


I need a NOT condition as well.


Here’s an example of a NOT condition using a template. This example triggers only when the upstairs thermostat is NOT off.

- alias: 'Example automation'
    condition: template
    value_template: "{{ not is_state('climate.upstairs', 'off') }}"

This slightly different template works for me

    condition: template
    value_template: "{{ states.sensor.last_motion.state != 'Bathroom Motion' }}"

This turns a bathroom light off if the last motion seen is NOT the bathroom motion detector.


I would also like to see this feature implemented soon. Using template syntax for lots of devices gets super messy. It would be nice to be able to just list them out like any other condition. Any ETA on this?


me too - on binary items (switches, lights) etc there is a rough workaround.

However on say alarm state with multiple options (if NOT armed), then arm
would take much more work to complete a workaround.


I would also like a NOT condition.

A workaround that works for me is functionality to switch on/off automations.

See https://community.home-assistant.io/t/automation-turn-on-off/9884


I have the following case for which i think i need a NOT option in conditions. I switch on a ‘decorative’ light on weekdays in the morning, for an hour. But i don’t want to do this when we’re on holiday. I have motion sensors, so i would like to state as a condition “only when no motion has been detected for 24 hours”.

Currently i have:

  - alias: 'decorative light on'
      platform: time
      at: '07:30:00'
        - mon
        - tue
        - wed
        - thu
        - fri
    entity_id: sensor.hall_motion_sensor
    state: on
      hours: 24
      service: light.turn_on
      entity_id: light.onoff_plug_1_2

I assume that would make this automation only trigger when there has been motion for 24 hours (or would it trigger if in the last 24 hours the state has at any time and for any period been ON?). I could state OFF instead of ON as condition state, but this would turn the lamp on only when there has been not motion in 24 hours and we’re on holiday or something ;-), which is the opposite of what i want .

So a NOT would be helpful, so a “state: !/not off” would mean ‘if the motion sensor has not been off for 24 hours’.


Your formatting is wrong, but that aside…

You need a template condition with a value template that the last time the sensor was on was within 24 hours. You can use the last_updated attribute for this.

I’m way too dopey to work out the exact contents of the template at the moment, but that’s a pointer to what you need.

Hope this helps.


Thank you, will look into that. (And already found out & fixed formatting)


I’m reviving an old thread, but I’m having this issue too and need some clarification.

I added my gas fireplace to HA. For safety reasons, I want an automation that will turn the fireplace off if it is accidentally turned on when neither my wife or myself are home. I have the automation created but needed a “not” condition to tell the system only to fire when we are not home. I like the idea of using the template posted by lorentz, but I’m not sure how to have the template sensor sense two device presences and return “false” is both are gone. How would I modify the code below to work with multiple devices and return a “false” if no device state is home?

  - platform: template
        name: 'Is someone home?'
        entity_id: device_tracker.lorentz_iphone
        value_template: '{% if states("device_tracker.lorentz_iphone") != "home" %}false{% else %}true{% endif %}'

I believe you can put your devices into a group. After that you can test whether the group is present or not. If one device is present, the group is present, but all devices must be away for the group to be away.


But both device trackers in a group. When at least one person is home, the group will be home, when nobody is home, the group will be not_home.

No templates required


Thanks guys, that worked!


This would be nice. Ideally, I would like to use this with a weather sensor so that if its NOT sunny or clear outside, turn on the lights 45 minutes before sunset.

Currently I can’t do this because there a too many conditions that are NOT ‘clear’, like rain, snow, cloudy, partly cloudly, mostly cloudy…etc…it’d be too tedious to create this automation…so a ‘NOT’ condition would be really cool