Condition only for one action in the automation

Hello all,

is it possible to attach a condition to only one action?

Here is my automation:

alias: Sonnenuntergang
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "00:05:00"
condition:
  - condition: or
    conditions:
      - condition: device
        device_id: 27a90dfd9f98f3df6efd493ab873d50f
        domain: device_tracker
        entity_id: a2d77cdce2a69a14192baa3ddecc7000
        type: is_home
      - condition: device
        device_id: 9d4ca7a15ccfaca43006e9f449094770
        domain: device_tracker
        entity_id: fbce6fe67da003294766103153380e65
        type: is_home
action:
  - device_id: b7d1457bd4e25eb87848b81ca97426a2
    domain: cover
    entity_id: cover.esszimmer
    type: set_position
    position: 0
  - device_id: 9a60a49cf566edd42859ec1ce079829c
    domain: cover
    entity_id: cover.wohnzimmer
    type: set_position
    position: 0
  - device_id: ba19b3f7f239513e4d84045133738d80
    domain: cover
    entity_id: cover.buro
    type: set_position
    position: 0
  - device_id: c657988920e07c7891b84f204883607a
    domain: cover
    entity_id: cover.kuche
    type: set_position
    position: 0
  - device_id: 294678bdd220ab375534f9385c5a58c3
    domain: cover
    entity_id: cover.schlafzimmer
    type: set_position
    position: 0
  - device_id: d6cf684ac218f79548dc36cbfc761d0a
    domain: cover
    entity_id: cover.kinderzimmer
    type: set_position
    position: 0
  - type: turn_on
    device_id: fc19f3018666befb21bb29e34f739434
    entity_id: 9b6dee13c8a6cdeef7e9be35b1b031eb
    domain: light
mode: single

I just want to link the last action (turn_on light) to the condition if one of the two iPhones is at home.

Thanks in advance.

Greets

use choose. It allows you to write a condition for a set of actions. If the condition is not met, it does nothing. You can also use if then else.

I am a German guy from the Black Forest and my English is not so good.

Could you briefly explain this to me based on my automation above?

That would be terrific.

Using the UI, use

and fill out the information.

If-then is probably the easier choice.

Can you tell if this is correct?

choose:
      - conditions:
          - condition: device
            device_id: 9d4ca7a15ccfaca43006e9f449094770
            domain: device_tracker
            entity_id: fbce6fe67da003294766103153380e65
            type: is_home
        sequence:
          - type: turn_on
            device_id: fc19f3018666befb21bb29e34f739434
            entity_id: 9b6dee13c8a6cdeef7e9be35b1b031eb
            domain: light
      - conditions:
          - condition: device
            device_id: 27a90dfd9f98f3df6efd493ab873d50f
            domain: device_tracker
            entity_id: a2d77cdce2a69a14192baa3ddecc7000
            type: is_home
        sequence:
          - type: turn_on
            device_id: fc19f3018666befb21bb29e34f739434
            entity_id: 9b6dee13c8a6cdeef7e9be35b1b031eb
            domain: light

Option 1 is that my iPhone is at home. Option 2 is that my wife’s iPhone is at home.

That will work.

great, thanks for your help.

1 Like

Hi together,

I have tested this but unfortunately it does not work after all. Here is the full automation:

alias: Sonnenuntergang
description: ""
trigger:
  - platform: sun
    event: sunset
    offset: "00:05:00"
condition: []
action:
  - device_id: b7d1457bd4e25eb87848b81ca97426a2
    domain: cover
    entity_id: cover.esszimmer
    type: set_position
    position: 0
  - device_id: 9a60a49cf566edd42859ec1ce079829c
    domain: cover
    entity_id: cover.wohnzimmer
    type: set_position
    position: 0
  - device_id: ba19b3f7f239513e4d84045133738d80
    domain: cover
    entity_id: cover.buro
    type: set_position
    position: 0
  - device_id: c657988920e07c7891b84f204883607a
    domain: cover
    entity_id: cover.kuche
    type: set_position
    position: 0
  - device_id: 294678bdd220ab375534f9385c5a58c3
    domain: cover
    entity_id: cover.schlafzimmer
    type: set_position
    position: 0
  - device_id: d6cf684ac218f79548dc36cbfc761d0a
    domain: cover
    entity_id: cover.kinderzimmer
    type: set_position
    position: 0
  - choose:
      - conditions:
          - condition: device
            device_id: 9d4ca7a15ccfaca43006e9f449094770
            domain: device_tracker
            entity_id: fbce6fe67da003294766103153380e65
            type: is_home
        sequence:
          - type: turn_on
            device_id: fc19f3018666befb21bb29e34f739434
            entity_id: 9b6dee13c8a6cdeef7e9be35b1b031eb
            domain: light
      - conditions:
          - condition: device
            device_id: 27a90dfd9f98f3df6efd493ab873d50f
            domain: device_tracker
            entity_id: a2d77cdce2a69a14192baa3ddecc7000
            type: is_home
        sequence:
          - type: turn_on
            device_id: fc19f3018666befb21bb29e34f739434
            entity_id: 9b6dee13c8a6cdeef7e9be35b1b031eb
            domain: light
mode: single

The automation of the shutters works. Now all we really want is for the lights to turn on when my or my wife’s cell phone is home. We were not at home last week. When we arrived home, however, the light was on anyway.

Have I set something wrong?

Thanks in advance.