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

Add pressed and released event to allow usage as momentary button

Open indykoning opened this issue 4 years ago • 58 comments

I added two config values to allow a pressed_action and release_action to be added to allow this button to be used as a momentary button, calling a service eg: light.turn_on when it is pressed down and calling another service eg: light.turn_off to be called once this button is released.

indykoning avatar Jul 15 '20 19:07 indykoning

Great stuff, thanks, I'm going to have a look 😊

RomRider avatar Jul 15 '20 19:07 RomRider

Really looking forward having this feature :D thank you so much

Any plans to accept this PR or date to merge it back to master? :)

sla89 avatar Aug 23 '20 09:08 sla89

This should be ready to merge now, I now use the helpers for it, and added some fixes for later changes of the helpers repository

indykoning avatar Apr 05 '21 13:04 indykoning

Will this be merged?

maxi1134 avatar Jun 17 '21 01:06 maxi1134

Will this be merged?

+1

and313 avatar Jun 21 '21 13:06 and313

Me too!

expaso avatar Jul 26 '21 07:07 expaso

+1

liadg2 avatar Aug 06 '21 01:08 liadg2

Will this be merged?

williamkikai avatar Sep 13 '21 15:09 williamkikai

I don't get it, why is this ignored @RomRider ? It looks like there is a need for it by the community.

sla89 avatar Oct 17 '21 07:10 sla89

Because I don't have time to test it properly, yet

RomRider avatar Oct 17 '21 07:10 RomRider

Can the community support you somehow?

sla89 avatar Oct 17 '21 09:10 sla89

I am also looking forward to this as a door opener button, i will do some test when my other PR is accepted!

Do i get this correctly, the pressed_action is added because the hold_action would execute the action delayed?

CubieMedia avatar Nov 07 '21 23:11 CubieMedia

Do i get this correctly, the pressed_action is added because the hold_action would execute the action delayed?

Not specifically because of that but it can be used that way, hold action gets triggered after you remove your finger from the button. The pressed action triggers the moment your finger touches the button And the released button triggers the moment your finger leaves the button.

You could use it to move a camera right for as long as you are holding the button

indykoning avatar Nov 13 '21 09:11 indykoning

You could use it to move a camera right for as long as you are holding the button

That's exactly my goal! @indykoning Could you tell me how to install this code into my own installation?

maxi1134 avatar Nov 13 '21 23:11 maxi1134

Ok, i checked out your branch and build the js file. Copied it to my "config/www" folder. Then i added the file as resource in my Configuration -> Lovelace.

I can now add the card on my Dashboard with following configuration:

type: custom:button-card
entity: light.cubiemedia_gpio_output_10_10_20_42_18
name: Test
pressed_action:
  action: call-service
  service: homeassistant.turn_on
  service_data:
    entity_id: light.cubiemedia_gpio_output_10_10_20_42_18
release_action:
  action: call-service
  service: homeassistant.turn_off
  service_data:
    entity_id: light.cubiemedia_gpio_output_10_10_20_42_18

But the normal action (tap_action) is executed when i release the button, so it seems not to work. What am i doing wrong?

When executing the service via developer tools it is working. I also checked the .js file for "release" action and it is present (it is not in the file from master)

Any ideas what i am missing?

CubieMedia avatar Nov 23 '21 18:11 CubieMedia

This is untested, that's why it's not merged.

RomRider avatar Nov 24 '21 02:11 RomRider

This is a Pull Request and should work.

Also i don't think @indykoning did not test this. That is why i am assuming i am doing something wrong.

CubieMedia avatar Nov 24 '21 13:11 CubieMedia

Yeah i'm actually using it right now 😉 I've made a mistake in the comments here calling it "pressed_action" It shouldve been press_action as shown in the new readme https://github.com/custom-cards/button-card/pull/360/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R104 So your config would be:

type: custom:button-card
entity: light.cubiemedia_gpio_output_10_10_20_42_18
name: Test
press_action:
  action: call-service
  service: homeassistant.turn_on
  service_data:
    entity_id: light.cubiemedia_gpio_output_10_10_20_42_18
release_action:
  action: call-service
  service: homeassistant.turn_off
  service_data:
    entity_id: light.cubiemedia_gpio_output_10_10_20_42_18

And you are correct the tap or hold actions will still execute as well since those events are still happening as well of course

indykoning avatar Nov 24 '21 14:11 indykoning

Thanks for the tip, it works with "press_action"!

type: custom:button-card
entity: light.cubiemedia_gpio_output_10_10_20_42_18
name: Haustür
tap_action:
  action: null
press_action:
  action: call-service
  service: homeassistant.turn_on
  service_data:
    entity_id: light.cubiemedia_gpio_output_10_10_20_42_18
release_action:
  action: call-service
  service: homeassistant.turn_off
  service_data:
    entity_id: light.cubiemedia_gpio_output_10_10_20_42_18

Well done with your work! I would like to see this in the button-card for everyone.

CubieMedia avatar Nov 24 '21 18:11 CubieMedia

Looking forward to the release of this! Thank you for developing and merging.

ascarola avatar Dec 07 '21 13:12 ascarola

Since im using this solution now daily i have found a little flaw.

You have a custom-button card in lovelace (eg. door opener).

Use-Case: If you press the button the defined action is executed (eg. enable door opener) and if you release the button the defined action is also executed (eg. disable door opener). This is the sunny day scenario and it works very well.

Special Use-Case: You want to scroll down on your mobile phone on your lovelace dashboard. For doing this you press the screen (in this case the door opener button) and move your finger up for scrolling. The press action will be executed but the release action will be executed on the lovelace element that is under the finger after scrolling. So the door opener now is enabled and will only be disabled if you press and release again.

Can anyone confirm this?

Do we also need a move (drag) action? Should it be the same as release action?

Would be perfect if there is no need to define the drag action, only in the backround the drag action does the same as release.

CubieMedia avatar Dec 23 '21 18:12 CubieMedia

Since this MR is from 2020 I am afraid that this will never be merged back. An alternative maybe https://github.com/twrecked/hass-momentary

sla89 avatar Jan 11 '22 09:01 sla89

This is very good idea and I am looking forward to have it available in HA. However I am not sure how soon this can happen :( In a meantime (as I am not that experienced), can anyone give me simple directions how to make it in my instance ? Like @CubieMedia did ? If it is as simple as putting mentioned js file into "config/www" and creating lovelace resource from it - I trust I can manage. Only the js file is the challenge...

Maco65 avatar Jan 11 '22 13:01 Maco65

An alternative maybe https://github.com/twrecked/hass-momentary In my case this is not a viable option as I am looking for a switch/button which can be pressed and hold for some time and as long as it is hold the action should happen and as soon as it is released the action should stop. This PR is the best, simplest and easiest solution for me!

Maco65 avatar Jan 11 '22 13:01 Maco65

@Maco65 You need to setup an development environment (https://developers.home-assistant.io/docs/development_environment/) then check out this GIT repository (remember to use this branch not master) and go into the main folder (button-card in this case), execute the command ''npm run build'' to create the js file.

Good Luck!

CubieMedia avatar Jan 11 '22 17:01 CubieMedia

⚠⚠⚠⚠⚠⚠⚠⚠⚠ NOT TESTED VERSION ⚠⚠⚠⚠⚠⚠⚠⚠⚠

button-card.zip

PiotrMachowski avatar Jan 11 '22 19:01 PiotrMachowski

@CubieMedia or any other. It's originally installed with hacs. I have replaced the newly built js in the config/www folder but hacs seams to cache the old one. What to do? 🙂

EDIT: Got it working.. I also removed the gzip compressed file. Now it picks up my replacement file.

enorfelt avatar Jan 13 '22 20:01 enorfelt

@indykoning It does look like the press and release actions dont work on hassio android app? :/ Nothing happens.

enorfelt avatar Jan 14 '22 20:01 enorfelt

Yes the plain js file is needed for HA to load the file (no zip or tar)

I can confirm this UI change is working inside a browser and inside android app. This still seems to be a problem on your side. Maybe if you changed your UI lovelace needs to reload (message on the bottem).

CubieMedia avatar Jan 15 '22 15:01 CubieMedia

@CubieMedia thank you! Can confirm it works on android app now. Had to clear the app cache.

One issue though is that I have to hold my finger still on the button otherwise the release action is not triggered, only the press. So if I start press the button and slightly move my finger, still on the button, and release the release event is not triggered.

enorfelt avatar Jan 15 '22 20:01 enorfelt