HowTo: Node Red - Control GPIO of an ESPEasy device

EspEasy and Node Red each offer a number of options for automation.

You get even more options if you combine both systems. In the article ESPEasy - Execute commands and actions via HTTP , MQTT and UDP I have already described in general how to send certain commands to an ESPEasy device from Node Red.

This example describes how you can use this, for example to activate or deactivate a specific GPIO of the ESPEasy device.


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 stores listed here are so-called affiliate links. If you click on such an affiliate link and store via this link, Nerdiy.de receives a commission from the online store 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:
How to prepare a RaspberryPi and then install NodeRed on it is described in the following articles.

Required tools:
-none-

Materials needed:

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


Import Node Red code

In this section you will find the Node Red code you need. How you can import this into your NodeRed environment is described in the article NodeRed - Import and export Node code.

In order to be able to use the node code linked below with your ESPEasy device, you have to make a few changes. These are described in the next section.

You can find the Node Red code in the Nerdiy Git repository under the following link:

View of the Node Red Flow in the configuration interface.


Configure ESPEasy device

So that you can send commands to your ESPEasy device via MQTT, it must of course be configured appropriately. To do this, you must first set the "Unit Name" of your ESPEasy device appropriately.

Open the web configuration view, switch to the "Config" tab and configure the name of your ESPEasy device. You should make a note of the name you set, because you will need it later.

View of the "Config" tab in the web menu of your ESPEasy device.


Configure MQTT servers

The next step is to configure the MQTT server on your ESPEasy device.

Open the web menu of your ESPEasy device and open the "Controllers" tab. There you should set the MQTT server as shown below. In addition to the "Controller Hostname", the "Controller Subscribe" topic is also important.

You can find more information about this in the article ESPEasy - Configure MQTT server and subscribe to topics.

View of the MQTT controller setting in the web menu of your ESPEasy device.


GPIO on and off

You can use this part of the Node Red code if you just want to turn the GPIO on and off.

View of the Node Red Flow in the configuration interface.

In order for the NodeRed code to work with your ESPEasy device, you must configure both the desired GPIO and the name of your ESPEasy device.

To do this, replace the 12 in the area marked in red with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.


Toggle GPIO state

You can use this part of the Node Red code if you want to switch the GPIO with one command.

View of the Node Red Flow in the configuration interface.

In order for the NodeRed code to work with your ESPEasy device, you must configure both the desired GPIO and the name of your ESPEasy device.

To do this, replace the 12 in the area marked in red with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.


Switch longer pulse (1 to 999 seconds) to GPIO

You can use this part of the Node Red code if you want to output a pulse with a pulse duration of 1 to 999 seconds on the GPIO.

View of the Node Red Flow in the configuration interface.

In order for the NodeRed code to work with your ESPEasy device, you must configure both the desired GPIO and the name of your ESPEasy device.

To do this, replace the 12 in the area marked in red with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.

By adjusting the "pulse_duration" value at this point, you can adjust the length of the pulse duration.


Switch longer pulse (10 to 15000 milliseconds) to GPIO

You can use this part of the Node Red code if you want to output a pulse with a pulse duration of 10 to 15000 milliseconds on the GPIO.

View of the Node Red Flow in the configuration interface.

In order for the NodeRed code to work with your ESPEasy device, you must configure both the desired GPIO and the name of your ESPEasy device.

To do this, replace the 12 in the area marked in red with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.

By adjusting the "pulse_duration" value at this point, you can adjust the length of the pulse duration.


Switch short pulse (1 to 1000 milliseconds) to GPIO

You can use this part of the Node Red code if you want to output a pulse with a pulse duration of 1 to 1000 milliseconds on the GPIO.

View of the Node Red Flow in the configuration interface.

In order for the NodeRed code to work with your ESPEasy device, you must configure both the desired GPIO and the name of your ESPEasy device.

To do this, replace the 12 in the area marked in red with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.

By adjusting the "pulse_duration" value at this point, you can adjust the length of the pulse duration.


View of status changes in the weblog

You can also check the status change or the successful execution of the command with the weblog of your ESPEasy device. To do this, open the web view of your ESPEasy device under "Tools" and "Log".

In the opened view you can then see all executed commands. In this case the GPIO commands.

View of the weblog of an ESPEasy device.


More articles about NodeRed and ESPEasy

In the following categories you will find further links on the subject of NodeRed and ESPEasy.


Have fun with the project

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. 🙂

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 that I share this information with you, I would be happy about a small donation to the coffee box. 🙂

Buy Me a Coffee at ko-fi.com   

Kommentar hinterlassen

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