Yes! Now OpenHAB can send WhatsApp Text Messages thanks to the CallMeBot Free API. You just need OpenHAB to execute a WGET or CURL command to send WhatsApp Messages. Find below the step-by-step instructions to implement it.

Setup:

You need to get the apikey form the bot before using the API:

  1. Add the phone number +34 644 56 55 18 into your Phone Contacts. (Name it it as you wish)
  2. Send this 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 123123" from the bot. As this is still in beta testing, the activation can take up to 2 minutes.
  4. The WhatsApp message from the bot will contain the apikey needed to send messages using the API.

You can send text messages using the API after receiving the confirmation.

Example:

How to send a WahtsApp message using the API:

You need to use the following URL:

https://api.callmebot.com/whatsapp.php?source=OpenHAB&phone=[phone]&apikey=[apikey]&text=[text]

Parameters:
[phone] is the destination phone number to send the message (For example: +34123123123)
[apikey] is the apikey that you received in the step 4 above
[text], is the message that you want to send. You can encode the URL (i.e. %20 istead of space, %0A for new lines) or use the symbol "+" for the spaces. WhatsApp formatting characters are allowed (i.e "*" for bold, etc.)

For example, to send the WhatsApp text message "Alarm from OpenHAB to inform you that the alarm has been triggered" to the phone number +34 123 123 123, the URL will be:

https://api.callmebot.com/whatsapp.php?source=HA&phone=+34123123123&apikey=987654&text=Alarm+from+OpenHAB+to+inform+you+that+the+alarm+has+been+triggered

And you can GET the URL with wget like this:

wget "https://api.callmebot.com/whatsapp.php?source=HA&phone=+34123123123&apikey=987654&text=Alarm+from+OpenHAB+to+inform+you+that+the+alarm+has+been+triggered"

To do that with OpenHAB is pretty easy! You have two (or more) different ways to do it:

Instructions (OPTION 1): Using the OpenHab HTTP Actions:

Use the sendHttpGetRequest action like this:

import java.net.URLEncoder
rule "Test WhatsApp Send Message"
when     
Item TestWhatsApp changed to ON
val urlmessage = URLEncoder::encode("This is a test from openHAB sending you a WhatsApp Message becaue something is happening in your house", 'UTF-8')
SendHttpGetRequest("https://api.callmebot.com/whatsapp.php?source=openHAB&phone=+34123123123&apikey=123123&text=" + urlmessage)
end
In this example, we are using the URLEncoder function to format properly the message passed in the URL. If no lang (language) parameter is set, then english is used by default.
 

 Instructions (OPTION 2): Using the OpenHab Exec Actions:

rule "Another WhatsApp Send Test"
when
    Item WhatsAppTest changed to ON
then
    var MessageWhatsApp = ("La alarma esta sonando en la cocina. Mirar las camaras por favor")

    MessageWhatsApp = MessageWhatsApp.replace(" ", "%20")
executeCommandLine ("wget https://api.callmebot.com/whatsapp.php?source=openHAB&phone=+34123123123&apikey=567567&text="+MessageWhatsApp)
 

In this example, I replaced the " " (spaces) by "%20" to encode the URL. And I used the wget shell command to execute the GET command needed by the API.

Custom Activation Message & Answer with common Apikey

If you need a custom activation message like "Please, send me reminders" (instead of the standard one) with a customized answer from the bot like "Got it! We will send you reminders by WhatsApp", please contact me at support@callmebot.com or via Telegram @callmebot_com. Your user's phones will be activated with the same Apikey that you can use to send messages from your software.
If needed, you can use your own WhatsApp account (phone number) to send the messages in order to get all the answers.

Problems?

If you have problems, like not receiving the Call on Telegram, or not receiving the WhatsApp messages,  try to test the CallMeBot API using your Web Browser:

  • Telegram Phone Calls using Web Browser: here
  • Telegram Text Messages using Web Browsers: here
  • WhatsApp Text Messages using Web Browser: here

You might get some errors on the screen that will help you to identify the problem. (Ex: Calls disabled in the Telegram Security Settings, WhatsApp not activated, etc.)

If you still have problems to use this API, don’t hesitate to contact me in Telegram @callmebot_com or by email at support@callmebot.com. Rember to Follow me on Twitter to get news about coming features, changes, invitations, etc.