Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

programmable button_press & button_release #58

Closed
armedad opened this issue Feb 5, 2024 · 15 comments
Closed

programmable button_press & button_release #58

armedad opened this issue Feb 5, 2024 · 15 comments
Assignees
Labels
enhancement New feature or request

Comments

@armedad
Copy link

armedad commented Feb 5, 2024

i'm trying to simulate how fastforward works on some services which is that tapping on fast forward jumps forward 10 secs. but press and hold for a couple seconds activate fastforward.

what i've done to work around it is this:


  fast_forward:
    icon: mdi:fast-forward
    tap_action:
      service: androidtv.adb_command
      service_data:
        entity_id: media_player.main_bedroom_fire_tv
        command: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 1 && sendevent /dev/input/event4 0 0 0 && sendevent
          /dev/input/event4 4 4 786611 && sendevent /dev/input/event4 1 208 0 &&
          sendevent /dev/input/event4 0 0 0    
    hold_action:
      service: script.androidtv_send_command_pair
      service_data:
        entity_id: media_player.main_bedroom_fire_tv
        command1: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 1 &&  sendevent /dev/input/event4 0 0 0
        delay: 3
        command2: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 0 && sendevent /dev/input/event4 0 0 0

what i'd like to do is this:


  fast_forward:
    icon: mdi:fast-forward
    tap_action:
      service: androidtv.adb_command
      service_data:
        entity_id: media_player.main_bedroom_fire_tv
        command: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 1 && sendevent /dev/input/event4 0 0 0 && sendevent
          /dev/input/event4 4 4 786611 && sendevent /dev/input/event4 1 208 0 &&
          sendevent /dev/input/event4 0 0 0    
    button_press:
      service: androidtv.adb_command
      service_data:
        entity_id: media_player.main_bedroom_fire_tv
        command: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 1 &&  sendevent /dev/input/event4 0 0 0
    button_release:
      service: androidtv.adb_command
      service_data:
        entity_id: media_player.main_bedroom_fire_tv
        command: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 0 && sendevent /dev/input/event4 0 0 0


@armedad armedad added the enhancement New feature or request label Feb 5, 2024
@Nerwyn
Copy link
Owner

Nerwyn commented Feb 5, 2024

So if I'm understanding this correctly, this would add a new action hold_end_action. tap_action would trigger normally, then if the button is held down long enough (500 ms) hold_action will trigger, and then on, and then finally when the button is released hold_end_action will trigger?

@armedad
Copy link
Author

armedad commented Feb 6, 2024 via email

@Nerwyn
Copy link
Owner

Nerwyn commented Feb 6, 2024

That makes sense, it would just mean that you could not have hold start/end actions on the same button that has a tap action. We could also make it so that the hold_secs number that gets sent with the hold end action counts from the initial hold start event, so it counts up from 500 ms. That way you would still only need to hold for 1000 ms, but the initial hold start action wouldn't be sent until 500 ms.

I could possibly implement both, and make it so that hold_end_action triggers if hold_action or hold_start_action is initially triggered (as described in my first comment), and then if hold_start_action is defined it disables tap_action and hold_action.

@armedad
Copy link
Author

armedad commented Feb 6, 2024 via email

@armedad
Copy link
Author

armedad commented Feb 6, 2024 via email

@Nerwyn
Copy link
Owner

Nerwyn commented Feb 6, 2024

So button_press and button_release would replace the normal tap/double/hold actions if they're configured for a button?

@armedad
Copy link
Author

armedad commented Feb 6, 2024 via email

@Nerwyn Nerwyn self-assigned this Feb 17, 2024
@Nerwyn
Copy link
Owner

Nerwyn commented Feb 17, 2024

This should be working in the latest beta. Can you try installing it and a command like this?

custom_actions:
  fast_forward:
    icon: mdi:fast-forward
    momentary_start_action:
      action: call-service
      service: androidtv.adb_command
      data:
        entity_id: media_player.main_bedroom_fire_tv
        command: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 1 &&  sendevent /dev/input/event4 0 0 0
    momentary_end_action:
      action: call-service
      service: androidtv.adb_command
      data:
        entity_id: media_player.main_bedroom_fire_tv
        command: >-
          sendevent /dev/input/event4 4 4 786611 && sendevent /dev/input/event4
          1 208 0 && sendevent /dev/input/event4 0 0 0

You can also include HOLD_SECS in the service call data value if possible for momentary end actions.

@Nerwyn
Copy link
Owner

Nerwyn commented Feb 22, 2024

@armedad still waiting for your feedback

@Nerwyn Nerwyn assigned armedad and unassigned Nerwyn Feb 22, 2024
@armedad
Copy link
Author

armedad commented Feb 23, 2024 via email

@armedad
Copy link
Author

armedad commented Feb 23, 2024

i've got to be doing something wrong. i'm not getting the start and end action events being triggered at all.

i've got this. only tap_action triggers. if i remove tap_action it complains to me of not having an entity for send_command.

note that i put volume up/down/mute just for testing... it helps me see exactly what's happening.

fast_forward: icon: mdi:fast-forward tap_action: service: webostv.button service_data: entity_id: media_player.great_room_lgtv button: VOLUMEUP momentary_start_action: service: webostv.button service_data: entity_id: media_player.great_room_lgtv button: VOLUMEUP momentary_end_action: service: webostv.button service_data: entity_id: media_player.great_room_lgtv button: MUTE

it feels as if i don't even have the new version on, however i am getting this:
image
and i did a reboot of home assistant just in case.

i've opened up the .js file in config\www\community.... and i see "momentary_end_action" in the js, so i believe i've got it downloaded.

can you see an issue with the above?

@Nerwyn
Copy link
Owner

Nerwyn commented Feb 23, 2024

It's probably a caching issue in your browser like with the keyboard. Can you try clearing it (or the HA app cache) and trying again?

@armedad
Copy link
Author

armedad commented Feb 23, 2024 via email

@Nerwyn
Copy link
Owner

Nerwyn commented Feb 23, 2024

Great! If it's all good I'll work on the final release later.

@Nerwyn
Copy link
Owner

Nerwyn commented Feb 26, 2024

Added in 3.4.0

@Nerwyn Nerwyn closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants