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.
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.
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.
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
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.
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’
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]
"""
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.