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'
  trigger:
    ...
  condition:
    condition: template
    value_template: "{{ not is_state('climate.upstairs', 'off') }}"
  action:
    ...
10 Likes

This slightly different template works for me

  condition:
    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.

7 Likes

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'
    trigger:
      platform: time
      at: '07:30:00'
      weekday:
        - mon
        - tue
        - wed
        - thu
        - fri
    condition:
    entity_id: sensor.hall_motion_sensor
    state: on
    for:
      hours: 24
    action:
      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?

sensor:
  - platform: template
    sensors:
      someone_home:
        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

Have you tried something like this:

condition:
 - condition: template
       value_template: "{{ not is_state ('sensor.weather, 'clear') }}"
3 Likes

does that work??

As long as you’re using the right sensor it should. I use “{{ not is_state ('person.me, ‘home’) }}” for a lot of my automations as it works regardless of whether the person.me state is not-home or away.

I am fairly sure this would now be possible with this?

2 Likes