Long_press / double_tap actions for all Buttons
dipseth opened this issue · comments
Is your feature request related to a problem? Please describe.
Will help reduce number of buttons required for full functionality. For example I would like a single tap on the power button to toggle art mode on Samsung Frame TV, and long_press to toggle power.
Describe the solution you'd like
This can possible exist only for custom and/or source keys:
For example
custom_keys:
power:
long_click_action:
action: service
service: media_player.toggle
target:
entity_id: media_player.frame # different entity for power
double_click_action:
action: service
service: light.toggle
data:
color_name: red
target:
area_id: living_room
service: media_player.toggle
target:
entity_id: media_player.samsung_int_frame_3 # entity for art mode
Additionally this could have actions supported by native HA dashboards.
Describe alternatives you've considered
This could help reduce number of buttons required for desired functionality and support a minimalist design. The alternative is to simply create more buttons.
Additional context
Add any other context or screenshots about the feature request here.
Taking notes as I work on a huge refactor and implementation to support Home Assistant actions.
Work so far:
- Refactored
IAction/s
interfaces to match HA actions updateDeprecatedFields
new functionality:- Copies key, source, and service call fields to
tap_action
. - Sets
action
of actions based on presence ofkey
,source
,service
, etc. fields if it is not set.
- Copies key, source, and service call fields to
- Added confirmation support copied from other project. While it does give different messages for each action type, most of the actions aren't implemented yet.
- Added
hold_action
anddouble_tap_action
fields.
TODO:
- Figure out why slider broke.
- Double tap button support.
- Rework how touchpad commands are defined so they use the new
hold_action
anddouble_tap_action
fields instead.- And add logic to
updateDeprecatedFields
.
- And add logic to
- Make default tap/hold/double actions persistent if not overwritten by custom actions.
- Get rid of separate custom keys and sources fields for one custom actions field.
- Implement
navigate
/url
- Implement
assist
- There is no easy way to do so in a custom card since the Home Assistant front end code fire event call includes a reference to the
ha-voice-command-dialog
itself.
- There is no easy way to do so in a custom card since the Home Assistant front end code fire event call includes a reference to the
- Update README
Thanks for the when on this!👍👍
Here is the beta for action support, if @dipseth and @Montreal666 could test it out. I'll officially release it either tomorrow or early next week.
https://github.com/Nerwyn/android-tv-card/releases/tag/3.2.0-beta.005
Not totally sure about the syntax, can you confirm for the tap-action/url part ?
This will also accept templates, right?
Thx
- type: custom:android-tv-card
view_layout:
grid-area: A2
remote_id: remote.rss
rows:
- - touchpad
touchpad_style:
height: 10rem
background: transparent
opacity: 20%
custom_keys:
up:
service: script.rss_headlines_increment
down:
service: script.rss_headlines_decrement
left:
service: script.rss_headlines_increment
right:
service: script.rss_headlines_decrement
center:
tap-action:
action: url
url_path: https://www.home-assistant.io
card_mod:
style: |
ha-card {
height: 8em !important;
opacity: 0%;
}
Not totally sure about the syntax, can you confirm for the tap-action/url part ? This will also accept templates, right? Thx
Yup, that should work. Templating is also supported, albeit with a limited set of functions as described in the ha-nunjucks documentation. And while putting service
at the root of a custom action and calling it custom_keys
are deprecated, they should still work.
type: custom:android-tv-card
view_layout:
grid-area: A2
remote_id: remote.rss
rows:
- - touchpad
touchpad_style:
height: 10rem
background: transparent
opacity: 20%
custom_actions:
up:
tap_action:
action: call-service
service: script.rss_headlines_increment
down:
tap_action:
action: call-service
service: script.rss_headlines_decrement
left:
tap_action:
action: call-service
service: script.rss_headlines_increment
right:
tap_action:
action: call-service
service: script.rss_headlines_decrement
center:
tap-action:
action: url
url_path: |
{% if is_state("remote.rss", "on") %}
https://www.home-assistant.io
{% else if is_state("input_select.thing", "other thing") %}
https://community.home-assistant.io
{% else %}
https://www.google.com
{% endif %}
card_mod:
style: |
ha-card {
height: 8em !important;
opacity: 1000%;
}
Thanks it does work with a direct URL like above but when using a template to get the url, an extra https:// is added as a prefix ...
url_path: |
{% set rss = states('counter.news_rss_counter') | int %}
{{ state_attr('sensor.radio_canada_rss','entries')[rss].link }}
Outputs:
https://http//ici.radio-canada.ca/sports/2034812/soccer-mls-crew-columbus
Maybe unrelated to your card.
I'll do more tests tomorrow, worst case I'll use a "replace" but wondering what causes this behavior.
Thanks it does work with a direct URL like above but when using a template to get the url, an extra https:// is added as a prefix ...
That's weird. My toUrl
function does prepend https://
to the URL if it doesn't contain //
, but that shouldn't have triggered here.
toUrl(action: IAction) {
let url = (renderTemplate(this.hass, action.url_path!) as string) ?? '';
if (!action.url_path!.includes('//')) {
url = `https://${url}`;
}
window.location.assign(url);
}
I'll have to test it some more when I get the time.
Edit: I just realized that I'm checking for //
in the original string instead of it after rendering its template. I'll fix it in the morning. Good find!
Great, glad you could pinpoint the issue.
Will test again once the fix is released.
Cheers,
@Montreal666 Should be fixed in beta 3
Bingo. Thank you ! 👍
Not sure if what being discussed here would apply but when you "long press" a button I think multiple single taps (judging by the multiple vibrations it triggers) are sent which makes things like rewinding a video a bit of a hassle.
From what I understand you're providing a way to customize a button's long press event but not addressing this issue, correct?
I could open a different issue If that's the case
when you "long press" a button I think multiple single taps (judging by the multiple vibrations it triggers) are sent which makes things like rewinding a video a bit of a hassle.
If you're talking about the multiple vibrations when holding up, down, left, right, volume up, volume down, or delete, that's intended behavior. Because those buttons get repeated when held their hold actions can't be remapped.
Tested most everything seems to work pretty seamlessly with existing config structure
Only issue I had was not being able to use the hold action from my computer web dashbaord.
custom_keys:
sunroom_light:
icon: >-
{{ iif(is_state("light.office_light_1", "on"), "mdi:ceiling-light",
"mdi:ceiling-light-outline") }}
service: light.toggle
data:
entity_id: light.office_light_1
double_tap_action:
action: call-service
service: scene.turn_on
service_data: # works with data or service_data keys
entity_id: scene.office_color
target: {}
hold_action: # did not work from computer (MacOS)
action: call-service
service: scene.turn_on
data: # works with data or service_data keys
entity_id: scene.office_white
target: {}
volume_mute:
double_tap_action:
action: url
url_path: >-
https://pictogrammers.com/library/mdi/?welcome
service: media_player.volume_mute
data:
is_volume_muted: false
icon: mdi:volume-off
target:
entity_id: media_player.frame
hdmi:
double_tap_action:
action: navigate
navigation_replace: true
navigation_path: /home-control/kitchen
service: media_player.select_source
Because hold actions use touch events, they don't work on desktop browsers. I think I may be able to add mouse support for hold actions via mouse up/down events and can try to do so next week.
@dipseth I think I've got button hold actions working on desktop browsers in the latest beta. And I got double tap actions working on iPhone! I'm going to adapt these changes for touchpad in the next beta. Can you give it a test and make sure it works on your devices?
And now the touchpad supports double tap and hold events on Brave and Firefox desktop, and the Home Assistant app for Android, and iPhone! I'll let y'all test the latest beta (5 at time of writing) and work on README updates, and then release it either later today or tomorrow.
Edit: Wait no touchpad is broken, fires center event on swipe.
Edit 2: Should be fixed for good in beta 6.
Released v3.2.0
https://github.com/Nerwyn/android-tv-card/releases/tag/3.2.0