HowTo: Node Red - Controlling GPIO of an ESPEasy device

EspEasy and Node Red each offer some automation capabilities in their own right.

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

This example describes how you can use this to enable or disable a specific GPIO of the ESPEasy device for example.


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:
To be able to install new nodes, NodeRed should of course already be installed on your RaspberryPi.
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.


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 in the article NodeRed - import and export node code described.

To use the node code linked below with your ESPEasy device, you need to make a few changes. These are described in the next section.

You can find the Node Red code in the Nerdiy Git repository at 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.

To do this, open the web configuration view, switch to the "Config" tab and configure the name of your ESPEasy device. You should remember the name you have set, as you will need it later.

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


Configure MQTT Server

In the next step you should configure the MQTT server on your ESPEasy device.

To do this, 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 also find more information 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.


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

For the NodeRed code to work with your ESPEasy device you need to configure both the desired GPIO and the name of your ESPEasy device.

Replace the 12 in the red marked area 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 a command.

View of the Node Red Flow in the configuration interface.

For the NodeRed code to work with your ESPEasy device you need to configure both the desired GPIO and the name of your ESPEasy device.

Replace the 12 in the red marked area 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 duration of 1 to 999 seconds on the GPIO.

View of the Node Red Flow in the configuration interface.

For the NodeRed code to work with your ESPEasy device you need to configure both the desired GPIO and the name of your ESPEasy device.

Replace the 12 in the red marked area with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.

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


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 duration of 10 to 15000 milliseconds on the GPIO.

View of the Node Red Flow in the configuration interface.

For the NodeRed code to work with your ESPEasy device you need to configure both the desired GPIO and the name of your ESPEasy device.

Replace the 12 in the red marked area with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.

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


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 duration of 1 to 1000 milliseconds on the GPIO.

View of the Node Red Flow in the configuration interface.

For the NodeRed code to work with your ESPEasy device you need to configure both the desired GPIO and the name of your ESPEasy device.

Replace the 12 in the red marked area with your desired GPIO and ESPEasy_GPIO with the name of your ESPEasy device.

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


View of the state changes in the weblog

You can also check the status change or the successful execution of the command with the web log 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 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 more links about NodeRed and ESPEasy.


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.