Whatsapp bot sending notifications from Home Assistant

Integrating WhatsApp into Home Assistant – Part 1: Setup and Notifications

Integrating WhatsApp into your Home Assistant setup opens up new possibilities for smart home automation. It allows you to receive important notifications and even interact with your smart home devices directly from a WhatsApp chat. This blog post will guide you through the first steps: setting up the WhatsApp add-on in Home Assistant, pairing it with a secondary WhatsApp account, and sending your first notification.

The following method described in this and future posts in the series involves installing a specific Add-On in Home Assistant. Please note that Add-Ons can only be installed if you are using Home Assistant OS. This is the installation method I recommend, whether you’re setting it up on a Raspberry Pi or as a VM on a NAS such as Unraid.

What can you achieve by integrating WhatsApp?

Integrating WhatsApp into Home Assistant can enhance your smart home by adding a “virtual assistant” that serves two main purposes:

  1. Notifications: You can send alerts, reminders, and updates directly to WhatsApp. For example, you can get a morning briefing based on your calendar, a weather report when you’re about to leave, or a notification when the washing machine is done.
  2. Commands and Queries: Following these tutorials, you will be able to control your smart home directly from WhatsApp. For instance, you can ask the WhatsApp “assistant” to turn off the lights or check how much time is left for a washing machine cycle—all through a simple chat interface.

Why You Need a Secondary WhatsApp Account

Before we dive into the setup, it’s essential to understand why a secondary WhatsApp account is required. If you use your primary WhatsApp account, messages sent by Home Assistant will not trigger notifications on your phone. This happens because WhatsApp sees these messages as if they were sent by you, and it won’t notify you of messages you’ve “sent.” By creating a secondary account with a different phone number, you ensure that Home Assistant can send you notifications and interact with your smart home independently.

Setting Up a Secondary WhatsApp Account

To create a secondary WhatsApp account, you’ll need an additional phone number. The easiest way to do this is by using a mobile application like TextNow, which provides a free phone number that you can use for this purpose.

  1. Create a Secondary WhatsApp Account:
    • If you’re using an Android device, go to Settings -> Apps -> App Cloner and clone the WhatsApp app. This will allow you to have two separate WhatsApp instances on the same device.
    • Alternatively, use an old phone you may have, install WhatsApp, and register it with the phone number you obtained from TextNow.
    • When registering, opt for the “Call me” option instead of SMS to receive the verification code, which will be sent to the TextNow app (Receiving SMS verification is a paid feature of TextNow and while I encourage to support developers, the option “Call Me” is easy and free).
  2. Set Up the Contact:
    • On your primary phone, save the new WhatsApp number as a contact. You might name it something like “AI Home Assistant” and give it a distinct avatar.

Installing the WhatsApp Add-On in Home Assistant

Now that your secondary WhatsApp account is ready, it’s time to install the WhatsApp add-on in Home Assistant.

  1. Install the WhatsApp Add-On:
    • Navigate to Settings -> Add-ons -> Add-on Store in Home Assistant.
    • Open the Hamburger menu (top-right corner) and select Repositories.
    • Add the following repository: https://github.com/giuseppecastaldo/ha-addons.
    • After refreshing the page, search for “WhatsApp” in the add-on store and install it.
  2. Integrate WhatsApp with Home Assistant:
    • Open the File Editor in Home Assistant and edit the configuration.yaml file.
    • Add the following line at the very end of the file: whatsapp: (notice the “:” symbol at the end).
    • Save the changes and restart Home Assistant.
  3. Pairing WhatsApp with Home Assistant:
    • After restarting, you’ll receive a notification in Home Assistant containing a QR code.
    • Open WhatsApp on your secondary account (either on the cloned app or the second device).
    • Go to Menu -> Linked Devices -> Link a Device in that WhatsApp account and scan the QR code displayed in the Home Assistant notification. This will link your WhatsApp account to Home Assistant.

Sending Your First WhatsApp Notification

With everything set up, you can now create a simple automation in Home Assistant to send notifications via WhatsApp. Here’s a basic example:

alias: Send notification
data:
  clientId: default
  to: [phonenumber]@s.whatsapp.net
  body:
    text: |
      Dryer is done, don't forget to take the clothes out.
enabled: true
action: whatsapp.send_message

Replace [phonenumber] with your full phone number, including the country code, digits only (e.g., 405009725555 for a Romanian number with country prefix +40). This automation will send a notification when triggered.

Conclusion

In this first part of our series on integrating WhatsApp with Home Assistant, we covered the setup of the WhatsApp add-on, pairing it with a secondary account, and sending a basic notification. In the next part, we’ll explore how to send notifications to a group, such as a family chat, making your smart home even more interactive and accessible. Stay tuned for more!


Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply