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 have 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 switches the printer off automatically once the 3D print is complete.

The printer can also be switched on again in the same way. Initially, I used an appropriately configured button to do this. At some point, however, I came up with the idea that this switch-on command should also be possible with a mouse click.

Over time, this resulted in the flow below, which should also be usable for other actions. All you need to do is execute the batch file shown and the configured signal will be sent to your NodeRed instance, where you can then react to it.

You can find more information in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/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 make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other 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 tool:
-no-

Required material:

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


Log into the NodeRed configuration interface

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

View of the login dialog. Here you have to enter the login data that you specified during the configuration of the login. You can find information about this in the article NodeRed - set up user login.

Trigger action via batch file

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

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

After execution, the file for switching off first waits for a further confirmation. The command to switch off the 3D printer is only sent once this has been confirmed with a "Y". This prevents the 3D printer from being switched off unintentionally (e.g. during an ongoing printing process).

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

To do this, when the batch file is executed, the link

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

is called up. The value "3dPrinterOn" for the parameter "action" is transferred. This value is read in NodeRed and reacted to depending on it.

When the link is called up and the value "3dPrinterOn" the 3D printer is switched on.

The contents 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 a query. This means before the link

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

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

The parameter "action" the value "3dPrinterOff" is passed. Your NodeRed instance can read this value again and act accordingly. In this case, the 3D printer is switched off.

The contents 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 in it and then change the file extension of the text file from ".txt" to ".bat". You can then execute the batch file by double-clicking on it 🙂


The NodeRed code for further processing

To ensure that your NodeRed instance executes the received calls accordingly, 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. This means that when the link is called

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

the supplied "action" parameter 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 defined via the character string after the "...action=" part.

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


More articles about NodeRed

More articles about NodeRed including examples can be found at the following link.


Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS 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 think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.