Closed schwickster closed 10 months ago
handle_call_service doesn't support response data, which is the websocket endpoint that NR uses. This would need to be added to Home Assistant or NR changed to use the handle_execute_script endpoint.
In the meantime, you can use the API node to make a call to the 'excute_script' endpoint.
{
"type": "execute_script",
"sequence": [
{
"service": "calendar.list_events",
"data": {
"start_date_time": "2023-07-09 00:00:00",
"end_date_time": "2023-07-15 00:00:00"
},
"target": {
"entity_id": [
"calendar.events"
]
},
"response_variable": "service_result"
},
{
"stop": "done",
"response_variable": "service_result"
}
]
}
This helped and its working. However, when I try to use {Template function and try:
This is the payload: {{payload.context.id}} ! The locations are {{payload.response.events[1].location}}
The payload.context.id returns a value, but payload.response.events[1].location does not resolve to a value. It should be:
{ "context":{ "id":"01H4RQK3F1QZM9740W99SQY1MD", "parent_id":null, "user_id":"4409938ad8da43f392aec7d5d1c50d6f" }, "response":{ "events":[ { "start":"2023-07-08T09:00:00-07:00", "end":"2023-07-08T10:00:00-07:00", "summary":"OA", "description":" \r\n", "location":"Band Room K1" },
payload.response.events[1].location
Arrays are zero base. payload.response.events[0].location
This is the output with
This is the payload: {{payload.context.id}} ! The locations are {{payload.response.events[0].location}}
in the Template
This is the payload: 01H4S1YQSSMWYGMS35RV1XVKN4 ! The locations are
This is my flow.
[{"id":"977c23b2e096b041","type":"tab","label":"Test Sand Box","disabled":false,"info":"","env":[]},{"id":"704b39077b155cb1","type":"inject","z":"977c23b2e096b041","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":70,"y":580,"wires":[["ee13db2c6ee8b4e5"]]},{"id":"ec6aa564089e342d","type":"debug","z":"977c23b2e096b041","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":580,"wires":[]},{"id":"ee13db2c6ee8b4e5","type":"ha-api","z":"977c23b2e096b041","name":"","server":"863c96d1.fe1118","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\":\"execute_script\",\"sequence\":[{\"service\":\"calendar.list_events\",\"data\":{\"start_date_time\":\"2023-07-08 00:00:00\",\"end_date_time\":\"2023-07-09 00:00:00\"},\"target\":{\"entity_id\":[\"calendar.journeychurchitapp_gmail_com\"]},\"response_variable\":\"service_result\"},{\"stop\":\"done\",\"response_variable\":\"service_result\"}]}","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":350,"y":500,"wires":[["ec6aa564089e342d","475bbab28154092c"]]},{"id":"475bbab28154092c","type":"template","z":"977c23b2e096b041","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{payload.context.id}} ! \nThe locations are {{payload.response.events[0].location}}","output":"str","x":700,"y":500,"wires":[["bd41b56d53ad33a1"]]},{"id":"bd41b56d53ad33a1","type":"debug","z":"977c23b2e096b041","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":980,"y":500,"wires":[]},{"id":"863c96d1.fe1118","type":"server","name":"Home Assistant","addon":true}]
I'm running HA 2023.07.1 with node-red 14.3.0
@bfmorgan payload.response.events.0.location
I have tried using mustache template for the start_date_time, like {{config}} or {{payload}} and they are not accepted even though the API doc states Data accepts Mustache Templates.
This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This needs to be implemented, because the new way of getting weather forecasts is through service responses. The old way is deprecated, and will be removed in Home Assistant Core 2024.3.
The problem is not just for weather forecasts. In reality, many services are being developed, both custom and resulting from integration, which provide a direct response. I think the implementation is a must, otherwise the call service block, which is fundamental in my opinion, will become unusable
As mentioned you can use the API node however does fundamentally change many workflows starting to move away from the call service node so does need to be updated to accommodate this.
Well if anything can be done with the API node, are all home assistant nodes obsolete? No. They provide a quick and user friendly way to interact with the API. This obviously needs to be implemented.
Looks like responses were added to call_service
endpoint.
https://github.com/home-assistant/core/commit/618b666126a885bfb0ae44571bec0c44ff5bdada
I upgraded to 0.60 but somehow cannot see how to access responses from output messages.
Here is what I get from direct API call - this is expected outcome:
But when I call call_service node with the same setting I get two output messages - none of them containing expected results:
Is there some way I should configure call_service node to access these newly added results ?
@sgurgul Are you running Home Assistant 2023.12+?
Yes:
I tried full OS reboot to check if it help but it did not change anything
@sgurgul You'll need to use the output properties to set the results to a property of the message object.
If that doesn't solve your issue please open a different issue. As it would be unrelated to this one.
Yes, I confirm. That was the missing piece on my side. Setting output property gives me access to results. Thank you.
I have the same problem, but trying to get Todo items. However, I don't see "results", but only "sent data". I have nodered, noderedcompanion and HA updated to last version. Is there something I am missing?
@fherreror If you don't see "results" as an option in output properties I would double-check the version you're running.
@fherreror If you don't see "results" as an option in output properties I would double-check the version you're running.
The thing is that, theoretically, everything is up to date:
Add-on version: 16.0.2 You are running the latest version of this add-on. System: Home Assistant OS 11.2 (aarch64 / raspberrypi4-64) Home Assistant Core: 2023.12.1 Home Assistant Supervisor: 2023.11.6 `
14 Dec 11:20:46 - [info] Node-RED version: v3.1.0 14 Dec 11:20:46 - [info] Node.js version: v18.18.2`
The only thing that may be outdate is node-red-contrib-home-assistant-websocket, which is in v 0.59.0. However I cannot update it, as it requires nodered v 3.1.1, which is higher that the one used by the addon.
These are the output options available:
I assumed that "data sent" whould return the data sent by the service, but it throws the same error.
I don't know what else to do in order to get de data sent by services
@fherreror If you update websocket node to version 0.60 (not higher) than it will work - you will get a "result" object available in NR containing results of call-service.
@fherreror If you update websocket node to version 0.60 (not higher) than it will work - you will get a "result" object available in NR containing results of call-service.
Thanks. I have updated to 0.60.1, but then all my nodes with data field empty show error. This bug has been fixed in 0.60.1 I think, which is the version I theoretically have installed. Anyway, I think I will wait until addon updates :(
From my experiments, 0.60.0 is the last version to be used with current HA & NR. If you go with newer you will expect problems - either data field empty error (with 0.60.1) or incompatible NR version (0.61.* and newer).
On the other side, 0.60.0 works OK and it gives access to call-service results. It is also fully backward compatible - I did not need to change anything in my existing flows.
@sgurgul Hey, can you please tell me how to upgrade only to 0.60.0?
@sgurgul Hey, can you please tell me how to upgrade only to 0.60.0? Download from here: https://registry.npmjs.org/node-red-contrib-home-assistant-websocket/-/node-red-contrib-home-assistant-websocket-0.60.0.tgz Then in nodered, instead of update package, go to install tab, and there is a buton to upload a package. Select the downloaded file and restart node red. But make a backup before, in case you need to restore.
From my experiments, 0.60.0 is the last version to be used with current HA & NR. If you go with newer you will expect problems - either data field empty error (with 0.60.1) or incompatible NR version (0.61.* and newer).
On the other side, 0.60.0 works OK and it gives access to call-service results. It is also fully backward compatible - I did not need to change anything in my existing flows.
Thanks, I will try 0.60.0
The binary of the speciic version of the node you can download from the nmpjs.org page. For 0.60.0 it would be like that: https://registry.npmjs.org/node-red-contrib-home-assistant-websocket/-/node-red-contrib-home-assistant-websocket-0.60.0.tgz
Once you have it you should do following:
Installation can be done in "manage palette" screen, "Install" tab - there is a button called "upload module tgz file".
0.60.0 works nice. thank you
Confirm working with 0.60.0
Thanks aswell for this detailed step by step tutorial.
Thank you @sgurgul, this was precisely what I needed to access my weather.get_forecasts data from the meteostation. Kudos!
Describe the bug
Hey,
Currently when calling calendar.list_events service it's suppose to return data. However the error that's returned is
"Call-service error. Service call requires responses but caller did not ask for responses"
This feature is new since HA 2023.7.0. Looks like Nodered HA node does not have this feature yet. Would love this to be added.
To Reproduce
Expected behavior
Array of event from calendar
Screenshots
No response
Example Flow
This package's version (not the Home Assistant add-on version)
0.51.0
Is Node-RED running in Docker?
Yes
Node-RED version
3.0.2
Node.js version
16.16.0
Additional context
No response