How to cast mp3 local file in nodered as HA addons

Hi Everyone,

Currently iam running nodered as homeassistant addons and i need to cast mp3 local file from nodered.

Unfortunately can't find /endpoint directory to put an mp3 file. Only find the nodered directory to put mp3 file in usr/share/hassio/homeassistant/ but not success to play it.

The messages debug in nodered is "Not able to load media:Load failed Not able to load the media."

Try to test access the mp3 URL directly in browser but can't play and have a messages "Cannot GET /endpoint/test.mp3"

Checking the homeassistant log is "Failed to cast media https://xxxxx.com:1880/endpoint/test.mp3. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address"

Try to follow this topic How to cast videos - #19 by Steve-Mcl and this procedure node-red-contrib-cast (node) - Node-RED to play local files but it didn't work for me

Try to use this sample Create an HTTP Endpoint : Node-RED it's works like charm

Believe what next step i need is have to play mp3 successfully in browser but i don't know where exactly /endpoint folder to put an mp3 file.

I have no config anything auth for http_node options. only have https ssl configuration.

Anyone can help how to cast local life with this situation? Let me know if I am missing in this scenario. and let you know this flow below

[{"id":"01a5fce4debb676d","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"7058ebff8eb168c9","type":"http in","z":"01a5fce4debb676d","name":"","url":"/","method":"get","upload":false,"swaggerDoc":"","x":420,"y":200,"wires":[["495526aab1718814","51d348fe933a5d73"]]},{"id":"495526aab1718814","type":"file in","z":"01a5fce4debb676d","name":"","filename":"test.mp3","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":680,"y":200,"wires":[["5010c49e41e7e78c","d64a5e7e4565c4e7"]]},{"id":"5010c49e41e7e78c","type":"http response","z":"01a5fce4debb676d","name":"","statusCode":"","headers":{"contentType":"audio/mp3"},"x":910,"y":200,"wires":[]},{"id":"51d348fe933a5d73","type":"debug","z":"01a5fce4debb676d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":140,"wires":[]},{"id":"d64a5e7e4565c4e7","type":"debug","z":"01a5fce4debb676d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":140,"wires":[]},{"id":"4504f24cb43fb341","type":"cast-to-client","z":"01a5fce4debb676d","name":"","url":"","contentType":"","message":"","language":"en","ip":"","port":"","volume":"50","x":670,"y":260,"wires":[["af95eba64593a3df"]]},{"id":"c11bc90cb49306ac","type":"inject","z":"01a5fce4debb676d","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"ip\":\"192.168.50.50\",\"url\":\" https://xxxxx.com:1880/endpoint/\",\"contentType\":\"audio/mp3\",\"volume\":50}","payloadType":"json","x":490,"y":260,"wires":[["4504f24cb43fb341"]]},{"id":"af95eba64593a3df","type":"debug","z":"01a5fce4debb676d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":890,"y":260,"wires":[]},{"id":"0e4784673f6c4c0d","type":"http in","z":"01a5fce4debb676d","name":"","url":"/hello","method":"get","upload":false,"swaggerDoc":"","x":430,"y":380,"wires":[["66915b6fa8705d51"]]},{"id":"66915b6fa8705d51","type":"template","z":"01a5fce4debb676d","name":"page","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n    <head></head>\n    <body>\n        <h1>Hello World! Good Morning!</h1>\n    </body>\n</html>","x":620,"y":380,"wires":[["6caa147e3ba74a64"]]},{"id":"6caa147e3ba74a64","type":"http response","z":"01a5fce4debb676d","name":"","statusCode":"","headers":{},"x":760,"y":380,"wires":[]}]

Try these steps ↑

This is what I use to play local media files.

