button-card icon indicating copy to clipboard operation
button-card copied to clipboard

Copying tap_action into long_tap_action

Open sciurius opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. My wife is handicapped and does not have very fine control over her muscles. It is difficult for her to push a UI button, not too long, not too short.

Describe the solution you'd like A simple way to instruct button-card to handle long_tap_action the same as a common tap_action.

Describe alternatives you've considered Copy (cut/paste) the tap_action YAML into the long_tap_action for each and every button... Doable but tedious and prone to errors.

sciurius avatar Jul 22 '22 17:07 sciurius

You could do something like

type: custom:button-card
entity: counter.door_counter
show_state: true
variables:
  tap_action:
    action: call-service
    service: counter.increment
    service_data:
      entity_id: counter.door_counter
tap_action:
  action: '[[[ return variables.tap_action.action; ]]]'
  service: '[[[ return variables.tap_action.service; ]]]'
  service_data: '[[[ return variables.tap_action.service_data; ]]]'
hold_action:
  action: '[[[ return variables.tap_action.action; ]]]'
  service: '[[[ return variables.tap_action.service; ]]]'
  service_data: '[[[ return variables.tap_action.service_data; ]]]'

Then you only need to make your settings once, as a variable.

But I discovered that it is not necessary to define hold_action if you want hold_action to do the same as tap_action. It is default behaviour that the tap_action is also used as hold_action if no hold_action was defined.

sadly it's not possible to template tap_action itself but only the action's properties...

Wombosvideo avatar Sep 15 '22 11:09 Wombosvideo

It is default behaviour that the tap_action is also used as hold_action if no hold_action was defined.

This is not how I interpret the docs,

hold_action ... Define the type of action on hold, if undefined, nothing happens.

sciurius avatar Sep 17 '22 18:09 sciurius