Multiple actions sensor

Hi All,

New to the whole automation scene, but so far I’ve got HA running on my NUC and multiple lights connected.

Today I’ve received a door trigger. Trigger is connected and the state changes as expected. In my automation overview I’ve created two automations:

Automation 1: door is open turn on light
Automation 2: door is closed turn of light

If I continue with all automations like this the list will grow rapidly. Can’t I create 1 automation that checks triggers on the state of the sensor and either turns on or off the light, such as if then else. Basically grouping actions.

I’m sure you get questions like these more often, but I couldn’t find an answer via Google or this forum.

Thnx.

Use the “Wait until trigger”.

Automation 1:
Trigger:
door opens

Condition:

Actions:
Turn on light
Wait until trigger: Door is closed
Turn off light


automation:

- id: '202210171134'
  alias: Arbeitsplatte
  description: /packages/automationen/arbeitplatte.yaml
  mode: restart

  trigger:
  - platform: state
    entity_id: binary_sensor.bewegungsmelder_kuche
    from:
    - 'on'
    - 'off'
    to:
    - 'on'
    - 'off'

  action:
  - service: light.turn_{{ trigger.to_state.state }}
    target:
      entity_id: light.arbeitsplatte