Wall switch

Hi here,

I have created an automation for a 2 wall switch. The automation should disable the motion automation and turn light on for two different lamps.
This is worked, but when I switch off the left or right switch, both side goes to off and I dosen’t understand why.

alias: Flur_Kueche_Leuchten
description: MOES_Schalter neben Kühlschrank
trigger:
  - platform: state
    entity_id:
      - light.moes_flur_kueche_schalter_light
  - platform: state
    entity_id:
      - light.moes_flur_kueche_schalter_light_2
condition: []
action:
  - if:
      - condition: state
        entity_id: light.moes_flur_kueche_schalter_light
        state: "on"
    then:
      - type: turn_on
        device_id: dd82a5abe33af699233d663ea4f7ac6d
        entity_id: d5d208616926debf9cd5b48b1c2f544d
        domain: light
        brightness_pct: 95
      - type: turn_on
        device_id: ac78548ad76e9e2eaf384733ea4672ce
        entity_id: 29bd7c0253eaa0ee89c18d21bb4b2a50
        domain: switch
      - service: automation.turn_off
        target:
          entity_id: automation.licht_k_bew
        data:
          stop_actions: true
    alias: moes links an
  - if:
      - condition: state
        state: "off"
        entity_id: light.moes_flur_kueche_schalter_light
    then:
      - type: turn_off
        device_id: dd82a5abe33af699233d663ea4f7ac6d
        entity_id: d5d208616926debf9cd5b48b1c2f544d
        domain: light
      - type: turn_off
        device_id: ac78548ad76e9e2eaf384733ea4672ce
        entity_id: 29bd7c0253eaa0ee89c18d21bb4b2a50
        domain: switch
      - service: automation.turn_on
        target:
          entity_id:
            - automation.licht_k_bew
          device_id: []
          area_id: []
        data: {}
    alias: moes links aus
  - if:
      - condition: state
        entity_id: light.moes_flur_kueche_schalter_light_2
        state: "on"
        alias: moes rechts an
    then:
      - type: turn_on
        device_id: 3f4190815e5d4ae599cc97c245769422
        entity_id: 31c4da6d8d0f4024fdc02ab345caad7b
        domain: light
        brightness_pct: 95
      - service: automation.turn_off
        data:
          stop_actions: true
        target:
          entity_id: automation.sonoff_test
    alias: Moes rechts an
  - if:
      - condition: state
        state: "off"
        entity_id: light.moes_flur_kueche_schalter_light_2
    then:
      - type: turn_off
        device_id: 3f4190815e5d4ae599cc97c245769422
        entity_id: 31c4da6d8d0f4024fdc02ab345caad7b
        domain: light
      - service: automation.turn_on
        target:
          entity_id:
            - automation.sonoff_test
          device_id: []
          area_id: []
        data: {}
    alias: moes rechts aus
mode: single

The state switches to off, bit in my opinion it should be difference between light.moes_flur_kueche_schalter_light & light.moes_flur_kueche_schalter_light_2
which it does not.
Can you please help me to understand why?

TIA Micha

It kind of looks like the automation is repeating itself because your triggers are for either light changing and then the automation itself is changing the light. Now it’s a single method, so technically it should’t be possible but you are also using IF statements that would continue to evaluate after the previous IF statement made a change.

A few things you could try:

  • Break this into two different automations
  • Use trigger ID’s on the triggers and then include in your IF statements only if a particular trigger ID caused the automation to fire
  • Use CHOOSE instead of IF so you run only one set of actions per run of the automation

The low hanging fruit would be to duplicate the automation and just use one per trigger and if that works then refining the original with CHOOSE or trigger ID’s might be the answer (or just leaving it as two automations).

hey,

thanks you, for your hints.

Split it to two automations work, change it to the choose option has the same problem as the if possibility. Since I don’t understand why for both
:frowning:

