Enhancing your Home Assistant setup with the ability to send images and audio messages through WhatsApp can take your smart home notifications to the next level. Imagine receiving not just a text alert when the temperature in a room exceeds a certain threshold but also an accompanying graph that shows how the temperature has changed over time. This level of detail can help you better understand what’s happening in your home. This post is part 3 in a series on integrating WhatsApp into Home Assistant. If you haven’t yet installed the WhatsApp add-on or set up the integration, please refer to Part 1 and Part 2, where we covered the initial setup and how to send messages from Home Assistant to individual contacts and to groups.
There are a few important things to consider when sending images and audio messages through WhatsApp:
- HTTPS Requirement: The images and audio files must be stored on an HTTPS server, ensuring they are securely accessible from the internet.
- Audio File Format: While MP3 files are commonly used, WhatsApp works best with audio files in the Opus format. Unfortunately, popular hosting services like Jukehost, which were previously recommended for MP3 storage (for sending audio messages through Alexa devices), do not currently support hosting Opus files. You’ll need to find an alternative hosting solution yourself, such as GitHub, your own web hosting service, or another online platform that provides publicly available HTTPS links for your files.
Sending an Image via WhatsApp
To send an image through WhatsApp using Home Assistant, you can use the following YAML code. This will allow you to attach an image from an HTTPS source and send it along with a caption:
service: whatsapp.send_message
data:
clientId: default
to: [phone number]@s.whatsapp.net
body:
image:
url: "the url of png or jpg files stored publically and accessible over https"
caption: Simple text
Replace [phone number]
with the WhatsApp contact number, and make sure the image URL points to a publicly accessible PNG or JPG file hosted over HTTPS.
Sending an Audio Message via WhatsApp
If you want to send an audio message, the process is similar, but you’ll need to ensure the audio file is in the Opus format. Here’s how to do it:
service: whatsapp.send_message
data:
clientId: default
to: [phone number]@s.whatsapp.net
body:
audio:
url: "opus file address that's publically accessible over https"
ptt: true # Send audio as a voice
Again, replace the phone number and the audio URL with the correct values. The ptt: true
option will send the audio as a voice note (so you can see the sound “waves” like a real voice message).
If you already have audio files in MP3 or WAV format, one way to convert them to OPUS format is with this free online conversion service.
Exploring More Possibilities
While sending images can provide valuable visual context, the potential uses for sending audio are still open to exploration. If you have creative ideas for using audio messages in your smart home setup, please share them in the comments below. I’ll be experimenting with different possibilities and may include your suggestions in future updates to this guide.
Summary: In this post, we’ve covered how to send images and audio messages from Home Assistant to WhatsApp, enhancing your smart home notifications. By leveraging HTTPS-hosted files, you can send detailed alerts, such as temperature graphs or audio messages. Stay tuned for more tips in this series, and share your ideas for using audio in your setup!
Pingback: Integrating WhatsApp into Home Assistant – Part 4: Sending Stickers - Dr. Smart Home