Turn on/off device when a different device turns on/off

Is there a simple way to turn off Device B when Device A turns on, and then turn device B back on when device A turns off? Right now I create 2 separate automations, but there has to be a better way. These are not lights, but that’s basically what i’m looking for a blueprint like the motion lights but for another device.

There are blueprints available for this application. Here’s one example:

There’s a sync group helper available as a custom integration. Never tried it, though.

You need two triggers, one for Device A turning on and one for Device A turning off. Give each trigger an ID. Then use a Choose in the action. Add two options, triggered by ID. The first would turn off Device B and the second would turn Device B on.

I’m not at home so can’t paste YAML or screenshots. It’s a fairly straightforward automation to set up once you understand the trigger IDs and the Choose function so I wouldn’t think you’d need a Blueprint which may introduce lots of options that you don’t need.

I got this automation, that does exactly that:

alias: Flurlampe abends zusammen mit der Esstischlampe schalten
description: ""
triggers:
  - entity_id:
      - switch.licht_esszimmer_deckenlampe_output_switch_0
    to: "on"
    trigger: state
    id: an
  - entity_id:
      - switch.licht_esszimmer_deckenlampe_output_switch_0
    to: "off"
    trigger: state
actions:
  - if:
      - condition: trigger
        id:
          - an
    then:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: light.flurlampe
    else:
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.flurlampe
mode: single

Yours is a little different to what I described. Here is an example using Choose:

alias: Bin Light
description: Turns on/off Garden Light 1 when garage back door is opened/closed.
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.garage_back_door_sensor
    to: "on"
    id: garage_bdoor_open
  - trigger: state
    entity_id:
      - binary_sensor.garage_back_door_sensor
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 0
    id: garage_bdoor_closed
conditions:
  - condition: sun
    before: sunrise
    after: sunset
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - garage_bdoor_open
        sequence:
          - action: light.turn_on
            metadata: {}
            data:
              transition: 5
              brightness_pct: 100
              color_temp_kelvin: 5500
            target:
              entity_id: light.garden_light_1
      - conditions:
          - condition: trigger
            id:
              - garage_bdoor_closed
        sequence:
          - action: light.turn_off
            metadata: {}
            data:
              transition: 5
            target:
              entity_id: light.garden_light_1
mode: single

Thank you these will be super helpful!

It’s as simple as this:

alias: example
triggers:
  - trigger: state
    entity_id: switch.device_a
    from:
      - 'on'
      - 'off'
    to:
      - 'off'
      - 'on'
conditions: []
actions:
  - action: switch.turn_{{ trigger.from_state.state }}
    target:
      entity_id: switch.device_b

You can paste both of the above YAML examples straight into a blank automation and then switch back to the visual editor to see how they are built and then you don’t need to worry about YAML.

Since 2025.5 you can paste into visual editor as well.

1 Like

Maybe so, but your solution requires knowledge of YAML which not everybody has.

ejkeebler simply has to copy-paste it into the Automation Editor.

Like arganto said, as of 2025.5.0 you don’t even need to switch the Automation Editor into YAML mode. You can copy-paste the YAML code while the Automation Editor is in Visual mode. Easy peasy.

FWIW, it even works for partial code, like copy-pasting just a condition into an existing automation. It’s never been easier to transfer an automation from the forum into one’s own system.

Yes, I understand that. My point, perhaps not made clearly, was that your code can only be edited in YAML mode. Whilst it can be viewed in the Visual Editor, it cannot be edited which could be an issue for non-YAML users.

Are they not here to learn?


Home Assistant’s scripting abilities are far richer than what the Automation Editor reveals in its Visual mode.