Node RED is a Flow based programming interface that is somewhere between block and text based coding. It can be an easy way to program automations for Home Assistant that are a bit more advanced than what can be done with the Automations menu.
From the Hass.io ADD-ON STORE, scroll down to find Node-Red and click on it.
- Click the INSTALL link.
- Once Installed, scroll down to the Config section.
- Set a credential_secret, which is used to encrypt sensitive data. This is just a password, which you should save in a secondary location.
- Next set ssl and require_ssl to false.
- Note: SSL can be added, more information in the documentation.
- Click the SAVE link
- Now scroll up and click the START link.
- This can take a few moments to start up, but you can check the log at the bottom of the page to see when Node-RED is up and running.
- If desired, turn on the Show in sidebar
- Once finished, you can now click on the OPEN WEB UI link or the Node-RED menu link to open Node-RED.
Since we have already installed the MQTT Broker we may as well set up Node-RED to use that for sending and receiving data from connected devices right?
Scroll down to find the mqtt node under input or output.
Move the mqtt node to Flow 1
Double click on the mqtt node to open it's Properties window.
Under the Connection tab, add your MQTT Server address.
This will be the same IP address as your Raspberry Pi unless you are using another MQTT server like Adafruit.IO
Next click the Security tab.
Add the Username and Password that you set for your MQTT server.
Now click Add
That will add your connection and your can now set a topic to interact with. As a test, I will usually add and inject node to send a time stamp to the mqtt node under output with a Topic of "test". Then I will get another mqtt node from the input section, set it's Topic to "test" and connect it to a debug output.
When you click the tab next to the timestamp inject node it will send the Unix time to the topic "test" via MQTT. Once that happens, the mqtt node set as input will receive that update and send it to be printed in the debug log.