New to Node-Red; How to play radio channel on speaker?

Very new to Node-Red, but it’s completely rejuvenated my interest in automations for my HA-setup.

So, I’m now trying to create a flow, where if I press an input boolean then a specific radio channel will play on my office speaker.

I used to be able to do that in the HA automations (well, haven’t figured it out since they changed them), but I’m having difficulty with inputting the correct data in Node-Red.

My flow is:
A “Events: state” node leading to a “call service” node.

Input is correctly picked up, but the call service says “API error”. So, how exactly do I enter the data to correctly play my intended radio station?
Domain, service and entity id are all set.

I’ve tried investigating on the node-red website, but can’t say I’m any wiser from it.

thanks,

Without posting your flow or how the nodes are configured, it’s hard to say what you did wrong. If it’s only turning on an input boolean there is no data needed only the turn_on service.

Is the easiest way to show my flow via a screenshot?

My current call service node is configured like so:

domain: media_player
service: media_play
entity id: media_player.office

Right now, when I activate my input boolean, my office speaker starts playing whatever was last playing on it. What I’m trying to do is make it play a specific source, a radio channel in this case.

Ideally you are sharing both. Screenshot and the JSON export. Just mark all the nodes and then click on export in the NodeRed UI. You can then copy paste the code here.
I would recommend scrubbing it before posting it here:

In any case… you need to find out the correct service call to play a specific source via Home Assistant.
Node Red is just using the HA Calls. It just uses a different format.
You can play around in the developer tab with the different service calls and when you found it, just format it in json and add it to the data part.

This is an example of the Spotify command to play a specific playlist:

{“media_content_id”:“spotify:playlist:37i9dQZEVXcBWmzZZQtgKv”,“media_content_type”:“playlist”}

image
Take special notice of the different service call. Instead of media_play it uses play_media.

Thank you.

My flow is this:

When I use the “play_media” in HA’s native automation, I can usually just write “source: [name of my local station]” and it’ll play when the automation runs.
I’ve assigned the radio station as a favourite in the Sonos-app, which is probably why I can just write the name and not a weblink or similar.

Would that be a possible solution inspired by your example; so instead just point the data towards the web-stream of the radio channel?

Where the data is entered change from J expression to {}.

image

oh, did not notice that. I didn’t accidentally expose anything important, did I? :expressionless:

The actual JSON looks like this then.

[{"id":"8795b1fa608e5706","type":"api-call-service","z":"872d85efdc6ad3f8","name":"Play local radio","server":"","version":3,"debugenabled":false,"service_domain":"media_player","service":"","entityId":"media_player.office","data":"{\"media_content_id\":\"https://home-assistant.io/images/cast/splash.png\",\"media_content_type\":\"music\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":970,"y":800,"wires":[[]]}]

found a solution; found a link to a live-stream of the radio channel and put it into the media_content_id.

Man, Node-Red is definitely a learning journey.

Thank you all very much for pointing me in the right direction!