How do I use a specific message on a specific channel to activate a trigger? I can’t figure it out
Because of the structure of the event data, and how Event triggers work, you don’t specify the channel and message in the trigger. You use a generic trigger using the meshtastic_api_text_message Event. Then use Template conditions to check the data you are interested in.
The channel ID number can be retrieved from the trigger variable with trigger.event.data.data.to.channel and the message with trigger.event.data.data.message:
triggers:
- trigger: event
event_type: meshtastic_api_text_message
conditions:
- alias: "Check Channel ID is 1"
condition: template
value_template: "{{trigger.event.data.data.to.channel == 1}}"
- alias: "Check Message is my secret code"
condition: template
value_template: "{{trigger.event.data.data.message == 'My Secret Code'}}"
actions:
#Your actions
Edit: Fixed issue with Channel ID. It should be an integer, not a string
Idk why it didn’t work but I guess it was false somehow
alias: Check Channel ID is 1
condition: template
value_template: ‘{{trigger.event.data.data.to.channel == ‘‘1’’}}’
This worked
{{trigger.event.data.data.message == ‘/newsl’}}
I just used “1” as an example, did you check that “1” is correct for the channel as it’s defined on your device? Check the “Changed variables” tab to see what the actual channel for that message was.
How do I do that
In the trace (where you took that screenshot) at the bottom there is a tabbed section that is currently showing “Step config” (as shown by the blue underline. Click on “Changed variables”.
Then scroll down to find “channel”. Here’s an example from a message I received earlier:
It’s empty
How do I see what the channel is called
You need to click on the trigger in the trace map… that’s the circle at the top with the asterisk-looking thing in it. Then select “Changed variables”.
1773669521199 is that it?
Oh wait no it’s 0
That message came in on channel 0. It comes in as a string, so make sure you keep it in quotes (like I had it in my example) in the template.
I tried with regular quotes and work the single quotes. Doesn’t work just says false. Idek
Try it without the quotes around 0. The trace doesn’t show it as quoted, so I may be mis-remembering something I did with mine…
EDIT:
Just tested, it should be 0 not “0”. ![]()
Here’s an example I’ve been playing with… piping select messages from meshtastic into Assist:
alias: Meshtastic Assist
description: "Process messages from Meshtastic through Assist"
triggers:
- trigger: event
event_type: meshtastic_api_text_message
variables:
message: "{{trigger.event.data.data.message | default('No Message', 1)}}"
node_id: "{{trigger.event.data.data.from }}"
allowed_channels:
- 1
allowed_nodes:
"123456789": Mobile Node 1
"987654321": Mobile Node 2
conditions:
- alias: Check for allowed Channel or To Node
condition: template
value_template: |-
{% if trigger.event.data.data.to.channel == none %}
{{ trigger.event.data.data.to.node|string == '12344321' }}
{% else %}
{{ trigger.event.data.data.to.channel | int in allowed_channels }}
{% endif %}
- alias: Check that source node is Allowed
condition: template
value_template: "{{ node_id|string in allowed_nodes.keys() }}"
- alias: Check that message is addressed to Assist
condition: template
value_template: "{{ message is match('Assist:')}}"
actions:
- action: conversation.process
data:
text: "{{ message.split('Assist: ')[1] | lower }}"
@Didgeridrew
I got it working thanks to your example.
Thank you.
triggers:
- trigger: event
event_type: meshtastic_api_text_message
conditions:
- alias: Channel ID is '1'
condition: template
value_template: "{{ trigger.event.data.data.to.channel | int(0) == 1 }}"
- alias: Message contains code 'ROSEBUD'
condition: template
value_template: "{{ 'ROSEBUD' in (trigger.event.data.data.message).upper() }}"
actions:
- parallel:
- action: notify.alexa_media_echo1
metadata: {}
data:
title: Rosebud... Rosebud...
message: >-
{% set id = trigger.event.data.data.from | string %}
{% if id == '123456789' %}{% set device = 'Tracker-1' %}
{% elif id == '9876543210' %}{% set device = 'Tracker-2' %}
{% else %}{% set device = 'sender unknown' %}
{% endif %}
Message from {{ device }} (channel: my-channel-name): {{ trigger.event.data.data.message | regex_replace(find='rosebud',replace='', ignorecase=true) }}



