AND functions in an automation

I want to create a boolean AND function.
2inputs , 1output
only when the 2inputs are on , then the output is on.

i have a yaml , but actualy it is not 100% what i want to achieve.
because there is a delay used.

Question 1 : is it possible in an automatisation to achieve this boolean algabra ?
Question 2 : is it possible in 1 automatisation ?

kind regards ,

alias: and gate
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.a1
    to: "on"
  - platform: state
    entity_id:
      - input_boolean.a2
    to: "on"
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: input_boolean.a1
        state: "on"
      - condition: state
        entity_id: input_boolean.a2
        state: "on"
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.out
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.out
mode: restart

Conditions are ‘and’ by default.

alias: and gate
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.a1
    to: "on"
  - platform: state
    entity_id:
      - input_boolean.a2
    to: "on"
condition:
    - condition: state
      entity_id: input_boolean.a1
      state: "on"
    - condition: state
      entity_id: input_boolean.a2
      state: "on"
action:
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.out
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.out
mode: restart

There is no need for an automation. Use a legacy group, just set the all option to true.

group:
  ip_booleans:
    name: "ANDed IP Booleans"
    all: true # both must be on for on state
    entities:
      - input_boolean.a1
      - input_boolean.a1

Tom’s suggestion is the best way to implement what you want. But if you are wanting to learn how to do that in an automation just for the sake of learning, here is how you could achieve it.

Note that I use the choose function instead of an if-then statement but either way would work.

alias: and gate
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.a1
      - input_boolean.a2
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_boolean.a1
            state: "on"
          - condition: state
            entity_id: input_boolean.a2
            state: "on"
        sequence:
          - service: input_boolean.turn_on
            target:
              entity_id: input_boolean.out
    default:
      - service: input_boolean.turn_off
        target:
          entity_id: input_boolean.out
mode: restart
1 Like

a legacy group is not possible via the GUI :
check this : 2022.04 - groups feature - how to group input.boolean entities?