Programatically delete instances of nodes

I'm sure I'm missing something simple here but I'm not seeing it. I can easily use my BigTimer Node to trigger something (like an Alexa Notify Node) later this week - but this is a one-off event. I want to have Node-Red-contrib-bigtimer Tell Alexa to queue a notification once only... Ater it has sent off the notification to Alexa later in the week, I want Node-Red to delete that particular BigTimer, the Notify node and the wire that joins them - as if they'd never been put in flow in thw first place. There might be othe similar one-offs in that flow for different times.

Ideas? Am I missing something trivial or is this a monster to do automatically, programatically without me being there?

I'd thought it'd be possible to launch say a python script that would kill your Node-RED process, edit your flow.json to remove the nodes and restart Node-RED but it'd be quite a bit of work and pain to debug :slight_smile:

[edit]It would be an easier task if you just put the BigTimer & Alexa nodes in a seperate tab with link to main tab and get your python code to to just change Flow disable from false to true

Much easier to debug


[/edit]

What's your actual use case that requires your BigTimer node to be removed from the flow once its triggered.

Personally, I would have thought it better to have a job scheduler with an option to have one-off jobs that then auto-delete themselves.

Perhaps a request to the following thread might end up with an additional feature:

Trying to edit the flow using a flow seems like a recipe for a disaster. Trying to understand that flow later on could be a nightmare.

Would probably be easier to simply have BigTimer (as I wrote BigTimer) delete itself once it had run once... I thought of having BigTimer or Inject delete their own Payload once they'd run, but that is no good for "Alexa NotifyMr" node - it just gripes about no notification.

Basic POC

[{"id":"c1222112.cd919","type":"inject","z":"a208955f.d140e8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":140,"wires":[["4a1838df.ea67c8"]]},{"id":"592048ea.eba7a8","type":"debug","z":"a208955f.d140e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":120,"wires":[]},{"id":"4a1838df.ea67c8","type":"exec","z":"a208955f.d140e8","command":"bash /home/pi/disable.sh","addpay":false,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"","x":450,"y":140,"wires":[["592048ea.eba7a8"],[],[]]}]

disable.sh

#ps aux
#/usr/bin/lxterm &disown
sed -i -e 's/Flow 2","disabled":false/Flow 2","disabled":true/g' /home/pi/.node-red/flows_pi420191007.json
# >/home/pi/.node-red/test.txt
sudo pkill -f node-red
cd /home/pi/.node-red
node-red

I dimly remember dire warnings against self-modifying code...

1 Like

@TotallyInformation as it happens, I have added the ability to "add", "remove", "start", "stop" & "list" schedules as a topic input into the node. Essentially that makes this possible

e.g. Something (dashboard/api/mqtt) causes a request for a one time event at "09:00:00" (

  1. inject topic "add" with payload {"name":"9am", "expression":"0 0 9 * * *"}
  2. when the node triggers with a topic of "9am" - this can then be used to "remove" the job.

[update]...
actually, sod it, I decided to also add a .limit property so it will be even easier. :slight_smile:

//inject this into a cron-plus node...
msg.topic = "add";
msg.payload = {"name":"9am", "expression":"0 0 9 * * *", limit:1};

I'll be posting an update in a few days.

2 Likes

Hmm now that payload is a growing object. You may as well not use topic and put the command into the payload as well :slight_smile:

1 Like

yeah, its one of those things. Do ya, dont ya. :thinking:

What would be your advice / recommendation on sending control type inputs to a node?

(sorry to hijack the thread)

Well, I've not the expertise of Dave but my preference would be to keep the topic clear as it can be useful to pass through as a "tag" or "category" through a flow.

1 Like

This one certainly sems to have wings. My current solution unfortunately needs both the name and payload updating in order to see the subject of a replacement scheduled event in the flow before it sets up. The ideal would me to set up a message in this case to the Alexa NotifyMe node, to be actually sent to the node, say, next Friday lunchtime or at a specific time/day in a couple of weeks. Alexa would then turn green from then on until I actually go to Alexa and ask for notifications. I can easily use BigTimer or the Inject Node to set up repeating outputs every day or week or month et at specific times, but a one-off event not as easily. I briefly looked at node-red-contrib-calendar-trigger but that needs a database and hasn't been updated in years.

I was "castigated" for mentioning its update cycle previously :blush:
But it certainly does what it says on the tin, and it doesn't need a database, but it could do with some enhanced functionality. It is quite basic.

Ok I'll take another look just in case.

@scargill Pete, what about using a command line json editor?
and thinking now, we can use this to modify json files in your script, too...
info: https://stackoverflow.com/questions/43292243/how-to-modify-a-keys-value-in-a-json-file-from-command-line

Pete, what about a "flow" boolean variable set to TRUE, put in AND with the input to bigtimer... after bigtimer started, put it to FALSE, and all of that will be disabled... no need to remove anything from flow, and all there if you need that again