Multiple script

Hello,
Sorry for my english, i’m french. I’m newbies, thank you for your help.
I’m trying to do this, but I can’t:
If door 1 or door 2 is open, and the window group is closed, then only light 1 is active.
If door 1 or door 2 is open, and the window group is open, then only light 2 is active.
If door 1 and door 2 are closed, and the window group is open, then only light 3 is active.
If door 1 and door 2 are closed, and the window group is closed, then everything is off.

Here, if you can help me that would be nice.
Thank you all

Original
Bonjour,
Je suis débutants, merci de votre aide. Je cherche à faire ceci, mais je n’y arrive pas:
Si la porte 1 ou la porte 2 est ouverte, et que le groupe fenêtres est fermé, alors seule la lumière 1 est active.
Si la porte 1 ou la porte 2 est ouverte, et que le groupe fenêtres est ouvert, alors seule la lumière 2 est active.
Si la porte 1 et la porte 2 sont fermées, et que le groupe fenêtres est ouvert, alors seule la lumière 3 est active.
Si la porte 1 et la porte 2 sont fermées, et que le groupe fenêtres est fermé, alors tout est éteint.

Voici, si vous pouvez m’aider ce serait sympa.
Merci à tous

This assumes that when a door or windw is closed its binary sensor state is ‘off’:

automation:
  - trigger:
      - platform: state
          - entity_id: binary_sensor.door_1
          - entity_id: binary_sensor.door_2
          - entity_id: group.windows
    action:
      - choose:
          - conditions:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: binary_sensor.door_1
                    state: 'on'
                  - condition: state
                    entity_id: binary_sensor.door_2
                    state: 'on'
              - condition: state
                entity_id: group.windows
                state: 'off'
            sequence:
              - service: light.turn_on
                entity_id: light.light_1
              - service: light.turn_off
                entity_id: light.light_2
              - service: light.turn_off
                entity_id: light.light_3
          - conditions:
              - condition: or
                conditions:
                  - condition: state
                    entity_id: binary_sensor.door_1
                    state: 'on'
                  - condition: state
                    entity_id: binary_sensor.door_2
                    state: 'on'
              - condition: state
                entity_id: group.windows
                state: 'on'
            sequence:
              - service: light.turn_off
                entity_id: light.light_1
              - service: light.turn_on
                entity_id: light.light_2
              - service: light.turn_off
                entity_id: light.light_3
          - conditions:
              - condition: state
                entity_id: binary_sensor.door_1
                state: 'off'
              - condition: state
                entity_id: binary_sensor.door_2
                state: 'off'
              - condition: state
                entity_id: group.windows
                state: 'on'
            sequence:
              - service: light.turn_off
                entity_id: light.light_1
              - service: light.turn_off
                entity_id: light.light_2
              - service: light.turn_on
                entity_id: light.light_3
          - conditions:
              - condition: state
                entity_id: binary_sensor.door_1
                state: 'off'
              - condition: state
                entity_id: binary_sensor.door_2
                state: 'off'
              - condition: state
                entity_id: group.windows
                state: 'off'
            sequence:
              - service: light.turn_off
                entity_id: light.light_1
              - service: light.turn_off
                entity_id: light.light_2
              - service: light.turn_off
                entity_id: light.light_3

There are also a couple of other options which may simplify your triggers/conditions, although they are not necessary to achieve what you want to do.

You could create a new group containing the two door sensors. The group should report on if either door is open, or off it they are both closed, so you can use the group in your automations in place of checking each door individually.

You could also create a binary sensor for your doors which reports a single status - either on if one of the doors is open, or off if both are closed. The config would be something like this:

binary_sensor:
  - platform: template
    sensors:
      doors_open:
        value_template: >-
          {{ is_state('binary_sensor.door_a','on') or is_state('binary_sensor.door_b','on') }}
        device_class: opening

Ok I’m looking at this and keep you posted.
Thank you

Ok je regarde ça et vous tiens informé.
Merci

Hello,
I made a second group for the gates as recommended by EKC and modified the automation of Tom_I to take this new group into account.
Everything is OK.

Thank you very much for your help

1 Like