Skip to content

Commit b4a3ce6

Browse files
committed
doc: add more automation examples
1 parent 1b6ae43 commit b4a3ce6

1 file changed

Lines changed: 95 additions & 11 deletions

File tree

README.md

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ Even though integration is classified as `local_polling` it predominantly operat
5959
as soon as new state is available. Polling is only used as fallback should the push mechanism stop working.
6060

6161
### [Notification](https://www.home-assistant.io/integrations/notify/)
62-
All nodes from the gateway's node database are available as notification targets.
63-
Channels are available as targets as well.
64-
65-
Use this method as preferred way to send messages when you don't need control over the details
62+
Using notification platform and the generated `notify.mesh_*` entities is the recommended way to send messages to the mesh when you don't need control over all the details
6663
(which gateway to use, acknowledgements, etc.)
6764

65+
Depending on your needs, all nodes from the gateway's node database as well as the channels can be made available as notification targets.
66+
67+
6868
Note: Support is based on new [entity notification platform](https://developers.home-assistant.io/blog/2024/04/10/new-notify-entity-platform/),
6969
for an example on how to use it, see [official documentation](https://www.home-assistant.io/integrations/notify/#example-with-the-entity-platform-notify-action).
7070

@@ -90,9 +90,9 @@ it is still busy with receiving / sending other mesh messages.
9090

9191
#### Examples
9292
<details>
93-
<summary>Reply back after message received from device on arbitrary channel (including direct message) </summary>
93+
<summary>Reply back after message received from predefined device on arbitrary channel (including direct message) </summary>
9494

95-
```
95+
```yaml
9696
- id: '1800000042000'
9797
alias: Ping Sample
9898
description: 'Reply back after message from device'
@@ -111,10 +111,89 @@ it is still busy with receiving / sending other mesh messages.
111111
```
112112
113113
</details>
114+
114115
<details>
115-
<summary>Handling incoming text messages from any node</summary>
116+
<summary>Echo incoming channel text messages from any node with gateway device trigger</summary>
117+
118+
```yaml
119+
- id: '1735857524502'
120+
alias: Echo Channel Message
121+
description: ''
122+
triggers:
123+
- domain: meshtastic
124+
device_id: 16efde6990a6a09903153abb8624fe38
125+
type: channel_message.received
126+
entity_id: meshtastic.gateway_brig_channel_primary
127+
trigger: device
128+
conditions: []
129+
actions:
130+
- delay:
131+
seconds: 5
132+
- action: meshtastic.broadcast_channel_message
133+
metadata: {}
134+
data:
135+
ack: true
136+
channel: meshtastic.gateway_brig_channel_primary
137+
message: 'ECHO: {{ trigger.event.data.message }}'
138+
mode: single
139+
```
140+
</details>
141+
142+
<details>
143+
<summary>Advanced: Handling incoming text messages from any node without notification platform and its entities</summary>
144+
145+
```yaml
146+
- id: '1735852176270'
147+
alias: Echo on Channel Message (without Notify Platform)
148+
description: 'Only from gateway with node id 3771721320'
149+
triggers:
150+
- trigger: event
151+
event_type: meshtastic_api_text_message
152+
event_data:
153+
data:
154+
to:
155+
node:
156+
channel: 1
157+
gateway: 3771721320
158+
conditions: []
159+
actions:
160+
- delay:
161+
seconds: 5
162+
- action: meshtastic.send_text
163+
data:
164+
ack: true
165+
text: 'ECHO: {{ trigger.event.data.data.message }}'
166+
from: '{{ trigger.event.data.data.gateway }}'
167+
channel: '{{ trigger.event.data.data.to.channel }}'
168+
mode: single
169+
- id: '1735852176271'
170+
alias: Echo on Direct Message (without Notify Platform)
171+
description: 'Only from gateway with node id 3771721320'
172+
triggers:
173+
- trigger: event
174+
event_type: meshtastic_api_text_message
175+
event_data:
176+
data:
177+
to:
178+
node: 3771721320
179+
channel:
180+
gateway: 3771721320
181+
conditions: []
182+
actions:
183+
- delay:
184+
seconds: 5
185+
- action: meshtastic.send_text
186+
data:
187+
ack: true
188+
text: 'ECHO: {{ trigger.event.data.data.message }}'
189+
from: '{{ trigger.event.data.data.gateway }}'
190+
to: '{{ trigger.event.data.data.from }}'
191+
mode: single
192+
```
116193
117-
This integration supports the creation of Home Assistant automations that can handle incoming text messages from any public node and replay to these messages. This is useful if to want to reply to incoming direct messages with a standard message, use a LLM or handle various commands with automations.
194+
If you don't want to use the recommend notification platform for sending messages (e.g. if you don't want to clutter your Home Assistant instance with potentially hundreds of notify mesh entities),
195+
you can still handle incoming text messages from any public node and reply to these messages.
196+
This is useful if to want to reply to incoming direct messages with a standard message, use a LLM or handle various commands with automations.
118197
119198
To do this, create a new Home Assistant automation that triggers on "Manual Events" and put `meshtastic_api_text_message` as the "Event Type". This will cause this automation to get triggerred on all incoming channel and direct messages. You will get events that include this information:
120199

@@ -128,10 +207,15 @@ trigger:
128207
to:
129208
node: null
130209
channel: 0
210+
gateway: 862525748
131211
message: Sample Message
132212
```
133213

134-
From is the NodeID of the sender of the message, to will have a node value if direct, or a channel number if the message is directed at the channel. You can create conditions in the automation to filter out the incoming messages you want, for example to filter out messages addressed to your node, use this condition with your nodeid.
214+
From contains the node id of the sender of the message, to will have the node id of the gateway for direct messages, or a gateway channel id if the message is directed at the channel.
215+
Note that the channel id is dependent on the gateway node, so make sure you are using the proper gateway node when replying using that channel id.
216+
217+
You can create conditions in the automation to filter out the incoming messages you want or you can directly filter in the trigger.
218+
For example to filter out messages addressed to your gateway node, use this condition with your node id.
135219

136220
```
137221
{{ trigger.event.data.data.to.node == 862525748 }}
@@ -149,15 +233,15 @@ You can also forward these messages as notifications to your phone, etc. For exa
149233
Meshtastic message from ({{ trigger.event.data.data.from }}): {{ trigger.event.data.data.message }}
150234
```
151235
152-
To reply to a text message in this situation, add a 2 second or more delay action and then an action called `Meshtastic 'Send Text'` to your automation. You need to add a short delay to make sure your Meshtastic device is idle before replying. Change the `Meshtastic 'Send Text'` action to edit in yaml and change the `to`, `from` and `text` values to somethign like his:
236+
To reply to a text message in this situation, add a 2 second or more delay action and then an action called `Meshtastic 'Send Text'` to your automation. You need to add a short delay to make sure your Meshtastic device is idle before replying. Change the `Meshtastic 'Send Text'` action to edit in yaml and change the `to`, `from` and `text` values to something like his:
153237
154238
```
155239
action: meshtastic.send_text
156240
metadata: {}
157241
data:
158242
ack: false
243+
from: "{{ trigger.event.data.data.gateway }}"
159244
to: "{{ trigger.event.data.data.from }}"
160-
from: "{{ trigger.event.data.data.to.node }}"
161245
text: "ECHO: {{ trigger.event.data.data.message }}"
162246
```
163247

0 commit comments

Comments
 (0)