How to trigger a Node-RED flow from a shell script

There was an earlier thread about this which is now closed. I'd like to ask for some more specific guidance around a couple of the suggestions that were made by @knolleary and @Colin if I may.

The daemon I'm trying to use as a trigger, spotifyd, accepts an onevent parameter for "a script that gets evaluated in the user's shell when the song changes" which seems to provide the opportunity. But I need a little bit of help to work out how to do this simply without causing other issues. Apologies if this is a bit basic.

One suggestion was to use curl to generate an http request that Node-RED would monitor:

  • presumably the IP would be that of the Node-RED server and a particular port specified in both the curl request and Node-RED listening node. The port could be anything not currently used - am I right?
  • does it matter that Node-RED will never respond to the curl request? Would this create a growing stack of unanswered requests that never clear?

Another suggestion would be to send an MQTT message:

  • can that be done simply from shell?
  • does it matter if the MQTT broker is located on another networked machine?

Thanks for the help.

MQTT would work, but you would need an MQTT client installed on the PC, which you may not. curl may well already be installed, and is easily installed if it isn't, so possibly best to use that.


It would be the same port that node red uses (1880 by default). This post in the cookbook shows how you can easily create an http endpoint in node-red.

It will respond, as described in the example.

1 Like

Cool! Thanks @Colin. I've just checked the GET http request out and it's very simple. Since I'm using Ubuntu on an RPi4, curl was already available. MQTT would have involved a 4Mb download of which I'd only be using a tiny part, so that doesn't make sense.

This approach almost solves the first half of my problem, facilitating detection that the Spotifyd Spotify Connect device has started playing. I think I've also found the solution to the second half too - just need to piece it together and it'll be sorted.

Thanks again

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.