alias: Choose
description: MOES_Schalter neben Kühlschrank
trigger:
  - platform: state
    entity_id:
      - light.moes_flur_kueche_schalter_light
  - platform: state
    entity_id:
      - light.moes_flur_kueche_schalter_light_2
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.moes_flur_kueche_schalter_light
            state: "on"
        sequence:
          - type: turn_on
            device_id: dd82a5abe33af699233d663ea4f7ac6d
            entity_id: d5d208616926debf9cd5b48b1c2f544d
            domain: light
            brightness_pct: 90
          - type: turn_on
            device_id: ac78548ad76e9e2eaf384733ea4672ce
            entity_id: 29bd7c0253eaa0ee89c18d21bb4b2a50
            domain: switch
          - service: automation.turn_off
            target:
              entity_id: automation.licht_k_bew
            data:
              stop_actions: true
  - choose:
      - conditions:
          - condition: state
            entity_id: light.moes_flur_kueche_schalter_light
            state: "off"
        sequence:
          - type: turn_off
            device_id: dd82a5abe33af699233d663ea4f7ac6d
            entity_id: d5d208616926debf9cd5b48b1c2f544d
            domain: light
          - type: turn_off
            device_id: ac78548ad76e9e2eaf384733ea4672ce
            entity_id: 29bd7c0253eaa0ee89c18d21bb4b2a50
            domain: switch
          - service: automation.turn_on
            target:
              entity_id:
                - automation.licht_k_bew
              device_id: []
              area_id: []
            data: {}
  - choose:
      - conditions:
          - condition: state
            entity_id: light.moes_flur_kueche_schalter_light_2
            state: "on"
        sequence:
          - type: turn_on
            device_id: 3f4190815e5d4ae599cc97c245769422
            entity_id: 31c4da6d8d0f4024fdc02ab345caad7b
            domain: light
            brightness_pct: 95
          - service: automation.turn_off
            data:
              stop_actions: true
            target:
              entity_id: automation.sonoff_test
    alias: Rechts an
  - alias: Rechts aud
    choose:
      - conditions:
          - condition: state
            entity_id: light.moes_flur_kueche_schalter_light_2
            state: "off"
        sequence:
          - type: turn_off
            device_id: 3f4190815e5d4ae599cc97c245769422
            entity_id: 31c4da6d8d0f4024fdc02ab345caad7b
            domain: light
          - service: automation.turn_on
            target:
              entity_id:
                - automation.sonoff_test
              device_id: []
              area_id: []
            data: {}
mode: single

I have also the sequence:

