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

Hold action - example?

Open FillHK opened this issue 4 years ago • 8 comments

Any example of hold_action? I have this code working:

              tap_action: 
                  action: call-service
                  service: script.executa_hisense_volume_up
                  service_data:
                    entity_id: script.executa_hisense_volume_up

How to add hold for Volume up?

FillHK avatar Mar 15 '21 11:03 FillHK

What do you mean by hold_action? You want it to repeat the action while you hold the button?

RomRider avatar Mar 20 '21 09:03 RomRider

Yes, exactly. I want to hold the Volume Up (etc) and increase volume.

FillHK avatar Mar 20 '21 16:03 FillHK

Then it's by using repeat:

hold_action: 
  action: call-service
  service: script.executa_hisense_volume_up
  repeat: 500 # will run the action every 500ms
  service_data:
    entity_id: script.executa_hisense_volume_up

RomRider avatar Mar 20 '21 16:03 RomRider

              # Volume up      
            - type: 'custom:button-card'
              entity: script.executa_hisense_volume_up
              icon: mdi:volume-plus
              name: Volume up
              show_name: false
              show_label: false
              font-size: 12px
              styles:
                card:
                  - width: 50px
                  - height: 70px
                  - background-color: '#333'
                  - margin-left: 10px
                  - margin-top: 10px
                  - border-top-right-radius: 40px
                  - border-top-left-radius: 40px
                name:
                  - font-size: 12px
                  - color: '#999'
                  - align-self: middle
                  - justify-self: center
                  - padding-bottom: 4px 
                icon: 
                  - color: '#999'
                  - width: 40%
              tap_action: 
                  action: call-service
                  service: script.executa_hisense_volume_up
                  service_data:
                    entity_id: script.executa_hisense_volume_up
              hold_action: 
                  action: call-service
                  service: script.executa_hisense_volume_up
                  repeat: 200 # will run the action every 500ms
                  service_data:
                    entity_id: script.executa_hisense_volume_up

This is my full code, but it doesn't work ;(

FillHK avatar Mar 20 '21 17:03 FillHK

Can you be a bit more explicit than "it doesn't work"?

RomRider avatar Mar 21 '21 14:03 RomRider

Yes, sorry.

I press Volume UP - and in just a few seconds seems volume increasing. Issues:

  • It works just for a few seconds of holding - then it stops increasing volume
  • Increasing is too slow, like 1 point per half-second

FillHK avatar Mar 21 '21 15:03 FillHK

Then you need to modify your script to make bigger increments in volume each time it's fired.

Also 200ms is a bit low between repetitions, I'd increase this to 500ms.

RomRider avatar Mar 21 '21 16:03 RomRider

I'm facing the same issue. The repeat does work but only runs a handful of times before it stops. My guess is some other javascript hold event is taking over and preventing subsequent increments from happening? If this is the case, if it could be reproduced on the developers side, is there a possibility to fix it by somehow not bubbling the hold event up to the browser or whatever might be 'taking over' and stopping the nth repeat from kicking in. For me it feels like maybe 2 or 3 repeats usually work but after that none fire.

mark007 avatar Apr 16 '24 21:04 mark007