Allow for dynamic responses when using the 'Sentence' trigger #295
Replies: 3 comments
-
I like all your ideas. Here are the initial notes I put together while brainstorming how to approach this a while back. These ideas aren’t fully developed yet—just some rough thoughts I wanted to capture. Option 1 (less preferred)Allow the sentence response field to accept Jinja2 templates.
Option 2Introduce two modes for the sentence node: Trigger and Response, similar to most entity nodes.
|
Beta Was this translation helpful? Give feedback.
-
I'll get started with implementing Option 2. Using the already existing Websocket message id reduces complexity but can cause problems down the line I think. I'll start experimenting... |
Beta Was this translation helpful? Give feedback.
-
I’m not sure if there’s been any progress on this, but I was able to find some time to complete the Home Assistant side. Now, I just need to wrap up a few remaining tasks on the Node-RED side. |
Beta Was this translation helpful? Give feedback.
-
At the time of creating this request, there is no way to create 'dynamic' responses for the Sentence trigger.
The response is defined in the Sentence node and is immediately returned when said sentence is triggered. This does not allow for create templated responses, or for forwarding an error to the user.
My suggested fix is as follows:
Inside the
handle_trigger
callback of thewebsocket_sentence
function we register a unique id for that specific Sentence trigger in a map. This id is return by the node in Node-RED.Create a new 'Response' node that takes in the Sentence trigger id and a response value.
Create a new websocket command, maybe call it
webhook_response
, that listens for requests from the new Response node and maps the given response to the Sentence trigger id in the map.Inside the
handle_trigger
callback of thewebsocket_sentence
function we wait for the Sentence trigger id in the map to be assigned a response value from the websocket command. If this does not happen within a set timeout period we return a default response.If a response node is fired while there's already a response registered we throw an error.
I will start by forking the repo and creating a PoC of this solution. Please give feedback on this proposed solution.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions