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

Button intent #124

Open
Delfshkrimm opened this issue Feb 20, 2023 · 6 comments
Open

Button intent #124

Delfshkrimm opened this issue Feb 20, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@Delfshkrimm
Copy link

Is your feature request related to a problem? Please describe.
There is no button intent support for ha

Describe the solution you'd like
It would be cool to have an intent like "(press | activate) {Entity}". But i'm new to HA so there might already be another intent already supported that can be used to realise this action?

Describe alternatives you've considered
Maybe wait for scripts or already use scene support for more generic use of buttons entity directly in HA?

Thanks in advance and great job!

@Delfshkrimm Delfshkrimm added the enhancement New feature or request label Feb 20, 2023
@Tony763
Copy link

Tony763 commented Feb 20, 2023

Hi, could you post here a link to example entity, please? Im not aware about this kind of entity type in HA to be present.

@Delfshkrimm
Copy link
Author

Delfshkrimm commented Feb 20, 2023

Sure! So for a bit of explaination: It's a simple button entity that I created through HASS.Agent on my Windows machine (that acts as a media center at my place) that leverages the MQTT command in HA:

Capture d’écran de 2023-02-20 17-29-55

(For information HA is on my Nuc (debian11) and commands my media center through a list of HASS.Agent commands (for turning on/off volume, play/pause the current media, launch a straming service etc.).)

This command from HASS.Agent just uses the Media Pause/Play action and creates an entity "Button" in HA. I should then be able to plug it to a mycroft intent such as "press play button" (if my button entity is named "play button" in HA).

Currently my workaround to be able to "press" a button was to create the HASS.Agent command with a Switch type instead of Button type. And then use the intent turn.on/off or toggle in order to activate the entity.
But since it's a button under the hood and not a switch (no dual state), turning it on always turns it back off after activation. So instead of using both turn.on and turn off intents, i've hacked the behavior by:

  • naming my fake switch entity "the video"
  • adding "stop {Entity}" and "play {Entity}" in the turn.on.intent
  • then when i say "stop the video" turn.on.intent is called and the entity is turned on (then immediately turned off) and the media is paused
  • same if i say "play the video", the turn.on.intent is called again and the entity is turned on and the media is played

I hope my explaination is clear enough, I can elaborate if needed. Thanks a lot amigo!

PS : here is the command I created in HASS.Agent just to show you the entity type "Button" (in the drop down list there are also "Light, Lock, Siren and Switch". My other command that hacks the Switch behavior as I explained uses the Switch filter in this dropdown list.
Capture d’écran de 2023-02-20 17-32-32

@Delfshkrimm
Copy link
Author

For reference, here is the HA doc for the Button intent: https://www.home-assistant.io/integrations/button/
I guess I could implement the behavior of calling the service button.press in the intent as you do it for switch but with less processing on the state (that doesn't exist) of the entity?

@Delfshkrimm
Copy link
Author

Delfshkrimm commented Feb 21, 2023

Got it to work with domain = "button" and service = "press".
So api call looks like: /api/button/press with payload = {entity_id: ha_entity['id']}

Do you want me to PR?
Again thanks a lot for everything :)

@Delfshkrimm
Copy link
Author

In the end, and for my specific use case, looking through the API doc I ended up ditching the commands specifically for the media_player entity back on HASS.Agent, and leverage the default API for domain="media_player" and use the "volume_up/down/set", "media_play/pause", etc. services with corresponding payloads.
It's much cleaner for this specific use case and I still can use HASS.Agent for other non native commands I want to execute on my media player computer (like opening programs such as Kodi etc.).

Nevertheless, the ability to trigger button.press service did the trick at first for me, and I still think it would be cool to have it (along with media_player intents ?) in the skill :)

Cheers

@Tony763
Copy link

Tony763 commented Feb 21, 2023

Thanks for doc, I will look into it when I will have a free time. Media_player is also on my TODO list.

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