Skip to content

About

Slide to Confirm is a custom card for Home Assistant that prevents accidental button presses by requiring the user perform a slide action to trigger a service.

Topics

Resources

Stars

34 stars

Watchers

2 watching

Forks

Repository files navigation

Slide to Confirm

A custom card for Home Assistant that prevents accidental actions. Instead of tapping a button, you drag a handle all the way across the card. Nothing happens until the handle reaches the far end.

Use case: a button that unlocks your front door is one mis-tap away from a door standing open while you are out. A slide across the full width of your phone is hard to do by accident.

v2 is a full rewrite: snake_case options, a visual editor, left-to-right or right-to-left sliding, a style: block for colors and sizes, entity awareness, keyboard access and a test suite. v1 configs keep working unchanged. See Migrating from v1.

Demo

Try it in your browser, no Home Assistant needed. The demo runs the real card against a simulated lock and garage door, and shows each action the card would send. It includes the themes, the one-slider garage door, dark mode, and right-to-left sliders.

To run it locally from a clone: npm install, then npm run demo.

Screenshot

Screenshot

Screencast

demo.mp4

Installation

Requires Home Assistant 2024.8 or newer.

HACS (recommended)

  1. In HACS, open Frontend, then the three-dot menu, then Custom repositories.
  2. Add https://github.com/itsbrianburton/slide-confirm as a Dashboard repository.
  3. Install Slide to Confirm and reload the page when prompted.

Manual

  1. Download slide-confirm.js from the latest release.
  2. Copy it to config/www/slide-confirm.js.
  3. Add a dashboard resource: Settings → Dashboards → ⋮ → Resources → Add resource, URL /local/slide-confirm.js, type JavaScript module.

Quick start

Edit a dashboard, click Add card, and pick Slide to Confirm. The visual editor covers every option. The same card in YAML:

type: custom:slide-confirm-card
sliders:
  - name: Front Door
    icon: mdi:door
    text_unconfirmed: Slide to Unlock
    text_confirmed: Door Unlocked!
    icon_unconfirmed: mdi:lock
    icon_confirmed: mdi:lock-open
    confirm_action:
      action: perform-action
      perform_action: lock.unlock
      target:
        entity_id: lock.front_door

Configuration

Card options

Option Type Default Description
type string custom:slide-confirm-card
header string Card title
direction ltr | rtl ltr Default slide direction for all sliders
theme theme Default theme for all sliders
style style object Style defaults for all sliders
sliders list Required. One or more sliders.

Slider options

Option Type Default Description
confirm_action action Required (unless every states entry has one). What happens after a successful slide.
name string entity friendly name Text above the slider
icon string entity icon Icon before the name, e.g. mdi:door
label string Secondary text next to the name
show_header boolean true false hides the icon, name and label row above the track
entity string Supplies the default name and icon and enables disabled_states and reset_delay: 0
text_unconfirmed string Slide to confirm Text on the track before confirming
text_confirmed string Confirmed Text on the track after confirming
icon_unconfirmed string mdi:chevron-right (mdi:chevron-left for rtl) Icon on the handle
icon_confirmed string mdi:check Icon on the handle after confirming
direction ltr | rtl card direction rtl puts the handle on the right and requires a right-to-left slide
reset_delay integer (ms) 1500 How long the confirmed state is shown. 0 holds it until the entity changes state (needs entity), 30 s at most.
haptic boolean false Vibrate the device on a successful slide (companion app, or browsers with Vibrate enabled in the user profile)
disabled_states string or list Grey out and disable the slider while entity is in one of these states
states map Per-state text, icons, direction, action and style, so one slider can work both ways. See states
theme theme card theme One of the built-in looks
style style object Style overrides for this slider

confirm_action

The same action object Home Assistant uses for tap_action everywhere else, so you can copy examples from the HA docs and edit it with HA's action picker:

confirm_action:
  action: perform-action
  perform_action: cover.set_cover_position
  target:
    entity_id: cover.garage
  data:
    position: 10

