NOT Condition possible?

How can I have an automation condition that passes when a condition is NOT satisfied?

Background: I have an automation that runs AC in Dry mode when humidity exceeds X percent.
Issue: this runs even when I previously set mode to Cool. I don’t want this.
Question: how do I limit my automation so it does not run when already in Cool mode? The editor only lets me pick “AC is set to a specific HVAC mode”. I’d basically like an “AC is NOT set to a specific HVAC mode” option.

trigger:
  - type: humidity
    platform: device
    device_id: feab63e34ffcdc250e0284838d497114
    entity_id: sensor.ble_humidity_living_room_sensor
    domain: sensor
    above: 53
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
condition:
  - condition: time
    after: '07:50'
    before: '22:30'
action:
  - service: climate.set_hvac_mode
    target:
      device_id: 83e6ff5154b8c396f590d02f2d737675
    data:
      hvac_mode: dry
mode: single

Yeah, there is just a NOT condition in HA. If the HVAC state is just set as state of the climate-entity it’s just:

trigger:
  - type: humidity
    platform: device
    device_id: feab63e34ffcdc250e0284838d497114
    entity_id: sensor.ble_humidity_living_room_sensor
    domain: sensor
    above: 53
    for:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
condition:
  - condition: time
    after: '07:50'
    before: '22:30'
  - condition: not
    conditions:
      - condition: state
        entity_id: climate.whatever
        state: Cool
action:
  - service: climate.set_hvac_mode
    target:
      device_id: 83e6ff5154b8c396f590d02f2d737675
    data:
      hvac_mode: dry
mode: single

Should also be possible to use a device condition rather then a state condition.

1 Like

Don’t use device triggers/conditions unless you know you want it.
Always use state as much as possible.

PS: I should open a FR to rename “Device” to “zz-Device” :smiley:

@koying I don’t use them often myself but why not use them?

Because less experienced user just pick that one because it’s first in the list in the UI :wink:

aha! I thought the NOT was to “Test multiple conditions in one condition statement. Passes if all embedded conditions are not valid.” as per documentation. I didn’t know it could be used for a single condition as well. Thanks!

Okay, so what?

1 Like

If you only add a single condition then all just refers to that single condition.

If Little Red Riding Hood only has a single apple in her basket she’s still able to give all the apples in her basket to grandmother :wink:

Because of that.
Although it likely is the same here, it’s not always the case.

Still, so what? Same applies to state. In both cases the answer is to enclose it in a NOT.

Still doesn’t work though.

This is the resulting automation. It still engages the Dry mode even when other modes are already running. I’m obviously bad with boolean logic because I can’t figure it out.

alias: AC - when humidity over 53, start Dry
description: ''
trigger:
  - type: humidity
    platform: device
    device_id: feab63e34ffcdc250e0284838d497114
    entity_id: sensor.ble_humidity_living_room_sensor
    domain: sensor
    above: 53
    for:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
condition:
  - condition: time
    after: '07:50'
    before: '22:30'
  - condition: not
    conditions:
      - condition: device
        device_id: 83e6ff5154b8c396f590d02f2d737675
        domain: climate
        entity_id: climate.daikinap64316
        type: is_hvac_mode
        hvac_mode: dry
action:
  - service: climate.set_hvac_mode
    target:
      device_id: 83e6ff5154b8c396f590d02f2d737675
    data:
      hvac_mode: dry
mode: single

Even with the Action - hvac_mode above changed to “cool”, it always turns on the Dry mode. It looks like it’s how I originally thought - the NOT condition is only for two or more conditions, as stated in the documentation. But I don’t know.

I just want the automation to NOT run when Cooling mode is already enabled.
EDIT: for the time being I just changed the second condition to “AC is set to mode: OFF” which prevents it to go to Dry when already in some else active mode.

Although it don’t see why not to use device-conditions, it does make checking for me harder. But, if you don’t want it to turn on when it is set to Cool, you should check for it Cool. Do you make the automation with the UI?

The documentation does not state that :wink: Little Red Riding Hood and all her apples, even if she at all but one.

NOT condition

Test multiple conditions in one condition statement. Passes if all embedded conditions are not valid.

It does to me…

It did engage Dry mode whether the “hvac_mode:” in the NOT condition was set to either Dry or Cool… I did reload automations after edits.

Because if you ever have to replace the device you are in for a lot of work. You cant change the new device id to match the old one in one place like you can do with entity ids. So you have to edit all your scripts and automations.

1 Like

Okay, the first sentence is indeed misleading. But I think the doc does that for all instances where you can use multiple things (triggers, conditions etc). But really, you can use a single condition. Heck, you can even use a single condition for an OR or an AND although there it really does not make sense…

But did you make the automation in the UI? If not, do so. And be sure to always post the latest version of an automation as a whole.

Oww, I fully agree it has downsides. But that does not justify a random “do not use” without a why.

Yes, in UI. Post 11 contains the entire automation. It did the same thing (engage Dry mode) with “hvac_mode: dry” and “hvac_mode: cool”

So it isn’t complete then :roll_eyes: Please don’t make us guess about changes, just post the most up to date version.

Okay, the device-condition does make debugging harder. Just switch to a state-condition. For that, can you post a screenshot of the entity id (with all of it’s attributes and set to the state you don’t want) in the development tools?

I don’t understand, it is complete. I can copy/paste it with the single word change if you want. Here goes, these both do the same thing.

alias: AC - when humidity over 53, start Dry
description: ''
trigger:
  - type: humidity
    platform: device
    device_id: feab63e34ffcdc250e0284838d497114
    entity_id: sensor.ble_humidity_living_room_sensor
    domain: sensor
    above: 53
    for:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
condition:
  - condition: time
    after: '07:50'
    before: '22:30'
  - condition: not
    conditions:
      - condition: device
        device_id: 83e6ff5154b8c396f590d02f2d737675
        domain: climate
        entity_id: climate.daikinap64316
        type: is_hvac_mode
        hvac_mode: dry
action:
  - service: climate.set_hvac_mode
    target:
      device_id: 83e6ff5154b8c396f590d02f2d737675
    data:
      hvac_mode: dry
mode: single
alias: AC - when humidity over 53, start Dry
description: ''
trigger:
  - type: humidity
    platform: device
    device_id: feab63e34ffcdc250e0284838d497114
    entity_id: sensor.ble_humidity_living_room_sensor
    domain: sensor
    above: 53
    for:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
condition:
  - condition: time
    after: '07:50'
    before: '22:30'
  - condition: not
    conditions:
      - condition: device
        device_id: 83e6ff5154b8c396f590d02f2d737675
        domain: climate
        entity_id: climate.daikinap64316
        type: is_hvac_mode
        hvac_mode: cool
action:
  - service: climate.set_hvac_mode
    target:
      device_id: 83e6ff5154b8c396f590d02f2d737675
    data:
      hvac_mode: dry
mode: single

This is the entity