[{"id":"4fb7f41ac04ccb3c","type":"api-call-service","z":"d0505e55.8a4b8","name":"Play","server":"","version":5,"debugenabled":false,"domain":"media_player","service":"play_media","areaId":[],"deviceId":[],"entityId":["media_player.living_room_speaker"],"data":"{\"media_content_id\":\"media-source://media_source/local/test.mp3\",\"media_content_type\":\"music\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1080,"y":320,"wires":[[]]}]

The test.mp3 file is saved in /usr/share/hassio/media/.

1 Like

I dont use HA so cant help there.

Did you try what I asked?

At step 2, did you enter the URL into the browser? What URL did you use? What did you see?

Hi @Steve-Mcl ,

This is a result that I use as your suggestion.

  1. Use the full path to file (/usr/share/hassio/homeassistant/node-red/audio/test.mp3)

  2. Cannot set this to /test but /endpoint/test

  3. Access entering url use into the browser (https://x.x.x.x:1880/endpoint/test)

  4. Check the browser pages (This site can’t be reached)

  5. Check debug msg.payload (Error: ENOENT: no such file or directory, open '/usr/share/hassio/homeassistant/node-red/audio/test.mp3')

image

image

[{"id":"4e8121031854c065","type":"http in","z":"01a5fce4debb676d","name":"","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":250,"y":220,"wires":[["122a3ecd7775d97f","a82de37c21178ffb"]]}]

What should need to check further and next action for this error?

Not a HomeAssistant user, but.

The problem here will be that HomeAssistant runs Node-RED in a container, so unless the /usr/share/hassio/homeassistant/ directory has been mounted into the container it will not have access to it.

You will have to ask the HomeAssistant node-red plugin folk what paths on the host system are available to the plugin.

Hi @hardillb @Steve-Mcl ,

So, my flow and config above is correct but have no exit way?

Is there an alternative way to use public directory that can mount and access for this situation?

Did you ask on HA forum which directories are available/shared to the node-red container?

/usr/share/hassio/homeassistant is mapped to /config inside the container
You should use /config/node-red/audio/test.mp3

Is Node-RED accessible via https://x.x.x.x:1880 ? Did you expose port 1880 in the add-on configuration?

Hi @mbonani ,

Can not find /config/node-red/ directory. could you advise the /config/node-red/ is mapped to where?
so I can put test.mp3 file in there.

Yes, expose port 1880 in the add-on config. So can accessible via web interface.

This means that what you see on the host as /usr/share/hassio/homeassistant, is seen from within the add-on as /config.

So /usr/share/hassio/homeassistant/node-red/audio/test.mp3, is seen from inside the add-on as /config/node-red/audio/test.mp3. And that's what you should use in the node in this case.

Ideally, you'd save audio/video files to /usr/share/hassio/media, which is mapped to /media in the add-on.

Hi @mbonani ,

Well noted.

If nodered need accessible file via https://x.x.x.x:1880/endpoint/audio/test.mp3

Let me know the directory on the host that I can save audio files to, So is seen from within the add-on as /endpoint/audio/test.mp3

Also I can set this url below correctly and can play test.mp3 via webbrowser directly.

image

Do you mean you want to access multiple mp3s but only specify endpoint /endpoint/audio/

e.g.

  • you want to save sound1.mp3 to /config/node-red/audio/ and access it via /endpoint/audio/sound1.mp3
  • you want to save sound2.mp3 to /config/node-red/audio/ and access it via /endpoint/audio/sound2.mp3
  • etc etc
  • but with only having one endpoint setup as /endpoint/audio/

Is that what you mean?

@mbonani already said " /usr/share/hassio/homeassistant , is seen from within the add-on as /config"

So putting sound1.mp3 inside /usr/share/hassio/homeassistant will be /config/sound1.mp3 for node-red.

Now i am confused - can you access your test.mp3 or not?


Maybe you should start again. Show use what files you have put where and what your flow currently is. Also, explain fully what your end goal is.

Hi @Steve-Mcl ,

The end goal is can cast mp3 local file. Let you know this config and flow currently below.

[{"id":"01a5fce4debb676d","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"4e8121031854c065","type":"http in","z":"01a5fce4debb676d","name":"","url":"/audio","method":"get","upload":false,"swaggerDoc":"","x":250,"y":220,"wires":[["122a3ecd7775d97f","a82de37c21178ffb"]]},{"id":"122a3ecd7775d97f","type":"file in","z":"01a5fce4debb676d","name":"","filename":"/config/node-red/audio/test.mp3","format":"","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":570,"y":220,"wires":[["dd8a20a5580907a2","ee4e9408ac8af6a9"]]},{"id":"dd8a20a5580907a2","type":"http response","z":"01a5fce4debb676d","name":"","statusCode":"","headers":{"contentType":"audio/mp3"},"x":850,"y":220,"wires":[]},{"id":"a82de37c21178ffb","type":"debug","z":"01a5fce4debb676d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":250,"y":280,"wires":[]},{"id":"ee4e9408ac8af6a9","type":"debug","z":"01a5fce4debb676d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":530,"y":280,"wires":[]},{"id":"5d8b66fce47eb44b","type":"cast-to-client","z":"01a5fce4debb676d","name":"","url":"","contentType":"","message":"","language":"en","ip":"","port":"","volume":"50","x":490,"y":360,"wires":[["5e99d16a17a8d2be"]]},{"id":"1503885c909d3f21","type":"inject","z":"01a5fce4debb676d","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"ip\":\"x.x.x.x\",\"url\":\"https://x.x.x.x:1880/endpoint/audio/test.mp3\",\"contentType\":\"audio/mp3\",\"volume\":50}","payloadType":"json","x":310,"y":360,"wires":[["5d8b66fce47eb44b"]]},{"id":"5e99d16a17a8d2be","type":"debug","z":"01a5fce4debb676d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":360,"wires":[]}]
  1. Already put file test.mp3 to /usr/share/hassio/homeassistant/node-red/audio/test.mp3
  2. Already config the flow as above configuration
  3. Can not play mp3 by accessing https://x.x.x.x:1880/endpoint/audio/test.mp3

Is there any missed config?

No, you cannot because you named your endpoint /endpoint/audio - that is the only endpoint possible.

Thats why I asked...

what happens if you try https://x.x.x.x:1880/endpoint/audio in a browser?

Hi @Steve-Mcl ,

Yes should be want like that. but i need to try for only single mp3s first

if try access https://x.x.x.x:1880/endpoint/audio in a browser, what happens is auto download a file with no extension. then I complete rename with extension .mp3, this is actually file test.mp3 that I put to /usr/share/hassio/homeassistant/node-red/audio/

image

ok, so now we know it works, you can try casting the URL https://x.x.x.x:1880/endpoint/audio to your device.

After that, I will show you how to do multiple files.

Hi @Steve-Mcl ,

Already try casting the URL https://x.x.x.x:1880/endpoint/audio, the cast status node is play but have no any sound in speaker. Any missed?

image

and few minutes came error load media

image

Try entering a valid content type header in the HTTP response...

image