Supported actions: perform-action, toggle, more-info, navigate, url, assist, fire-dom-event, none. toggle and more-info act on the slider's entity. The card hands the action to Home Assistant to run, so HA's own target handling, error toasts and confirmation dialogs apply.

The v1 shape (action: call-service with service:) and the Developer Tools shape (action: lock.unlock with target:) are still accepted.

states

One slider that changes with its entity: a garage door slider that opens when the door is closed and closes when it is open. Each key is an entity state; its value can set direction, text_unconfirmed, text_confirmed, icon_unconfirmed, icon_confirmed, confirm_action and style. Anything an entry leaves out comes from the slider's own options; an entry's style is merged over the slider's. Needs entity.

type: custom:slide-confirm-card
sliders:
  - entity: cover.garage
    reset_delay: 0
    states:
      closed:
        text_unconfirmed: Slide to open
        text_confirmed: Opening…
        icon_unconfirmed: mdi:garage
        confirm_action:
          action: perform-action
          perform_action: cover.open_cover
          target: { entity_id: cover.garage }
      open:
        direction: rtl
        text_unconfirmed: Slide to close
        text_confirmed: Closing…
        icon_unconfirmed: mdi:garage-open
        style:
          track_color: var(--warning-color)
        confirm_action:
          action: perform-action
          perform_action: cover.close_cover
          target: { entity_id: cover.garage }

When the door is closed the handle rests on the left and you slide right to open. When it is open the handle rests on the right and you slide left to close. Every action still needs a full slide.

  • States the map does not list (opening, closing, unavailable, unknown) disable the slider, and the track shows the state as Home Assistant displays it. Add an entry for a state if you want the slider usable in it.
  • Use the explicit service for each state (cover.open_cover / cover.close_cover, not cover.toggle). If Home Assistant's state is ever out of date, the worst case is a command the door is already in, never the opposite one.
  • If the entity changes state mid-slide, the slide is dropped: the handle returns to rest and nothing runs, even if you finish the gesture.
  • With reset_delay: 0 the confirmed text stays up while the door moves and clears once it reaches a listed state, with the handle already on its new resting side. The usual 30 s cap still applies.
  • Covers without a position sensor often report only unknown or an assumed state. For those, add an unknown: entry with confirm_action set to cover.toggle, or keep two separate sliders.

Style object

Colors and sizes without card_mod. Every key maps to a CSS custom property you can also set from a theme. Bare numbers on size keys mean pixels.

Key CSS property Default
handle_size --slide-confirm-handle-size 50px
track_height --slide-confirm-track-height handle size
border_radius --slide-confirm-border-radius half the handle size
font_size --slide-confirm-font-size 1rem
track_color --slide-confirm-track-color --slider-track-color (shown at 38%)
handle_color --slide-confirm-handle-color --card-background-color
handle_border_color --slide-confirm-handle-border-color --divider-color
text_color --slide-confirm-text-color --primary-text-color
confirmed_color --slide-confirm-confirmed-color --primary-color
confirmed_text_color --slide-confirm-confirmed-text-color --text-primary-color
fill_opacity --slide-confirm-fill-opacity 0.54
type: custom:slide-confirm-card
style:
  handle_size: 40
  font_size: 0.9rem
sliders:
  - name: Shutdown PC
    confirm_action:
      {
        action: perform-action,
        perform_action: button.press,
        target: { entity_id: button.pc_shutdown },
      }
    style:
      confirmed_color: var(--error-color)

CSS parts (card_mod)

For anything the style object does not cover, the slider exposes CSS shadow parts: slider, header, icon, name, label, track, fill, text, handle.

type: custom:slide-confirm-card
card_mod:
  style:
    slide-confirm-slider$: |
      [part="handle"] { box-shadow: none; }
      [part="text"] { font-weight: 600; letter-spacing: 0.02em; }
sliders: ...

Themes

theme picks a built-in look, for the whole card or per slider: ios, minimal, glow, glass, tonal, sunrise, outline, soft, arrows, mono, hazard, aurora. Themes use your Home Assistant accent color (--primary-color, or confirmed_color from the style object) unless they have their own palette. Leave theme out for the classic look.

Themes at rest, while sliding and confirmed

