HowTo: NodeRed – Perform action on Server-Start

Depending on how you configure your Node-Red installation, it may be convenient for you to be notified when Node-Red restarts.
For example, you will be notified of crashes and related errors in your Node-Red configuration.

How to set up such a status message is explained in the following article.

Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section. 
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂


Safety instructions

I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/sicherheitshinweise/


Requirements

Helpful Articles:
Of course NodeRed should already be installed so that you cango through this article.
How to prepare this and a RaspberryPi and then install NodeRed on it is described in the following articles.

RaspberryPi – Setting up for Nerdiys!
RaspberryPi – The first configuration
RaspberryPi – Controlling the RaspberryPi via SSH
NodeRed – Installing NodeRed on the RaspberryPi

Required tools:
-none-

Required material:

In the following list you will find all the parts you need to implement this article.


Log in to the NodeRed configuration interface

Before you can edit your NodeRed configuration you must - if activated - first log in to the NodeRed configuration interface.

View of the login screen. Here you have to enter the login details that you entered during the configuration of the login. Information about this can be found in the article NodeRed - User Login Setup.

Node code example

In principle, the server-start-message “only” consists of an injection node with a checkmark set to “Inject once after … seconds then …”. This causes – as described – that this inject node is executed after a reboot.

Here you can see the configuration of the inject node. The hook at “Inject after …” executes the node after restarting NodeRed. You can also set a delayed execution in the input field.

The following Node code outputs a message through the debug node after the server-restart. The following node code contains the complete configuration.

Node-Code:

[{"id":"5c21935a.39e70c","type":"inject","z":"8c9f8f17.13eb78","name":"","topic":"","payload":"NodeRed wurd gerade gestartet!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"","x":3530,"y":240,"wires":[["b3fff434.c1a8c8"]]},{"id":"b3fff434.c1a8c8","type":"debug","z":"8c9f8f17.13eb78","name":"","active":true,"console":"false","complete":"false","x":3710,"y":240,"wires":[]}]

Node code example with pushbullet message

A useful combination is to combine the inject node with a pushbullet node. So after a restart of Node-Red a pushbullet message is send to our phone or other devices.
On this way you get an immediately message as soon as your NodeRed installation may have been restarted.

You can find the Node code in this example.

[{"id":"a604fa0e.8c5138","type":"pushbullet","z":"8c9f8f17.13eb78","config":"5ab02a71.121594","pushtype":"note","title":"","chan":"","name":"","x":3470,"y":380,"wires":[]},{"id":"3017f8fc.bcd818","type":"inject","z":"8c9f8f17.13eb78","name":"","topic":"","payload":"NodeRed wurd gerade gestartet!","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"","x":3270,"y":380,"wires":[["a604fa0e.8c5138"]]},{"id":"5ab02a71.121594","type":"pushbullet-config","z":"","name":""}]

I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂

Fab

P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com

Leave a Reply

Your email address will not be published. Required fields are marked *