Skip to main content

Button

synapse.button creates a simple entity that can be pressed to trigger actions.

Home Assistant Counterpart

✏️ Usage

minimum properties

synapse.button({
context,
name: "My button entity"
});

Entity specific attributes

⚙️ Configuration

device_class

Enum ValueDescription
identifyButton to identify the device
restartButton to restart the device
updateButton to update the device

🌐 Events

press / onPress

Buttons emit a press event when activated. This can be handled in two ways:

Inline handler:

const entity = synapse.button({
context,
name: "My button",
press() {
logger.info("Button was pressed!");
// Handle the press action
}
});

Chained handler:

const entity = synapse.button({
context,
name: "My button"
});

entity.onPress(() => {
logger.info("Button was pressed!");
// Handle the press action
});

📝 Examples

Simple button with action:

const restartButton = synapse.button({
context,
name: "Restart System",
device_class: "restart",
press() {
logger.info("Restarting system...");
// Perform restart logic
}
});

Button with custom attributes:

const identifyButton = synapse.button({
context,
name: "Identify Device",
device_class: "identify",
attributes: {
manufacturer: "My Company",
model: "Button-001"
},
press() {
logger.info("Device identification triggered");
// Flash LED or other identification action
}
});