Integrating Meshtastic into Home Assistant brings a new level of control and monitoring to your mesh network. On this page, we'll guide you through the process of creating Meshtastic MQTT sensor entities within Home Assistant. Whether you want to keep an eye on battery levels, environmental conditions, or even receive notifications from your mesh network, these integrations provide you with the tools to make it happen.
:::info
It is highly recommended to download MQTT Explorer for analyzing the JSON threads that come across the broker. This can be downloaded here: http://mqtt-explorer.com/
:::
## Create Meshtastic MQTT Sensor Entities
- Ensure your mesh unit is connected to your MQTT broker and using JSON as an output.
- Open configuration.yaml and include the following line:
```yaml
mqtt: !include mqtt.yaml
```
- Create a new text file called `mqtt.yaml` in the root directory of home assistant (the same folder as configuration.yaml).
- For added functionality you can create an entity for messages received from a node:
```yaml
- name: "Node 1 Messages"
unique_id: "node_1_messages"
state_topic: "msh/2/json/LongFast/!67ea9400"
value_template: >-
{% if value_json.from == 4038675309 and value_json.payload.text is defined %}
{{ value_json.payload.text }}
{% else %}
{{ states('sensor.node_1_messages') }}
{% endif %}
```
### Additional Entities
Home Assistant entities can be created for any data type that is published to MQTT. For example: altitude, latitude_i, longitude_i, time, current, and neighbors. Use the templates above as a guide to create additional entities if desired.
### Configure With Your Topic & Node ID's
- In every entity, replace `msh/2/json/LongFast/!67ea9400` with the topic your node publishes to. In this example, `!67ea9400` refers to the node that has mqtt enabled on the mesh and is publishing to the broker.
- In every entity replace `4038675309` with the node number of the radio you wish to monitor. In this example `4038675309` is the node on the mesh with environment sensors and telemetry that I wish to observe. Node numbers can be found by monitoring the output in MQTT Explorer, listening with the MQTT addon or by using the Python CLI with `meshtastic --info`.
### Additional Nodes
Copy and paste these entities then change `name`, `unique_id`, `from`, and `states` to create entities from any additional nodes' parameters:
```yaml
- name: "Node 2 Messages"
unique_id: "node_2_messages"
state_topic: "msh/2/json/LongFast/!67ea9400"
value_template: >-
{% if value_json.from == 695318008 and value_json.payload.text is defined %}
{{ value_json.payload.text }}
{% else %}
{{ states('sensor.node_2_messages') }}
{% endif %}
```
### Check Configuration & Reload YAML
- In Home Assistant, run `CHECK CONFIGURATION` in the developer tools section and then reload all yaml configuration.
:::danger warning
Always Check Configuration before reloading YAML or restarting Home Assistant to identify errors.
It is possible to have Home Assistant trigger automations based on messages or events on your mesh.
### Notifications
This example waits for a message containing @Tropho and then sends a pop-up notification to his flip phone with the message. Optionally you can have ALL messages from the mesh sent as HA notifications to your phone.
This same type of automation is very useful to trigger other actions in Home Assistant. For example, you could turn on a fan when the temperature reaches a certain value, or a play a sound on a speaker when a new message is received.
## Create a Send Message Entity
It is possible to create an input text box to send messages to your mesh from within Home Assistant.
### Input Text Helper Entity
First, create an input text helper entity. The preferred way to configure an input text is via the HA interface at Settings > Devices & Services > Helpers. Click the add button and then choose the Text option. Make a text input helper with a max length of 190 to be on the safe side. See example below:
![HA Input Text Helper](/img/software/mqtt/ha_input_text_helper.png)
This automation will check the send box for changes. After typing a message, either hit enter or click off the box and the automation will send a text string in JSON to the mqtt broker. Make sure to call your channel "mqtt" and to update the device ID and `from` field in the example below.
Add this card to your dashboard by going to Edit Dashboard -> + ADD CARD. Then search BY ENTITY for Meshtastic Send Box and check the box next to the entry. Click CONTINUE, then ADD TO DASHBOARD.