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

WebSocket and Assist Pipeline events #10

Open
ReikanYsora opened this issue Aug 17, 2023 · 6 comments
Open

WebSocket and Assist Pipeline events #10

ReikanYsora opened this issue Aug 17, 2023 · 6 comments

Comments

@ReikanYsora
Copy link

ReikanYsora commented Aug 17, 2023

Hello, !

First of all, congratulations on the work done on this DLL. I've been using it for a while for a personal project and it works incredibly well.
It covers all my needs, except for one detail.

I'm trying to use Home Assistant's Assist Pipeline and I'm encountering just one difficulty for which I'd like your opinion.

With this code, I'm able to communicate a pipeline execution request and it works correctly, except that I can't catch the pipeline assist events specified in this documentation Assist Pipeline Dev Documentation

RawCommandResult result = await hassWSApi.SendRawCommandWithResultAsync(new RawCommandMessage("assist_pipeline/run", new { start_stage = "intent", end_stage = "tts", input = new { text = "Turn on kitchen light's" } }));

I'm trying to catch the assist pipeline events with this code :

await hassWSApi.AddEventHandlerSubscriptionAsync(TestEventHandler_Event, "run-start");

or

await hassWSApi.AddEventHandlerSubscriptionAsync(TestEventHandler_Event, "tts-end");

Unfortunately, I can't catch anything, so I can't parse and retrieve the feedback from the assist pipeline, which should give me, in this example, the link to play the TextToSpeech.

In the debug console of Assist Pipeline directly in Home Assistant, my request is mark as done and the action is properly handled (in this case, i speak french to Home Assistant, because i'm french :p)

image

Can you tell me what I'm doing wrong and what method I should use to catch these events?

Thanks you so much

Reikan

@vicfergar
Copy link
Owner

vicfergar commented Aug 17, 2023

Hi @ReikanYsora,

Glad to hear that you are finding this library so useful! 😄

I took a look at your issue, seems that the sending message has the right format. But this pipeline implementation seems to be slightly different from existing ones.

The WS server will respond with an event using the id from the run command. I'm sharing an example here:

image

I will try to take a look for a simple way of handling these result events.

@vicfergar
Copy link
Owner

vicfergar commented Aug 17, 2023

I created a branch named feature/run_pipeline that you can use to test this feature. It's still WIP because STT seems to be slily more difficult to implement as it needs to send binary data over the socket.

This can be used as follows:
IEnumerable<PipelineEventResultInfo> result = await hassWSApi.RunIntentPipeline(StageTypes.TTS, "Turn on kitchen light's");

@ReikanYsora
Copy link
Author

ReikanYsora commented Aug 18, 2023

Thank you very much for the speed of your reply.

I've just tested it, and "intent" and "tts" work perfectly! However, I had to add this line to manually define the pipeline id in my request :
RawCommandResult pipelineInfos = await hassWSApi.SendRawCommandWithResultAsync(new RawCommandMessage("assist_pipeline/pipeline/list"));

By default, if the value of the "pipeline" field is null, the operation fails and asks for it to be defined.

image

By specifying the pipeline ID returned by the '"assist_pipeline/pipeline/list"' command, everything works correctly :)
Maybe I should add a GetPipelines() method to get this information too ?

I understand that SST is more complex, and I'm very interested in this integration.

Anyway, thanks again for everything!

@ReikanYsora
Copy link
Author

ReikanYsora commented Aug 18, 2023

If you want, i have a commit on my 'feature/run_pipeline' forkked branch with this methods and models added

@vicfergar
Copy link
Owner

Good catch @ReikanYsora, I added a fix for that issue.

Feel free to open a PR with the changes from your commit :)

@ReikanYsora
Copy link
Author

Done. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants