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](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/Send-WhatsApp-Message-Node-RED.jpg?resize=828%2C466&quality=100&strip=all&ssl=1)
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:
- Install Node-RED on Raspberry Pi (works on RPI OS 64-bit)
- Access Node-RED Dashboard from Anywhere using Digital Ocean
For a quick Node-RED getting started guide, take a look at the following tutorials:
- Getting Started with Node-RED on Raspberry Pi
- Getting Started with Node-RED Dashboard on Raspberry Pi
Introducing WhatsApp
![WhatsApp logo](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/09/Whatsapp-logo.png?resize=200%2C200&quality=100&strip=all&ssl=1)
“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).
- 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.
- Send the following message: “I allow callmebot to send me messages” to the new Contact created (using WhatsApp of course);
- Wait until you receive the message “API Activated for your phone number. Your APIKEY is XXXXXX” from the bot.
![Get CallMeBot API key](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/09/Get-CallMeBot-API-Key.png?resize=350%2C458&quality=100&strip=all&ssl=1)
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](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/install-whatsapp-nodes-node-red.png?resize=711%2C295&quality=100&strip=all&ssl=1)
After installing, the WhatsApp node will show up on your palette.
![Node-RED WhatsApp Node](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/Node-RED-WhatsApp-Node.png?resize=147%2C111&quality=100&strip=all&ssl=1)
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](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/Node-RED-Send-Messages-WhatsApp-Flow.png?resize=617%2C53&quality=100&strip=all&ssl=1)
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](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/Node-RED-Inject-Node-WhatsApp-message.png?resize=571%2C267&quality=100&strip=all&ssl=1)
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](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/Node-RED-edit-WhatsApp-node.png?resize=537%2C342&quality=100&strip=all&ssl=1)
When you’re done, click on Update.
Then, change the Message field to msg.text.
![Node-RED edit WhatsApp Node](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/Node-RED-Edit-WhatsApp-Node-2.png?resize=512%2C317&quality=100&strip=all&ssl=1)
Finally, click Done.
Testing the Flow
Deploy your application.
![Node-RED deploy button](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/06/Node-RED-deploy-button.png?resize=136%2C35&quality=100&strip=all&ssl=1)
After deploying click on the left square on the inject node to trigger the WhatsApp sender node.
![Node-RED trigger WhatsApp Flow](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/Node-RED-trigger-WhatsApp-flow.png?resize=631%2C48&quality=100&strip=all&ssl=1)
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](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2022/11/WhatsApp-message-from-Node-RED-test.png?resize=450%2C169&quality=100&strip=all&ssl=1)
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.
My Inject node differs from yours.
Mine Payload
Topic
Yours Name
?
I’m sorry, but I didn’t understand your question…
When I open my inject node , properties..
Displays
Payload
Topic
Inject once after….
Repeat
Name
#######
Which is completely different from what is detailed in your inject node.
You need to edit the node so that it is displayed like mine.
Delete the “payload” and write “text”
Cannot see a way to delete the payload.
Just click with your mouse cursor and hit the backspace key.
INJECT NODE
msg.payload —> change to –> msg.text
whatapp NODE
Message Box change from STRING –> msg.text
click on a>z
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.
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
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.
I’m super following this tutorial and discussions.
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
with inject node everything is fine, but how to send a value from a senzor ? (mqtt in node)
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
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
Hi Folks!
Is it possible to send a picture with the bot and not just text messages? The whole thing best still in node red….
Hi.
Yes, it should be possible to send a picture, but I don’t have any example about it at the moment.
Regards,
Sara
No it`s not possible
I am following this information and discussion. Thanks for sharing!
Is FM WhatsApp safe to use?
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 ?
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.
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.
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.