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 621 331 709 to your Phone Contacts. (Name it as you wish) — please double-check the number on the CallMeBot website, because it sometimes changes.
  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.



Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »
Learn how to build a home automation system and we’ll cover the following main subjects: Node-RED, Node-RED Dashboard, Raspberry Pi, ESP32, ESP8266, MQTT, and InfluxDB database DOWNLOAD »

Enjoyed this project? Stay updated by subscribing our newsletter!

25 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
  3. Very interesting and helpful tutorial but here’s an interesting thing which I discovered when attempting to debug a signal sent to a control switch.
    Inject “1” and it all works. Inject “0” and although the output says it has been sent it is never received! Still trying to figure out where that goes awry

    Reply
  4. Fine,
    ypu done a great job as usually !
    It work perfectly but like go over, i need to change phone number (and obviously API Keys) from the user interface, it’s possibile ?
    thank

    Reply
  5. Hello, i tried to use your api for using in nodered. I did everything like in the step by step advice, received a apikey and put it in the node in nodeRED but as soon as i deploy i receive the following error:
    Cannot find module aws4
    Require stack:
    -…..

    Does somebody had the same issue?
    Kind regards

    Reply
  6. hi
    thanks for above tutorial.
    but I want to send whatsapp messages to diffrent phone numbers not to me only.
    How can I do that ?

    Reply
  7. using node-red-contrib-whatsapp-cmb works amazing,
    BUT I need to trigger the message with a GPIO instead of using the inject msg.text
    is it possible? the inject doesn’t have a input side.
    Is there a node that can activate the inject or a different method?

    using node-red-contrib-whatsapp-link bricks my Pi, then i have to start over with a nodered installaion. that on both options of whatsapp lite and web.

    Reply
  8. using node-red-contrib-whatsapp-cmb works amazing,
    BUT I need to trigger the message with a GPIO instead of using the inject msg.text
    is it possible? the inject doesn’t have a input side.
    Is there a node that can activate the inject or a different method

    using node-red-contrib-whatsapp-link bricks my Pi, then i have to start over with a nodered installaion. that on both options of whatsapp lite and web.

    Reply
    • Hi,
      I am guessing you would use the ‘rp-gpio in’ node (from the Raspberry Pi group of nodes in the left sidebar), this lets the state of a GPIO pin (0 or 1) trigger the flow.

      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.