Skip to content

Add NOT condition helper#34624

Merged
balloob merged 2 commits intodevfrom
frenck-2020-0433
Apr 24, 2020
Merged

Add NOT condition helper#34624
balloob merged 2 commits intodevfrom
frenck-2020-0433

Conversation

@frenck
Copy link
Copy Markdown
Member

@frenck frenck commented Apr 24, 2020

Proposed change

Add support for a NOT condition. Currently, Home Assistant does not have an option check for a condition you don't want. Which makes templates the last resort.

An example of a good use case, can be things like:

  • Person NOT home
  • Alarm NOT disarmed

This PR introduces a not condition wrapper, basically introducing a NAND for all the conditions provided to it.

Frontend PR: home-assistant/frontend#5616

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example automation
alias: Turn kitchen lights off when alarm is armed.
trigger:
  - platform: state
    entity_id:
      - alarm_control_panel.home_alarm
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: alarm_control_panel.home_alarm
        state: disarmed
action:
  - service: light.turn_off
    data:
      entity_id:
        - light.kitchen

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it 👍

Copy link
Copy Markdown
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@frenck frenck marked this pull request as ready for review April 24, 2020 12:43
@balloob balloob merged commit c93c6a6 into dev Apr 24, 2020
@balloob balloob deleted the frenck-2020-0433 branch April 24, 2020 16:40
@Mariusthvdb
Copy link
Copy Markdown
Contributor

Mariusthvdb commented Apr 24, 2020

would a shorthand version:

condition:
  condition: state
  entity_id: alarm_control_panel.home_alarm
  not_state: disarmed

be possible also?

@frenck
Copy link
Copy Markdown
Member Author

frenck commented Apr 24, 2020

@Mariusthvdb A bit off-topic/different feature request.

Yes, it is, but there are many approaches to that. It is definitely on my list to explore. This is a start, which can be applied to all conditions (or multiple even) we have.

@Mariusthvdb
Copy link
Copy Markdown
Contributor

Cool! Thanks for your work so far ! It’s just that @pnbruckner and I discussed this recently on the community. You can imagine how welcome this addition to the Ha toolbox is.

@lock lock Bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants