How to trigger a flow from the command line

I just finished setting up Kodi on my RPi, so now I have 3 installed OSs (Kodi, Retro Pie, and Raspbian). I've also got homebridge and node-red running and after setting up Kodi, I had an idea. It would be really cool if I could switch OSs by telling Siri "Turn on <Kodi|Retro Pie|Raspbian>". I envision this doing 2 things: quit/kill the currently running OS and start up the other. And I thought... instead of writing a shell script to do it, I might experiment with doing it in a flow. However, how do I get homebridge and Node-Red to cooperate?

I currently have a homebridge plugin called homebridge-commander that executes command-line utilities. I use it primarily for turning on/off my RF outlets using pilight-send's raw protocol. If I write a flow to do the OS switch I'm envisioning, what command can I put in homebridge-commander to trigger the flow to run?

Note, node-red is always running. I saw that you can run a flow (on startup?) from the command-line, but it's not clear to me from the documentation whether that starts up a separate instance of node-red or whether it tells the currently running node-red to run the supplied flow.

Why would you want to switch between operating systems using voice commands?

How is node red “always running” if you “switch/kill” the OS?

So since you have three os is the SD card partitioned into 3 chunks? Does this mean you have to have NR installed three times ? With three copies of the flow?

If so, I’m think that will be a bear to keep them sync’ed

OK, so I'm a noob. I guess "OS" is the wrong term. I got it from somewhere while learning about RPi over the past month or 2. All I know is, you can't have any of them running at the same time, you can't launch one from inside the other (e.g. you can't launch emulationstation from a terminal inside raspbian), and I only have one instance of node-red and homebridge each running even when I kill kodi, emulationstation, or raspbian.

To answer the "why" question, it's for home automation. If I want to watch a movie using kodi while sitting on the couch, it's easier to tell my smart speaker to "turn on kodi" than it is to walk across the room, kill whichever thing is currently running (e.g. using the game controller to stop emulationstation), start up my vpn client, and start up kodi. Also, I've got to find the remote, turn on the TV, switch to HDMI 1, and launch the kodi remote app on my phone. However, I can create a scene in the home app on my phone to do every one of those steps with a single spoken command, including the launching of the kodi remote app on my phone. Besides that, I just like messing around with automation. It's fun.

1 Like

Get another Pi :slight_smile:

BTW, I've already written a shell script with a bunch of functions to accomplish the "OS" switch (for lack of a better term.. what should I call these things? "full screen apps"? That doesn't seem to convey that they can't run along side one another).

The only problem I have now is that when I exit out of kodi and don't start up one of the other "OSs", vt 1 is getting corrupted and I have to reinitialize it using either alt+F1 or executing sudo chvt 2;sudo chvt 1. But I guess that's not an issue for this forum.

I figure for now, I can just run one of the bash functions from inside either node-red or homebridge now that I have everything working from the command line (via ssh). So I guess my original problem is ultimately solved. I still don't know how to trigger a flow from the command line though unless I use something like a webhookrelay call using curl, but it seems like there should be a completely local way...

When Node Red starts the flows will run automatically.

I've received the advice to get another pi on a few occasions. But everything works fine on one. I'm not sure why I would get another. There's only one TV and I'm not keen on switching wires anytime I want to switch from retro to kodi or raspbian. Even if they could run simultaneously, I only ever want to use one at a time.

Node-red is running all the time. It handles all my automations. So running a flow upon node-red startup isn't what I'm looking for. I can trigger flows with webhookrelay and curl, but there's got to be a way of doing it so I can trigger flows from the command line and keep everything local.

If node red is running the flows are too, are you looking to trigger an action remotely?

There is no specific node that exposes flows to the command line.

You can use the HTTP In nodes to create flows you can trigger locally using curl - no need to use webhookrelay.

1 Like

Hmmm... interesting. So I can create an http node that can receive a local trigger, like curl http://localhost...? That would work. I'll look into that.

My intent is to use it from the homebridge-commander plugin for homebridge. I set up homebridge a good while before I started playing with node red. I've got a handful of plugins and a little over a dozen devices set up in it (RF outlets, WeMo Devices, a garage door, my TV, etc.). It's a little buggy. Sometimes I have to issue commands twice. Sometimes the command succeeds but Siri thinks it failed.

I looked into trying to have my homebridge(/home app) devices show up in node red, but apparently you can only create devices in node red and can't issue commands to devices that the home app already is aware of. I guess that makes sense now that I understand better how it all works.

Perhaps at some point, setting up the devices anew in node red using a homekit node would be worthwhile. It might work better than homebridge (but I think they're both built on the same HAP-nodejs thing - so perhaps not). The limitation of homebridge is that I cannot control its devices remotely without exposing the pi to the internet to some degree, nor can you use any sort of autonomous triggering, which is why I've started playing with node red and webhook relay. Even if I did set up a homekit node, the remaining limitation might be that I cannot use Siri to trigger actions remotely... unless again, I expose the RPi to the internet.

But being able to trigger flows from the command line (or rather, the homebridge-commander plugin) was the low-hanging fruit option I was exploring for being able to use Siri to switch "OSs" on the RPi.

BTW, I've picked up that my usage of the term "flow" may be inaccurate. Should I be using the term "action" instead of "flow"? I'm inferring from ghayne's comments that I'm not using the term precisely.

I use galaxy a lot at work and galaxy has "workflows" that you can create in an editor that is very similar to the flow editor in Node-Red. In galaxy, a workflow is a single thing that you can run. To run it, it presents you with a web form where you must supply all the required inputs and then click a "Run workflow" button. So for years, I've thought of a workflow (i.e. "flow") as a single sequence of commands that you trigger once to run it, and I applied that concept to my understanding of node-red, since they're so similar. I thought flows were just sitting around on disk waiting to be "run" or "triggered". So I was initially confused at first about those little tabs on the inject nodes. I started thinking of them as triggers for flows with pre-built inputs, like pre-filled-out forms to run workflows in galaxy, to run a flow.

But now I realize that you can have stuff in a "flow" that doesn't all run when you trigger via an inject tab or a webhook relay input. So do you refer to a single sequence of contiguous nodes as an "action" and the "flow" is a collection of 1 or more "actions"?

ghayne indicated that the flows are running all the time and that what I want to do is trigger an "action" inside a constantly-running "flow". So I apologize that I've been unclear.

The term 'flow' is overloaded to mean a single tab in the editor and also any one particular set of joined nodes.

If you use mqtt, for homekit you may be better off with ‘homebridge-mqtt’, which can be easily used in nodered to ‘create’ homekit devices. Rock solid performance with homekit.

I haven't gotten into mqtt (yet). It seems interesting.

I looked into it once in order to try and receive garage door open/close events so that I could use them as triggers to control devices and update my slack status, but as I understand it, in order to know when the garage door does something that I don't initiate via node-red (e.g. using the remote that comes with the garage door, the myQ app, or the keychain remote I bought), I would either have to modify the proprietary code that runs in the opener itself or attach some sort of mqtt-capable sensor to monitor the state of the door...

But I guess what you're suggesting is different, so let me see if I understand correctly what it is you're suggesting (please forgive my mqtt ignorance). You're suggesting I install the homebridge plugin for mqtt? If I do that, are you saying that devices I already have configured in homebridge (using other plugins, such as home-bridge-commander of homebridge-liftmaster2) that those can be duplicated in node-red? And if all that's correct, I assume I need to install an mqtt server (i.e. "message broker") on my RPi that can send & receive messages from homebridge and node-red?