Replicating a call_service function in Node-RED

I’m trying to have a Node-RED flow play a sound on a tablet. This service call works from within HA:

service: fullykiosk.play_audio
data:
  entity_id: media_player.fire_tablet_media_player
  url: https://mydomain:8123/local/sounds/please_exit_lights.mp3
  stream: 1

…however, this flow does not:

Main

[{"id":"a569cb64d0c14d3f","type":"api-call-service","z":"b199f89f.aefe08","name":"Announce Exit","server":"296c0678.b5f9ca","version":3,"debugenabled":false,"service_domain":"fullykiosk","service":"play_audio","entityId":"media_player.fire_tablet_media_player","data":"{\"url\":\"https://mydomain:8123/local/sounds/please_exit_lights.mp3\",\"stream\":\"1\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":430,"y":3460,"wires":[[]]},{"id":"f10fa849678274f2","type":"inject","z":"b199f89f.aefe08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":3460,"wires":[["a569cb64d0c14d3f"]]},{"id":"296c0678.b5f9ca","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Where am I going wrong?

EDIT: my temporary solution is to call a script that calls the service, and that works; I just don’t think I should have to write a script and should be able to call the service directly…

You have the domain and service together, they need to be separate

domain: fullykiosk
service: play_audio

Actually, the YAML works fine. It’s the Node-RED flow I’m trying to get to work. In the call service node, they’re separated.

In node red you need to split the service call up into domain and service.

How are you doing this dynamically or settings in the node. Can you screenshot the service call node.

What is the entity? Is it shown as a media_player? Does fullykiosk auto fill in the domain portion?

The entity is shown as a media_player, and fullykiosk auto-fills the domain and service fields. I’m choosing not to do it dynamically, yet.

The data field is outlined in blue or red when selected? There is a check box just below for debug output, check it and then fire the flow and look at the debug message.

The field is blue when selected. Just now, I clicked the “load sample data” button and changed it over to my info… just in case the formatting was off. But it’s doing the same thing. Usually I use a debug node; I didn’t even notice this checkbox:

Main

EDIT: the stream number doesn’t matter, in YAML; it works regardless of what number I’ve chosen.

With debug checked it should expand on the api error.

Ah! It didn’t expand on the error, because there was no error… it’s actually executing the service call now, with the result as in the debug window above… but it’s still not playing the audio. Calling the script still works; the flow does not.

Check the home assistant logs and the nodered log from the addon page. The addon page only holds the last 2 min so you need to trigger the flow and then look at the log. There is also an option on the addon config page to set the log level to debug.

I’d expect the the flow to look like this (sorry posted wrong code before):

[{"id":"e36dd6fd07b50c04","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"705a8bb1442a2247","type":"api-call-service","z":"e36dd6fd07b50c04","name":"Announce Exit","server":"296c0678.b5f9ca","version":3,"debugenabled":false,"service_domain":"fullykiosk","service":"play_audio","entityId":"","data":"{\"entity_id\": \"media_player.fire_tablet_media_player\", \"url\":\"https://mydomain:8123/local/sounds/please_exit_lights.mp3\",\"stream\":\"1\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":980,"y":180,"wires":[[]]},{"id":"599c3a19319db14a","type":"inject","z":"e36dd6fd07b50c04","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":750,"y":180,"wires":[["705a8bb1442a2247"]]},{"id":"296c0678.b5f9ca","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

I set the log level to trace and triggered the script via inject node, which works; then I triggered the play_media node, which doesn’t work. Here’s what I get:

27 Jan 13:26:48 - [debug] [api-call-service:Announce Exit] Calling Service: script:announce_exit_lights_front_door_tablet -- {}
27 Jan 13:26:59 - [debug] [api-call-service:9434ccf44ec34485] Calling Service: fullykiosk:play_audio -- {"url":"https://mydomain:8123/local/sounds/please_exit_lights.mp3","stream":3}

I changed my domain to mydomain, obviously.

When I import those nodes and run (after correcting the domain), I get an API error:

Call-service error. invalid value or type (must have a partial ordering) for dictionary value @ data['stream']

However, the data field looks correct except for the inclusion of the entity_id. I tried that earlier, with the entity_id in the data field. No dice.

Maybe it should be 1 without quotes?

Looking at the service definition, yes the stream should be without quotes since it is a number.

Yeah, for the last few times I’ve been running the stream without the quotes. Here’s the data field:

{"url":"https://mydomain:8123/local/sounds/please_exit_lights.mp3","stream":1}

I’m pretty sure it won’t work with the entity id not in the data field. I’d have to try it on sobering in I know works to validate, but is what I usually do.

When I put this in the data field, the field border is blue (which is good) and I can execute the flow without error, but the media still doesn’t play:

{
    "entity_id": "media_player.amazon_fire_media_player",
    "url": "https://mydomain:8123/local/sounds/please_exit_lights.mp3",
    "stream": 1
}

I validated that you probably don’t need to put the entity id in the data field.

Is there anything that shows in the HA logs? I’ve really had no problems with service calls before as long as I have structured the inputs right.

Does this work?

[{"id":"a569cb64d0c14d3f","type":"api-call-service","z":"b79dc0d3.378dd","name":"Announce Exit","server":"","version":3,"debugenabled":false,"service_domain":"fullykiosk","service":"play_audio","entityId":"media_player.fire_tablet_media_player","data":"{\t   \"data\": {\t       \"url\":\"https://mydomain:8123/local/sounds/please_exit_lights.mp3\",\t       \"stream\":\"1\"\t    }\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":740,"y":620,"wires":[[]]},{"id":"f10fa849678274f2","type":"inject","z":"b79dc0d3.378dd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":510,"y":620,"wires":[["a569cb64d0c14d3f"]]}]