Easily Send Home-Assistant Notifications using Whatsapp

So after long long search i finally made it.
using the new Twilio Whatsapp Sandbox and some modification in Twilio SMS component i was able to send notification from Home Assistant strait to my Whatsapp application without having to Tweak, Sniff or even to have another number.

one thing you need to be aware of at this moment:
Twilio whatsapp is still in beta so somtimes the messages will be delayd.

for convenience sake i wrote an article about it on my blog:
http://bit.ly/Ha-Whatsapp-notify

Cheers!

15 Likes

Can this send a WhatsApp message to a WhatsApp group? T

3 Likes

thanks alot for this @Tomer_Klein

how do I use it in my automations? do I have to include the target number everytime?

Awesome! Definitely going to have a look at this.

Sadly, this implementation doesn’t seem to work anymore. It shows promise, though I get a strange error from saying “Unable to create record: Twilio could not find a Channel with the specified From address” though it seems correctly configured.

This is of course with .88 custom_component style folder formatting i.e. “/config/custom_components/twilio_whatsapp/notify.py”

Just gotta try and get the wife to accept Telegram as a superior alternative.

Hi Tomer.

I’m also facing some problems, follwed the instructions, when I do config check before restart I get the following message.
" integration twilio_whatsapp not found when trying to verify its notify platform "

When I # the notify lines at the configuration. Yaml this message doest show anymore.

Any idea what i’m doing wrong?

same error " integration twilio_whatsapp not found when trying to verify its notify platform "

Works fine with me using the now component layout. Thanks for the excellent tutorial!

Hi all,
i have updated the tutorial to be compatible with with the new custom component layout.

1 Like

Thankyou!
I’ve been looking for something like this - will it send images and to multiple phones? And is it possible to reply to it and get it to run an automation?
I will try this tonight

1 Like

thanks,
works like a charm

works for me too, though I assume this will incur a charge once my free credit runs out? I can’t find a way to attach an image either. Would be really handy for sharing webcam motion snapshots if it did.

@Tomer_Klein I do need to resend the join collect-straight each day to receive messages.

Did you find a workaround for that?

Can anyone help me debug this error?

Error setting up platform twilio_whatsapp
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/notify/init.py”, line 73, in async_setup_platform
platform.get_service, hass, p_config, discovery_info
File “/usr/local/lib/python3.7/concurrent/futures/thread.py”, line 57, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/twilio_whatsapp/notify.py”, line 32, in get_service
hass.data[DATA_TWILIO], config[CONF_FROM_NUMBER])
KeyError: ‘twilio’

1 Like

I have the same problem

Try to edit notify.py and set your CONF_FROM_NUMBER = “+XXXXXXXXXXXX” phone number.

Nope. Still no go

Invalid config for [notify.twilio_whatsapp]: required key not provided @ data[‘whatsapp:+14155886’]. Got None. (See /config/configuration.yaml, line 83). Please check the docs at https://home-assistant.io/components/notify.twilio_whatsapp/

i’ve got the same message

2019-09-08 20:10:50 ERROR (MainThread) [homeassistant.components.notify] Error setting up platform twilio_whatsapp
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/notify/__init__.py", line 78, in async_setup_platform
    platform.get_service, hass, p_config, discovery_info
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/twilio_whatsapp/notify.py", line 32, in get_service
    hass.data[DATA_TWILIO], config[CONF_FROM_NUMBER])
KeyError: 'twilio'

but i’ve tried to tinker around the code, changed the const to the specific number
it seems some thing is not working with hass.data[DATA_TWILIO]

but again i maybe wrong

any one managed to solve this problem?

1 Like

2 questions:

  1. Is it possible to receive video or photo notification?
  2. How to send to multiple mobile phone numbers?

@saarsinai, @maraz, @dougbaptista
I got this working using this config

notify:
  - name: whatsapp
    platform: twilio_whatsapp
    from_number: whatsapp:+14155......
    account_sid: !secret twilio_account_sid
    auth_token: !secret twilio_auth_token

And using this notify.py file

"""
Twilio Whatsapp platform for notify component.

For more details about this platform, please refer to the documentation at
https://en.techblog.co.il/2019/01/24/easily-send-home-assistant-notifications-using-whatsapp/
"""
import logging

import voluptuous as vol

# from homeassistant.components.twilio import DATA_TWILIO
import homeassistant.helpers.config_validation as cv
from homeassistant.components.notify import (
    ATTR_TARGET, PLATFORM_SCHEMA, BaseNotificationService)

_LOGGER = logging.getLogger(__name__)
# DEPENDENCIES = ["twilio"]

CONF_FROM_NUMBER = "from_number"
CONF_ACCOUNT_SID = "account_sid"
CONF_AUTH_TOKEN = "auth_token"

DOMAIN = "twilio"
DATA_TWILIO = DOMAIN

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
    {
        vol.Required(CONF_FROM_NUMBER): vol.All(cv.string),
        vol.Required(CONF_ACCOUNT_SID): vol.All(cv.string),
        vol.Required(CONF_AUTH_TOKEN): vol.All(cv.string),
    }
)

def get_service(hass, config, discovery_info=None):
    """Get the Twilio Whatsapp notification service."""
    from twilio.rest import Client

    hass.data[DATA_TWILIO] = Client(
        config[CONF_ACCOUNT_SID], config[CONF_AUTH_TOKEN]
    )

    return TwilioWhatsappNotificationService(
        hass.data[DATA_TWILIO], config[CONF_FROM_NUMBER])


class TwilioWhatsappNotificationService(BaseNotificationService):
    """Implement the notification service for the Twilio Whatsapp service."""

    def __init__(self, twilio_client, from_number):
        """Initialize the service."""
        self.client = twilio_client
        self.from_number = from_number

    def send_message(self, message="", **kwargs):
        """Send Whatsapp to specified target user cell."""
        targets = kwargs.get(ATTR_TARGET)

        if not targets:
            _LOGGER.info("At least 1 target is required")
            return

        for target in targets:
            self.client.messages.create(
                to='whatsapp:'+target, body=message, from_=self.from_number)

This solves the error with hass.data[DATA_TWILIO].

I noticed however that after a few days (of not sending a message) I have to send the code again to the Twilio number before I can receive messages again.

3 Likes