MycroftAI / skill-homeassistant

Mycroft Skill/Integration for Homeassistant
GNU Lesser General Public License v3.0
114 stars 62 forks source link

Button intent #124

Open Delfshkrimm opened 1 year ago

Delfshkrimm commented 1 year ago

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!

Tony763 commented 1 year ago

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 commented 1 year ago

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:

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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