Automation with trigger of multiple devices

Hi,

I have 3 switches in my living room and I would like to switch the same lamp from all of them. Actually I use 3 time the same code for each switch. Is there a way how to shorten the code a little bit?

alias: UI Busch-Jäger-Esstisch
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: db465fd4a340ef65dcb6f45a087eb83f
    type: action
    subtype: on_row_2
    discovery_id: 0xd85def11a1006ac6 action_on_row_2
    id: ein
  - platform: device
    domain: mqtt
    device_id: db465fd4a340ef65dcb6f45a087eb83f
    type: action
    subtype: off_row_2
    discovery_id: 0xd85def11a1006ac6 action_off_row_2
    id: aus
  - platform: device
    domain: mqtt
    device_id: 84b973e0373ab257e7faa98551f917ef
    type: action
    subtype: on_row_2
    discovery_id: 0xd85def11a1006ac9 action_on_row_2
    id: ein
  - platform: device
    domain: mqtt
    device_id: 84b973e0373ab257e7faa98551f917ef
    type: action
    subtype: off_row_2
    discovery_id: 0xd85def11a1006ac9 action_off_row_2
    id: aus
  - platform: device
    domain: mqtt
    device_id: 2757aa39e94d6d9f9602ad8c1606a129
    type: action
    subtype: on_row_2
    discovery_id: 0xd85def11a10065f2 action_on_row_2
    id: ein
  - platform: device
    domain: mqtt
    device_id: 2757aa39e94d6d9f9602ad8c1606a129
    type: action
    subtype: off_row_2
    discovery_id: 0xd85def11a10065f2 action_off_row_2
    id: aus

The device IDs are:

  • device_id: db465fd4a340ef65dcb6f45a087eb83f
  • device_id: 84b973e0373ab257e7faa98551f917ef
  • device_id: 2757aa39e94d6d9f9602ad8c1606a129

Thanks for support,
Spartacus

Hi,
thanks for that! I changed it. But I did not really get why the deice trigger is not the best way!

You asked how to make the code shorted/more compact… Device triggers are much more verbose compared to more elemental triggers.

Example: Trigger when either of 2 lights is ‘on’ for 5 minutes… Device trigger vs. State trigger

trigger:
  - platform: device
    type: turned_on
    device_id: 7ea34bb24553029d2be6383cd84368ae
    entity_id: f4a2d766621984ed103eed55b5ed55f8
    domain: light
    for: "00:05:00"
  - platform: device
    type: turned_on
    device_id: 7b7229ced1441dd3bf189f422de0b003
    entity_id: 5fe15650ed5b10dcebd512bd576d1196
    domain: light
    for: "00:05:00"
trigger:
  - platform: state
    entity_id:
      - light.ecosmart_zb_br30_01
      - light.ecosmart_zb_br30_02
    to: "on"
    for: "00:05:00"

For this basic setup, even using the shorthand method for the duration, for each additional light the device triggers will add 5x the number of lines compared to the state trigger.

Some trigger types like Template, Numeric State, and MQTT also allow the use of templates which can make a single trigger handle cases that would require multiple device triggers.

Hi,

ok, this is exactley what I notices, when changing the trigger to state.Thaks for clarification!
Spartacus