HowTo: Node Red – Trigger actions via Windows shortcut / mouse click

So that I can switch off my 3D printer automatically after the printing process, I installed a Sonoff relay so that it can interrupt the power supply to the entire 3D printer. The relay is then controlled via MQTT and automatically switches off the printer after the 3D printing is complete.

The printer can be switched on again in the same way. At the beginning I used an appropriately configured button. At some point, however, I got the idea that this switch-on command should also be feasible with a click on an icon on my computer.

Over time, this resulted in the node red flow below, which can also be used for other actions. All you have to do is run the batch file shown and the configured signal is sent to your NodeRed instance, where you can then react accordingly.

You can find out more information in the following article.


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/en/sicherheitshinweise/

Affiliate links / advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂


Requirements

Helpful Articles:
So that you can install new nodes, NodeRed should of course already be installed.
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.

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.

Trigger action via batch file

This implementation consists of several components. So that you can trigger an action with a click of the mouse, you must first create a batch file. This is a script with which command line commands under Windows can be summarized and triggered.

To switch my 3D printer on and off, I created two batch files. The file for switching on the 3D printer switches the 3D printer on immediately after execution without further request.

The file for switching off waits for a further confirmation after execution. Only when this has been confirmed with a “Y” the command to switch off the 3D printer gets executed. In this way, you cannot accidentally switch off the 3D printer (for example during a printing process).

On the left you can see the content of the batch file for sending a command without further inquiry.

To do this, the link

https://server.fritz.box:1880/http2mqttBridge.json?action=3dPrinterOn

is called. The value “3dPrinterOn” is transferred for the parameter “action”. This value is read out in NodeRed and reacts to it depending on it.

When the link is called up and the value “3dPrinterOn” is selected, the 3D printer is switched on.

The content of the batch file can also be found below as text.

curl --insecure https://server.fritz.box:1880/http2mqttBridge.json?action=3dPrinterOn

In this example you can see the content of a batch file for sending a command including confirmation. That is, before the link

https://server.fritz.box:1880/http2mqttBridge.json?action=3dPrinterOff

is called, you will first be asked whether you really want to do this. Only then the link is called up.

The value “3dPrinterOff” is transferred for the parameter “action”. Your NodeRed instance can read out this value again and act accordingly. In this case the 3D printer is switched off.

The content of the batch file can also be found below as text.

@echo off
:repeat
   set /p answer=3D Pinter poweroff: Proceed (Y/N)?
   if /i "%answer:~,1%" EQU "Y" curl --insecure https://server.fritz.box:1880/http2mqttBridge.json?action=3dPrinterOff && exit /b
   if /i "%answer:~,1%" EQU "N" exit /b
   echo Please type Y for Yes or N for No
   goto repeat

You can easily create batch files yourself. Simply create a simple text file, save the content shown above and then change the file extension of the text file from “.txt” to “.bat”. Then you can run the batch file by double-clicking on it. 🙂


The NodeRed code for further processing

So that your NodeRed instance executes the calls received, you must of course add some NodeRed code to your NodeRed instance. You can find information on this in the following article.

View of the required NodeRed flow.

The NodeRed implements a link that can be called. In this case, this is made up of the address to your NodeRed instance and the addition configured in the NodeRed code. So when calling the link

https://server.fritz.box:1880/http2mqttBridge.json?action=3dPrinterOff

the supplied parameter “action” can be read out.

A separate action can then be stored for the various values in the switch node shown on the left.

The value of the “action” parameter is determined by the character string after the “… action =” part.

You can find the NodeCode in the Nerdiy Git repository at:


More articles about NodeRed

Further articles on the topic of NodeRed including examples can be found under the following link.


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 *