πŸ€– Advanced Automations

The real power of the WhatsApp integration lies in the events. Every message received by the App is fired into Home Assistant as a whatsapp_message_received event.


πŸ“¨ Building a WhatsApp Bot

To react to commands, listen for the event and check the content field. You can create these automations directly in the Home Assistant UI.

Simple Command: /status

alias: 'WhatsApp Bot: Status'
trigger:
  - platform: event
    event_type: whatsapp_message_received
condition:
  - condition: template
    value_template: "{{ trigger.event.data.content | lower == '/status' }}"
action:
  - service: whatsapp.send_message
    data:
      target: '{{ trigger.event.data.sender }}'
      message: |
        The server is online! πŸš€
        Uptime: {{ states('sensor.whatsapp_uptime') }}

Complex Command: /light [on|off]

Using regex or simple β€œin” checks to handle parameters.

alias: 'WhatsApp Bot: Light Switch'
trigger:
  - platform: event
    event_type: whatsapp_message_received
condition:
  - condition: template
    value_template: "{{ trigger.event.data.content | lower | startswith('/light') }}"
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ 'on' in trigger.event.data.content | lower }}"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.living_room
      - conditions:
          - condition: template
            value_template: "{{ 'off' in trigger.event.data.content | lower }}"
        sequence:
          - service: light.turn_off
            target:
              entity_id: light.living_room

🎭 Group Interactions

Automating group chats requires checking if the message came from a group.

Auto-Emoji Reaction

React with a specific emoji if a keyword is mentioned in a group.

alias: 'WhatsApp Bot: Beer Keyword'
trigger:
  - platform: event
    event_type: whatsapp_message_received
condition:
  - condition: template
    value_template: >
      {{ 'beer' in trigger.event.data.content | lower or
         'cheers' in trigger.event.data.content | lower or
         'bier' in trigger.event.data.content | lower }}
action:
  - service: whatsapp.send_reaction
    data:
      target: '{{ trigger.event.data.sender }}'
      message_id: '{{ trigger.event.data.raw.key.id }}'
      reaction: '🍺'

πŸ“Έ Security: Camera Snapshots

Send an image when motion is detected.

alias: 'WhatsApp: Motion Security'
trigger:
  - platform: state
    entity_id: binary_sensor.front_door_motion
    to: 'on'
action:
  - service: camera.snapshot
    data:
      filename: '/config/www/tmp/snapshot.jpg'
    target:
      entity_id: camera.front_door
  - delay: '00:00:02'
  - service: whatsapp.send_image
    data:
      target: '49123456789'
      message: 'Movement at the door! πŸ“·'
      url: 'https://your-domain.com/local/tmp/snapshot.jpg'
      expiration: 86400 # Auto-delete camera snapshot from chat after 24h

πŸ“§ Useful Real-Life Examples

Forward Emails (IMAP) to WhatsApp

Useful for urgent training inquiries or important work emails.

id: 'volleyball_new_training_inquiry_mail'
alias: 'Volleyball Training: Forward New Email to WhatsApp'
description: 'Sends a WhatsApp message on new training inquiry via IMAP.'
mode: single
trigger:
  - platform: event
    event_type: imap_content
condition:
  # Filter for a specific mailbox user
  - condition: template
    value_template: >
      {{ trigger.event.data['username'] | lower | trim == 'your-mail@gmail.com' }}
action:
  - service: whatsapp.send_message
    continue_on_error: true
    data:
      target: '49171234567'
      message: |
        🏐 *Neue Trainingsanfrage*

        πŸ“… *Datum:* {{ as_timestamp(trigger.event.data['date'])
                         | timestamp_custom('%d.%m.%Y %H:%M') }}
        πŸ‘€ *Von:* {{ trigger.event.data['sender'] }}
        πŸ“ *Betreff:* {{ trigger.event.data['subject'] }}

        --------------------------------

        {{ trigger.event.data['text']
             | default(trigger.event.data['body'])
             | default('No content')
             | truncate(800) }}

Appliances: Washer/Dryer Notifications

Get a WhatsApp when your laundry is done.

alias: 'WhatsApp: Laundry Notification'
trigger:
  - platform: state
    entity_id: binary_sensor.washer_running
    from: 'on'
    to: 'off'
action:
  - service: whatsapp.send_message
    data:
      target: '1203630234567@g.us' # Send to a family group
      message: |
        🧺 *WÀsche ist fertig!*
        Bitte die Waschmaschine leeren und in den Trockner rΓ€umen.

System: Low Battery Alert

Get a list of all devices with low battery.

alias: 'WhatsApp: Low Battery Alert'
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.living_room_temp_battery
      - sensor.kitchen_motion_battery
    below: 20
action:
  - service: whatsapp.send_message
    data:
      target: '49171234567'
      message: |
        πŸͺ« *Batterie schwach!*
        Das GerΓ€t *{{ friendly_name(trigger.entity_id) }}*
        hat nur noch {{ state(trigger.entity_id) }}%.

Image Access: The App needs to be able to download the image from the URL you provided. If using localhost URLs, ensure the App has network access to the Home Assistant instance.


Maintained by FaserF. This project is not affiliated with WhatsApp Inc.

This site uses Just the Docs, a documentation theme for Jekyll.