Meshtastic Infobot

I know this is probably known to a lot of folks already, but here’s an automation you can use to make an auto-reply bot on Meshtastic. I live near a huge city park and I thought it would be nice to have a bot that can provide some information. This would be super helpful in disaster situations where internet is not fully reliable/available.

The automation listens and replies to Direct Messages on meshtastic. If you wanted, you could/probably should restrict this to known specific clients for safety, I suppose.

Prerequisites: You have a meshtastic node connected to home assistant using the Meshtastic integration on HACS. Set your node’s long name to something like “Infobot DM hi to start”

alias: meshtastic weather reply
description: ""
triggers:
  - trigger: event
    event_type: meshtastic_api_text_message
conditions:
  - condition: template

# Note: Replace XXXXXXXXXX with your node number. 
# Listen to events and message your node to get this.

    value_template: "{{ trigger.event.data.data.to.node == XXXXXXXXXX }}"

# Make a condition that processes the request. 
# There are probably easier ways to do this.
# I have one automation set to reply to hi that tells users this is a bot and what commands are available. 
# I then have separate automations for weather, forecast, and time.

  - condition: or
    conditions:
      - condition: template
        value_template: "{{ trigger.event.data.data.message == \"weather\" }}"
      - condition: template
        value_template: "{{ trigger.event.data.data.message == \"Weather\" }}"
      - condition: template
        value_template: "{{ trigger.event.data.data.message == \"What is the weather\" }}"
      - condition: template
        value_template: "{{ trigger.event.data.data.message == \"What is the weather?\" }}"
      - condition: template
        value_template: "{{ trigger.event.data.data.message == \"what is the weather?\" }}"
      - condition: template
        value_template: "{{ trigger.event.data.data.message == \"what is the weather\" }}"

# Meshtastic API examples give it 5 seconds, but 2 seconds seems to be just fine.

actions:
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0

# Change the "abc123def456ghi890" to the device ID of the node you have connected to home assistant and will broadcast replies from. Tip: Switch to the visual editor. This should be one of the only options in the drop-down.
# Keep ack: true.  

# These steps are critical. If you use the node number from above here, the automation will ONLY reply to clients with direct connections and strong signals.

  - action: meshtastic.send_text
    metadata: {}
    data:
      ack: true
      from: abc123def456ghi890
      to: "{{ trigger.event.data.data.from }}"

# The text should be whatever sensor data you want to share with the public. Here's NWS conditions and my acurite weather sensor, which is coming in via rtl_433!

      text: >-
        At home, it is currently {{ states("weather.home") 
        | regex_replace("lightning-rainy","Thunderstorms") |
        regex_replace("lightning","Lightning") | regex_replace("sunny","Sunny")
        | regex_replace("partlycloudy","Partly Cloudy") |
        regex_replace("clear-night","Clear") | regex_replace("cloudy","Cloudy")
        | regex_replace("fog","Fog") | regex_replace("hail","Hail") |
        regex_replace("rainy","Rain") }}. It's {{
        states("sensor.acurite_5n1_a_123_f")| round(1)}} °F. With
        {{states("sensor.acurite_5n1_a_123_h")}}% humidity. Winds are
        {{states("sensor.wind_dir") }} at
        {{states("sensor.acurite_5n1_a_123_ws") | round(1) }} mph.
mode: single

Hopefully this is helpful to you and makes Meshtastic way more useful to others!

1 Like

Thanks for this. Was just starting to think about how to do it and BOOOM you’ve done it already. Great stuff