mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-21 08:16:53 +00:00
Make examples section
This commit is contained in:
parent
8cbb2924ea
commit
7a056ff288
@ -14,7 +14,7 @@ ha_iot_class: depends
|
|||||||
|
|
||||||
The MQTT notification support is different than the other [notification](/components/notify/) 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.
|
The MQTT notification support is different than the other [notification](/components/notify/) 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 **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**.
|
**Call Service** section from the <img src='/images/screenshots/developer-tool-services-icon.png' alt='service developer tool icon' class="no-shadow" height="38" /> **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**.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"payload": "Test message from HA", "topic": "home/notification", "qos": 0, "retain": 0}
|
{"payload": "Test message from HA", "topic": "home/notification", "qos": 0, "retain": 0}
|
||||||
@ -30,6 +30,11 @@ The same will work for automations.
|
|||||||
<img src='/images/screenshots/mqtt-notify-action.png' />
|
<img src='/images/screenshots/mqtt-notify-action.png' />
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
## {% linkable_title Examples %}
|
||||||
|
|
||||||
|
### {% linkable_title REST API %}
|
||||||
|
|
||||||
Using the [REST API](https://developers.home-assistant.io/docs/en/external_api_rest.html) to send a message to a given topic.
|
Using the [REST API](https://developers.home-assistant.io/docs/en/external_api_rest.html) to send a message to a given topic.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -39,3 +44,31 @@ $ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \
|
|||||||
http://IP_ADDRESS:8123/api/services/mqtt/publish
|
http://IP_ADDRESS:8123/api/services/mqtt/publish
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### {% linkable_title Automations %}
|
||||||
|
|
||||||
|
Use as [`script`](/components/script/) in automations.
|
||||||
|
|
||||||
|
{% raw %}
|
||||||
|
```yaml
|
||||||
|
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 %}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user