{
  "trace": {
    "last_step": "action/3/choose/0/sequence/1",
    "run_id": "2b98a71c1b23ba8283b04dc46283ff4e",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-12-31T14:14:31.535283+00:00",
      "finish": "2023-12-31T14:14:31.817635+00:00"
    },
    "domain": "automation",
    "item_id": "1704028837390",
    "trigger": "state of light.moes_flur_kueche_schalter_light",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2023-12-31T14:14:31.535395+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.choose",
              "state": "on",
              "attributes": {
                "id": "1704028837390",
                "last_triggered": "2023-12-31T14:14:23.719279+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "Choose"
              },
              "last_changed": "2023-12-31T13:27:46.014826+00:00",
              "last_updated": "2023-12-31T14:14:23.945274+00:00",
              "context": {
                "id": "01HK03KM76PR0F9E9RF7SB7HCA",
                "parent_id": "01HK03KM6TQJM0RCN06WMWS65W",
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "state",
              "entity_id": "light.moes_flur_kueche_schalter_light",
              "from_state": {
                "entity_id": "light.moes_flur_kueche_schalter_light",
                "state": "on",
                "attributes": {
                  "supported_color_modes": [
                    "onoff"
                  ],
                  "color_mode": "onoff",
                  "off_with_transition": false,
                  "off_brightness": null,
                  "friendly_name": "moes_schalter_links",
                  "supported_features": 8
                },
                "last_changed": "2023-12-31T14:14:23.706478+00:00",
                "last_updated": "2023-12-31T14:14:23.706478+00:00",
                "context": {
                  "id": "01HK03KM6TQJM0RCN06WMWS65W",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "to_state": {
                "entity_id": "light.moes_flur_kueche_schalter_light",
                "state": "off",
                "attributes": {
                  "supported_color_modes": [
                    "onoff"
                  ],
                  "color_mode": null,
                  "off_with_transition": false,
                  "off_brightness": null,
                  "friendly_name": "moes_schalter_links",
                  "supported_features": 8
                },
                "last_changed": "2023-12-31T14:14:31.523551+00:00",
                "last_updated": "2023-12-31T14:14:31.523551+00:00",
                "context": {
                  "id": "01HK03KVV39TX0TE15Y3F135G3",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "for": null,
              "attribute": null,
              "description": "state of light.moes_flur_kueche_schalter_light"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-12-31T14:14:31.538802+00:00",
          "changed_variables": {
            "context": {
              "id": "01HK03KVVF1PBR8HQFAGP31N11",
              "parent_id": "01HK03KVV39TX0TE15Y3F135G3",
              "user_id": null
            }
          }
        }
      ],
      "action/0/choose/0": [
        {
          "path": "action/0/choose/0",
          "timestamp": "2023-12-31T14:14:31.538978+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0": [
        {
          "path": "action/0/choose/0/conditions/0",
          "timestamp": "2023-12-31T14:14:31.539057+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/0/choose/0/conditions/0/entity_id/0": [
        {
          "path": "action/0/choose/0/conditions/0/entity_id/0",
          "timestamp": "2023-12-31T14:14:31.539133+00:00",
          "result": {
            "result": false,
            "state": "off",
            "wanted_state": "on"
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2023-12-31T14:14:31.539359+00:00",
          "result": {
            "choice": 0
          }
        }
      ],
      "action/1/choose/0": [
        {
          "path": "action/1/choose/0",
          "timestamp": "2023-12-31T14:14:31.539488+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/1/choose/0/conditions/0": [
        {
          "path": "action/1/choose/0/conditions/0",
          "timestamp": "2023-12-31T14:14:31.539552+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/1/choose/0/conditions/0/entity_id/0": [
        {
          "path": "action/1/choose/0/conditions/0/entity_id/0",
          "timestamp": "2023-12-31T14:14:31.539619+00:00",
          "result": {
            "result": true,
            "state": "off",
            "wanted_state": "off"
          }
        }
      ],
      "action/1/choose/0/sequence/0": [
        {
          "path": "action/1/choose/0/sequence/0",
          "timestamp": "2023-12-31T14:14:31.540647+00:00"
        }
      ],
      "action/1/choose/0/sequence/1": [
        {
          "path": "action/1/choose/0/sequence/1",
          "timestamp": "2023-12-31T14:14:31.694889+00:00"
        }
      ],
      "action/1/choose/0/sequence/2": [
        {
          "path": "action/1/choose/0/sequence/2",
          "timestamp": "2023-12-31T14:14:31.706666+00:00",
          "result": {
            "params": {
              "domain": "automation",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "automation.licht_k_bew"
                ],
                "device_id": [],
                "area_id": []
              }
            },
            "running_script": false
          }
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2023-12-31T14:14:31.714956+00:00"
        }
      ],
      "action/2/choose/0": [
        {
          "path": "action/2/choose/0",
          "timestamp": "2023-12-31T14:14:31.715124+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/2/choose/0/conditions/0": [
        {
          "path": "action/2/choose/0/conditions/0",
          "timestamp": "2023-12-31T14:14:31.715187+00:00",
          "result": {
            "result": false
          }
        }
      ],
      "action/2/choose/0/conditions/0/entity_id/0": [
        {
          "path": "action/2/choose/0/conditions/0/entity_id/0",
          "timestamp": "2023-12-31T14:14:31.715248+00:00",
          "result": {
            "result": false,
            "state": "off",
            "wanted_state": "on"
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2023-12-31T14:14:31.715438+00:00",
          "result": {
            "choice": 0
          }
        }
      ],
      "action/3/choose/0": [
        {
          "path": "action/3/choose/0",
          "timestamp": "2023-12-31T14:14:31.715556+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/3/choose/0/conditions/0": [
        {
          "path": "action/3/choose/0/conditions/0",
          "timestamp": "2023-12-31T14:14:31.715621+00:00",
          "result": {
            "result": true
          }
        }
      ],
      "action/3/choose/0/conditions/0/entity_id/0": [
        {
          "path": "action/3/choose/0/conditions/0/entity_id/0",
          "timestamp": "2023-12-31T14:14:31.715680+00:00",
          "result": {
            "result": true,
            "state": "off",
            "wanted_state": "off"
          }
        }
      ],
      "action/3/choose/0/sequence/0": [
        {
          "path": "action/3/choose/0/sequence/0",
          "timestamp": "2023-12-31T14:14:31.716557+00:00"
        }
      ],
      "action/3/choose/0/sequence/1": [
        {
          "path": "action/3/choose/0/sequence/1",
          "timestamp": "2023-12-31T14:14:31.799794+00:00",
          "result": {
            "params": {
              "domain": "automation",
              "service": "turn_on",
              "service_data": {},
              "target": {
                "entity_id": [
                  "automation.sonoff_test"
                ],
                "device_id": [],
                "area_id": []
              }
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1704028837390",
      "alias": "Choose",
      "description": "MOES_Schalter neben Kühlschrank",
      "trigger": [
        {
          "platform": "state",
          "entity_id": [
            "light.moes_flur_kueche_schalter_light"
          ]
        },
        {
          "platform": "state",
          "entity_id": [
            "light.moes_flur_kueche_schalter_light_2"
          ]
        }
      ],
      "condition": [],
      "action": [
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "light.moes_flur_kueche_schalter_light",
                  "state": "on"
                }
              ],
              "sequence": [
                {
                  "type": "turn_on",
                  "device_id": "dd82a5abe33af699233d663ea4f7ac6d",
                  "entity_id": "d5d208616926debf9cd5b48b1c2f544d",
                  "domain": "light",
                  "brightness_pct": 90
                },
                {
                  "type": "turn_on",
                  "device_id": "ac78548ad76e9e2eaf384733ea4672ce",
                  "entity_id": "29bd7c0253eaa0ee89c18d21bb4b2a50",
                  "domain": "switch"
                },
                {
                  "service": "automation.turn_off",
                  "target": {
                    "entity_id": "automation.licht_k_bew"
                  },
                  "data": {
                    "stop_actions": true
                  }
                }
              ]
            }
          ]
        },
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "light.moes_flur_kueche_schalter_light",
                  "state": "off"
                }
              ],
              "sequence": [
                {
                  "type": "turn_off",
                  "device_id": "dd82a5abe33af699233d663ea4f7ac6d",
                  "entity_id": "d5d208616926debf9cd5b48b1c2f544d",
                  "domain": "light"
                },
                {
                  "type": "turn_off",
                  "device_id": "ac78548ad76e9e2eaf384733ea4672ce",
                  "entity_id": "29bd7c0253eaa0ee89c18d21bb4b2a50",
                  "domain": "switch"
                },
                {
                  "service": "automation.turn_on",
                  "target": {
                    "entity_id": [
                      "automation.licht_k_bew"
                    ],
                    "device_id": [],
                    "area_id": []
                  },
                  "data": {}
                }
              ]
            }
          ]
        },
        {
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "light.moes_flur_kueche_schalter_light_2",
                  "state": "on"
                }
              ],
              "sequence": [
                {
                  "type": "turn_on",
                  "device_id": "3f4190815e5d4ae599cc97c245769422",
                  "entity_id": "31c4da6d8d0f4024fdc02ab345caad7b",
                  "domain": "light",
                  "brightness_pct": 95
                },
                {
                  "service": "automation.turn_off",
                  "data": {
                    "stop_actions": true
                  },
                  "target": {
                    "entity_id": "automation.sonoff_test"
                  }
                }
              ]
            }
          ],
          "alias": "Rechts an"
        },
        {
          "alias": "Rechts aud",
          "choose": [
            {
              "conditions": [
                {
                  "condition": "state",
                  "entity_id": "light.moes_flur_kueche_schalter_light_2",
                  "state": "off"
                }
              ],
              "sequence": [
                {
                  "type": "turn_off",
                  "device_id": "3f4190815e5d4ae599cc97c245769422",
                  "entity_id": "31c4da6d8d0f4024fdc02ab345caad7b",
                  "domain": "light"
                },
                {
                  "service": "automation.turn_on",
                  "target": {
                    "entity_id": [
                      "automation.sonoff_test"
                    ],
                    "device_id": [],
                    "area_id": []
                  },
                  "data": {}
                }
              ]
            }
          ]
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01HK03KVVF1PBR8HQFAGP31N11",
      "parent_id": "01HK03KVV39TX0TE15Y3F135G3",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Choose",
      "message": "triggered by state of light.moes_flur_kueche_schalter_light",
      "source": "state of light.moes_flur_kueche_schalter_light",
      "entity_id": "automation.choose",
      "context_id": "01HK03KVVF1PBR8HQFAGP31N11",
      "when": 1704032071.535578,
      "domain": "automation"
    },
    {
      "when": 1704032071.685913,
      "state": "off",
      "entity_id": "light.leuchte_kueche_level_light_color_on_off",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Choose",
      "context_message": "triggered by state of light.moes_flur_kueche_schalter_light",
      "context_source": "state of light.moes_flur_kueche_schalter_light",
      "context_entity_id": "automation.choose"
    },
    {
      "when": 1704032071.709239,
      "state": "on",
      "entity_id": "automation.licht_k_bew",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Choose",
      "context_message": "triggered by state of light.moes_flur_kueche_schalter_light",
      "context_source": "state of light.moes_flur_kueche_schalter_light",
      "context_entity_id": "automation.choose"
    },
    {
      "when": 1704032071.795011,
      "state": "off",
      "entity_id": "light.leuchte_esstisch_light",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Choose",
      "context_message": "triggered by state of light.moes_flur_kueche_schalter_light",
      "context_source": "state of light.moes_flur_kueche_schalter_light",
      "context_entity_id": "automation.choose"
    },
    {
      "when": 1704032071.795981,
      "state": "off",
      "entity_id": "light.kuechenlichter",
      "icon": "mdi:lightbulb-group",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Choose",
      "context_message": "triggered by state of light.moes_flur_kueche_schalter_light",
      "context_source": "state of light.moes_flur_kueche_schalter_light",
      "context_entity_id": "automation.choose"
    },
    {
      "when": 1704032071.810713,
      "state": "off",
      "entity_id": "switch.nous_kueche",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Choose",
      "context_message": "triggered by state of light.moes_flur_kueche_schalter_light",
      "context_source": "state of light.moes_flur_kueche_schalter_light",
      "context_entity_id": "automation.choose"
    }
  ]
}

maybe the problem is that the switch entities are quite equal with
light.moes_flur_kueche_schalter_light & light.moes_flur_kueche_schalter_light_2

I will test it with the trigger id, when I have understand how it worked.

Thanks.

Edit trigger ids is working in the original automation fine