Skip to content

Instantly share code, notes, and snippets.

@andyshinn
Last active May 17, 2026 17:12
Show Gist options
  • Select an option

  • Save andyshinn/73a4f978a82c10d2aa24b03edcb4fcac to your computer and use it in GitHub Desktop.

Select an option

Save andyshinn/73a4f978a82c10d2aa24b03edcb4fcac to your computer and use it in GitHub Desktop.
A pathbot automation for MeshCore Home Assistant
alias: Pathbot
description: Responds with a path in the filtered channel where the word 'pathbot' is used
triggers:
- trigger: event
event_type: meshcore_message
event_data:
message_type: channel
channel_idx: 1
alias: When a MeshCore message is received
conditions:
- condition: template
value_template: "{{ (trigger.event.data.message | lower | trim).startswith('pathbot') }}"
alias: If it matches "pathbot" prefix
- condition: template
value_template: |
{{ trigger.event.data.rx_log_data is defined
and trigger.event.data.rx_log_data | length > 0 }}
alias: If it has rx_log_data
actions:
- variables:
msg: "{{ trigger.event.data.message | lower }}"
- choose:
- conditions:
- condition: template
value_template: "{{ msg is search('\\\\bpathbot\\\\s+(f|full)\\\\b') }}"
sequence:
- variables:
entries: "{{ trigger.event.data.rx_log_data }}"
alias: Show the full message
- conditions:
- condition: template
value_template: "{{ msg is search('\\\\bpathbot\\\\s+(s|snr)\\\\b') }}"
sequence:
- variables:
entries: |-
{{ [trigger.event.data.rx_log_data
| sort(attribute='snr', reverse=true) | first] }}
alias: Show the SNR message
default:
- variables:
entries: "{{ trigger.event.data.rx_log_data[:1] }}"
- variables:
paths_summary: |-
{%- set ns = namespace(lines=[]) -%} {%- for rx in entries -%}
{%- set hops = rx.path_len | int -%}
{%- set hex = rx.path | string -%}
{%- if hops == 0 or hex | length == 0 -%}
{%- set ns.lines = ns.lines + ['direct'] -%}
{%- else -%}
{%- set chunk = (hex | length) // hops -%}
{%- set parts = hex | batch(chunk) | map('join') | list -%}
{%- set ns.lines = ns.lines + [(hops|string) ~ 'h ' ~ parts|join(',')] -%}
{%- endif -%}
{%- endfor -%} {{ ns.lines | join(' | ') }}
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: "{{ range(2000, 4000) | random }}"
alias: Delay random amount
- action: meshcore.send_channel_message
data:
channel_idx: 1
message: "@[{{ trigger.event.data.sender_name }}] {{ paths_summary }}"
mode: parallel
max: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment