Skip to content

Instantly share code, notes, and snippets.

@Mechazawa
Last active August 20, 2025 18:33
Show Gist options
  • Select an option

  • Save Mechazawa/fe1664583f401619fa18d9397fe2c3b6 to your computer and use it in GitHub Desktop.

Select an option

Save Mechazawa/fe1664583f401619fa18d9397fe2c3b6 to your computer and use it in GitHub Desktop.
blueprint:
name: Toggle Device Based on Button Action
description: >
A blueprint that links a button with two different actions (on/off) to a paired device.
When the specified "on" action is triggered, the target device will turn on.
When the specified "off" action is triggered, the target device will turn off.
domain: automation
input:
trigger_device:
name: Button Device
description: The device that triggers the on/off actions.
selector:
device:
on_subtype:
name: On Action Subtype
description: The action subtype for the "on" press (e.g., "on", "single", etc.)
selector:
text:
off_subtype:
name: Off Action Subtype
description: The action subtype for the "off" press (e.g., "off", "double", etc.)
selector:
text:
target_device:
name: Target Device
description: The device to be turned on or off.
selector:
target:
mode: single
trigger:
- platform: device
device_id: !input trigger_device
domain: mqtt
type: action
subtype: !input on_subtype
id: on_action
- platform: device
device_id: !input trigger_device
domain: mqtt
type: action
subtype: !input off_subtype
id: off_action
action:
- choose:
- conditions:
- condition: trigger
id: on_action
sequence:
- service: homeassistant.turn_on
target: !input target_device
- conditions:
- condition: trigger
id: off_action
sequence:
- service: homeassistant.turn_off
target: !input target_device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment