button-card
button-card copied to clipboard
Add pressed and released event to allow usage as momentary button
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.
Great stuff, thanks, I'm going to have a look 😊
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? :)
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
Will this be merged?
Will this be merged?
+1
Me too!
+1
Will this be merged?
I don't get it, why is this ignored @RomRider ? It looks like there is a need for it by the community.
Because I don't have time to test it properly, yet
Can the community support you somehow?
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?
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
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?
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?
This is untested, that's why it's not merged.
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.
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
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.
Looking forward to the release of this! Thank you for developing and merging.
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.
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
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...
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 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 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.
@indykoning It does look like the press and release actions dont work on hassio android app? :/ Nothing happens.
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 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.