Input Boolean mutually exclusive

I have two input boolean switches: “Relax” and “Work”.
Right now, I use two automations and I would like to use only one!
Is it possible ?

  • id: ‘Sveglia_Work_To_Relax’
    alias: Wake Work To Relax
    initial_state: true
    trigger:

    • platform: state
      entity_id: input_boolean.svegliarelax
      from: ‘off’
      to: ‘on’
      action:
    • service: input_boolean.turn_off
      entity_id: input_boolean.svegliawork
  • id: ‘Sveglia_Relax_To_Work’
    alias: Wake Relax To Work
    initial_state: true
    trigger:

    • platform: state
      entity_id: input_boolean.svegliawork
      from: ‘off’
      to: ‘on’
      action:
    • service: input_boolean.turn_off
      entity_id: input_boolean.svegliarelax
1 Like
alias: blah
  trigger:
    - platform: state
      entity_id: input_boolean.svegliarelax, input_boolean.svegliawork
      from: 'off'
      to: 'on'
  action:
    service: input_boolean.turn_off
    data_template:
      entity_id: >
        {% set booleans = [ 'input_boolean.svegliarelax', 'input_boolean.svegliawork' ] | reject('equalto', trigger.entity_id) | list %}
        {{ booleans[0] }}

This will only work for a pair of input booleans. If you want to do this with more input_booleans:

alias: blah
  trigger:
    - platform: state
      entity_id: input_boolean.svegliarelax, input_boolean.svegliawork, input_boolean.other
      from: 'off'
      to: 'on'
  action:
    service: input_boolean.turn_off
    data_template:
      entity_id: >
        {% set booleans = [ 'input_boolean.svegliarelax', 'input_boolean.svegliawork','input_boolean.other' ] | reject('equalto', trigger.entity_id) %}
        {{ booleans | list | join(', ') }}
7 Likes

Thanks @petro!

I get:

ERROR (MainThread) [homeassistant.core] Invalid service data for input_boolean.turn_off: Entity ID is an invalid entity id for dictionary value @ data['entity_id']. Got ''

Which method did you use?

Edit: I adjusted the top method, it had an issue.

It works! :wink:
Thanks @petro

1 Like

Brilliant - thank you for this @petro. Cut a growing automation down a single action. Simplistic and beautiful :slight_smile:

1 Like