Themes inset the handle in the track, so track_height is ignored. The color options of the style object still apply where a theme uses them. Themes contributed by @dbuezas (PR #20).

type: custom:slide-confirm-card
theme: glow
sliders:
  - name: Front door
    confirm_action:
      {
        action: perform-action,
        perform_action: lock.unlock,
        target: { entity_id: lock.front_door },
      }

Examples

Lock that shows its state

The slider takes its name and icon from the lock, is disabled while the door is already unlocked, and stays in the confirmed position until the lock reports the new state (useful for locks that take a few seconds).

type: custom:slide-confirm-card
sliders:
  - entity: lock.front_door
    text_unconfirmed: Slide to Unlock
    text_confirmed: Unlocking…
    icon_unconfirmed: mdi:lock
    icon_confirmed: mdi:lock-open
    disabled_states: [unlocked, unlocking, unavailable]
    reset_delay: 0
    haptic: true
    confirm_action:
      action: perform-action
      perform_action: lock.unlock
      target:
        entity_id: lock.front_door

Garage door with one slider

See states. If you prefer one slider per direction, use two sliders with opposite direction:

type: custom:slide-confirm-card
header: Garage
sliders:
  - name: Open
    direction: ltr
    confirm_action:
      {
        action: perform-action,
        perform_action: cover.open_cover,
        target: { entity_id: cover.garage },
      }
  - name: Close
    direction: rtl
    confirm_action:
      {
        action: perform-action,
        perform_action: cover.close_cover,
        target: { entity_id: cover.garage },
      }

Scripts, scenes and anything else

type: custom:slide-confirm-card
sliders:
  - name: Movie night
    icon: mdi:movie-open
    text_unconfirmed: Slide to start
    text_confirmed: Enjoy!
    confirm_action:
      action: perform-action
      perform_action: scene.turn_on
      target:
        scene: scene.movie_night
  - name: Restart Home Assistant
    icon: mdi:restart
    text_unconfirmed: Slide to restart
    text_confirmed: Restarting…
    confirm_action:
      action: perform-action
      perform_action: homeassistant.restart
    style:
      confirmed_color: var(--error-color)

Behaviour

  • Confirming requires releasing the handle at the far end (within 2 px). Releasing earlier springs it back without doing anything.
  • Keyboard: focus the handle and press the arrow keys. Each press moves 10%, so confirming takes ten presses. Home resets. There is no shortcut that jumps to the end.
  • Disabled sliders (via disabled_states, or a state states does not list) are greyed out and ignore input.
  • Config notes, such as deprecated v1 option names, are printed once to the browser console.
  • Sections dashboards: the card is full width by default and can be shrunk to half a section in the layout editor.

Migrating from v1

v1 configs work unchanged; the card maps them in memory and logs a note in the console. The visual editor shows an Upgrade button that rewrites the option names in place. Changes:

v1 v2
textUnconfirmed / textConfirmed text_unconfirmed / text_confirmed
iconUnconfirmed / iconConfirmed icon_unconfirmed / icon_confirmed
confirm_action.action: call-service action: perform-action
confirm_action.service: lock.unlock perform_action: lock.unlock
--switch-* theme variables, --text-color --slide-confirm-* properties with HA fallbacks
card_mod selectors .slide-confirm-track etc. CSS parts: [part="track"] etc.

Details, including behaviour differences, are in docs/migration-v1-to-v2.md.

Development

npm install
npm run demo      # standalone demo page with a fake Home Assistant
npm test          # unit tests (Node) and component tests (Chromium via Playwright)
npm run check     # lint, format, typecheck, test, build
npm run build     # dist/slide-confirm.js (not committed; releases attach it)

Releases are cut from a tag by GitHub Actions; see docs/releasing.md.

The component tests need a Chromium build: npx playwright install chromium once.

The design and work plan for v2 is in docs/v2-plan.md.

Contributing

Issues and pull requests are welcome. Please run npm run check before opening a PR.

License

MIT

About

Slide to Confirm is a custom card for Home Assistant that prevents accidental button presses by requiring the user perform a slide action to trigger a service.

Topics

Resources

Stars

34 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages