Node-RED: Send Messages to WhatsApp

Learn how to send messages to your WhatsApp account with Node-RED. This can be a great addition to your Node-RED automation system. For example, to send notifications with sensor readings, alert messages when a sensor reading is above or below a certain threshold, when motion is detected, and many other applications. To send the messages we’ll use a free API called CallMeBot. The Free API is only for personal use.

Node-RED Send Messages to WhatsApp

Prerequisites

Before proceeding you need to have Node-RED installed. You can install Node-RED locally on your computer or on a Raspberry Pi, or on a cloud server. Check the following tutorials:

For a quick Node-RED getting started guide, take a look at the following tutorials:

Introducing WhatsApp

WhatsApp logo

“WhatsApp Messenger, or simply WhatsApp, is an internationally available American freeware, cross-platform centralized instant messaging and voice-over-IP service owned by Meta Platforms.” It allows you to send messages using your phone’s internet connection, so you can avoid SMS fees.

WhatsApp is free and is available for Android and iOS. Install WhatsApp on your smartphone if you don’t have it already.

CallMeBot WhatsApp API

To send messages to your WhatsApp account with Node-RED, we’ll use a free API service called CallMeBot service. You can learn more about CallMeBot at the following link:

Basically, it works as a gateway that allows you to send a message to yourself. This can be useful to send alert messages from Node-RED.

All the information about how to send messages using the API, can be found here.

Getting the CallMeBot API KEY

Before starting to use the API, you need to get the CallmeBot WhatsApp API key. Follow the next instructions (check this link for the instructions on the official website).

  1. Add the phone number +34 644 31 95 65 to your Phone Contacts. (Name it as you wish);
  2. Send the following message: “I allow callmebot to send me messages” to the new Contact created (using WhatsApp of course);
  3. Wait until you receive the message “API Activated for your phone number. Your APIKEY is XXXXXX” from the bot.
Get CallMeBot API key

Note: If you don’t receive the API key in 2 minutes, please try again after 24hs. The WhatsApp message from the bot will contain the API key needed to send messages using the API

Installing WhatsApp Nodes

There are different nodes you can install in Node-RED that make it easy to send messages to your WhatsApp account. As we’ve mentioned previously, we’ll use the nodes that use the CallmeBot service.

Go to Menu > Manage Palette > Install and search for node-red-contrib-whatsapp-cmb.

Node-RED install Whatsapp nodes

After installing, the WhatsApp node will show up on your palette.

Node-RED WhatsApp Node

Sending Messages to WhatsApp with Node-RED

Let’s create a basic example that shows how to send messages to WhatsApp using the node you’ve just installed.

Drag a Send Message WhatsApp node, an inject node, and a debug node to the flow. Wire them as follows:

Sending Messages to WhatsApp with Node-RED

If you check the WhatsApp node documentation, it says:

msg.text is used as the message you want to send. It must be a String. You can use it directly or with output from another node.”

We’ll set the message we want to send in msg.text in the inject node. Double-click on the inject node and edit its properties as follows (you can write any other message).

Node-RED inject node WhatsApp messages

Double-click on the Send Message node. Click on the pencil icon to add a new WhatsApp account. Give it a name, and insert your phone number (in international format), and the API key you received from the bot.

Node-RED edit WhatsApp Node

When you’re done, click on Update.

Then, change the Message field to msg.text.

Node-RED edit WhatsApp Node

Finally, click Done.

Testing the Flow

Deploy your application.

Node-RED deploy button

After deploying click on the left square on the inject node to trigger the WhatsApp sender node.

Node-RED trigger WhatsApp Flow

After a few seconds, you should receive a message in your WhatsApp account from the bot with the content you’ve set on the node:

Sending Messages to WhatsApp with Node-RED Testing Flow

That’s it! You learned an easy way to send messages to your WhatsApp using Node-RED and the callmebot API.

Wrapping Up

Now you know how to send messages to your WhatsApp account using Node-RED and the callmebot service. You can apply what you learned to your home automation system to send useful notification messages. The idea is to apply this feature in real-world scenarios.

If you want to learn how to send messages to WhatsApp using the ESP32 or ESP8266 boards, you can check the following tutorials:

To learn more about Node-RED and Home Automation, take a look at our dedicated eBook in the link below. Learn Node-RED and InfluxDB on a Raspberry Pi to build a Home Automation System with the ESP32 and ESP8266.

Thanks for reading.



Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »

Build Web Server projects with the ESP32 and ESP8266 boards to control outputs and monitor sensors remotely. Learn HTML, CSS, JavaScript and client-server communication protocols DOWNLOAD »


Enjoyed this project? Stay updated by subscribing our newsletter!

10 thoughts on “Node-RED: Send Messages to WhatsApp”

  1. Still unable to carry out your instructions
    I’m using raspberry pi inject node , is there a difference ?
    Noted in a you tube video that it appeared like yours.

    Reply
    • I’m sorry, but I don’t understand what is the issue.
      Can you show me a link to a printscreen of your inject node?
      Regards,
      Sara

      Reply
  2. I was able to obtain success by selecting “az” string in my Raspberry Pi inject node & leaving blank.
    In the Whats App node I again selected “az” string & a typed message.

    Reply

Leave a Comment

Download Our Free eBooks and Resources

Get instant access to our FREE eBooks, Resources, and Exclusive Electronics Projects by entering your email address below.