home-assistant.io/source/_cookbook/notify.mqtt.markdown
Franck Nijhof ebca3218c7
🔥Removes linkable_title everywhere (#9772)
* Automatically create linkable headers

* Visually improve position of linkable header chain icon

* Do not auto link  headers on homepage

* Remove linkable_title everywhere

* 🚑 Re-instante linkable_title plugin as NOOP
2019-07-04 19:08:27 +02:00

2.1 KiB

layout, title, description, date, sidebar, comments, sharing, footer, logo, ha_category, ha_iot_class, redirect_from
layout title description date sidebar comments sharing footer logo ha_category ha_iot_class redirect_from
page MQTT Notifications Instructions on how to add MQTT notifications to Home Assistant. 2016-02-01 08:00 true false true true mqtt.png Notifications Configurable /components/notify.mqtt/

The MQTT notification support is different than the other notification platforms. It is a service. This means that you don't have to create a configuration entry but you need to provide more details when calling the service.

Call Service section from the service developer tool icon Developer Tools allows you to send MQTT messages. Choose mqtt.publish from the list of Available services: and enter something like the sample below into the Service Data field and hit CALL SERVICE.

{"payload": "Test message from HA", "topic": "home/notification", "qos": 0, "retain": 0}

The same will work for automations.

Examples

REST API

Using the REST API to send a message to a given topic.

$ curl -X POST \
    -H "Authorization: Bearer ABCDEFGH" \
    -H "Content-Type: application/json" \
    -d '{"payload": "Test message from HA", "topic": "home/notification"}' \
    http://IP_ADDRESS:8123/api/services/mqtt/publish

Automations

Use as script in automations.

{% raw %}

automation:
  alias: Send me a message when I get home
  trigger:
    platform: state
    entity_id: device_tracker.me
    to: 'home'
  action:
    service: script.notify_mqtt
    data:
      target: "me"
      message: "I'm home"

script:
  notify_mqtt:
    sequence:
      - service: mqtt.publish
        data_template:
          payload: "{{ message }}"
          topic: home/"{{ target }}"
          retain: true

{% endraw %}