Publish sensor data from Just Sensors to Home Assistant, Grafana, and more
Just Sensors can publish sensor data to any MQTT broker, enabling integration with home automation systems, data visualization platforms, and custom applications. MQTT (Message Queuing Telemetry Transport) is a lightweight messaging protocol ideal for IoT and sensor data.
Sensor data is published to hierarchical topics that make it easy to subscribe to specific sensors or all data from a device.
| Component | Description | Example |
|---|---|---|
base_topic |
Configurable prefix (default: "justsensors") | justsensors |
device_id |
First 8 characters of device vendor ID | a1b2c3d4 |
sensor_type |
Sensor name in snake_case | accelerometer |
justsensors/a1b2c3d4/accelerometer
justsensors/a1b2c3d4/battery
justsensors/a1b2c3d4/location
justsensors/a1b2c3d4/sound_level
justsensors/a1b2c3d4/session # Session metadata
Use MQTT wildcards to subscribe to multiple topics:
# All sensors from a specific device
justsensors/a1b2c3d4/#
# Specific sensor from all devices
justsensors/+/battery
# All data
justsensors/#
All payloads are JSON-formatted with an ISO8601 timestamp and sensor-specific fields.
{
"timestamp": "2025-02-05T10:30:00Z",
"sensor_type": "accelerometer",
"x": 0.012,
"y": -0.984,
"z": 0.021
}
{
"timestamp": "2025-02-05T10:30:00Z",
"sensor_type": "battery",
"level": 0.85,
"state": "charging"
}
{
"timestamp": "2025-02-05T10:30:00Z",
"sensor_type": "location",
"latitude": 37.7749,
"longitude": -122.4194,
"altitude": 10.5,
"speed": 2.3,
"horizontalAccuracy": 5.0
}
MQTT supports three levels of delivery guarantee. Choose based on your reliability needs and network conditions.
Fire and forget. Message sent once with no acknowledgment. Best for high-frequency sensor streams where occasional loss is acceptable.
Acknowledged delivery. Publisher retries until acknowledged. May deliver duplicates. Best balance of reliability and performance.
Four-step handshake ensures single delivery. Higher latency. Best for critical messages where duplicates would cause issues.
| Sensor Type | Recommended QoS | Reason |
|---|---|---|
| Accelerometer, Gyroscope | QoS 0 | High frequency, loss acceptable |
| Battery, Brightness | QoS 1 | Periodic updates, should be reliable |
| Location | QoS 1 | Important for tracking |
| Session metadata | QoS 1 | Should not be lost |
Home Assistant has native MQTT integration that makes it easy to receive sensor data from Just Sensors.
Install Mosquitto as a Home Assistant add-on, or use an external broker.
# In Home Assistant, go to:
Settings โ Add-ons โ Add-on Store โ Mosquitto broker โ Install
Add the MQTT integration in Home Assistant.
# In Home Assistant, go to:
Settings โ Devices & Services โ Add Integration โ MQTT
Add MQTT sensors to your configuration.yaml:
mqtt:
sensor:
# iPhone Battery Level
- name: "iPhone Battery"
state_topic: "justsensors/+/battery"
value_template: "{{ (value_json.level * 100) | round(0) }}"
unit_of_measurement: "%"
device_class: battery
icon: mdi:cellphone
# Sound Level
- name: "iPhone Sound Level"
state_topic: "justsensors/+/sound_level"
value_template: "{{ value_json.decibels | round(1) }}"
unit_of_measurement: "dB"
icon: mdi:microphone
# Brightness
- name: "iPhone Brightness"
state_topic: "justsensors/+/brightness"
value_template: "{{ (value_json.level * 100) | round(0) }}"
unit_of_measurement: "%"
icon: mdi:brightness-6
# Barometer (Pressure)
- name: "iPhone Pressure"
state_topic: "justsensors/+/barometer"
value_template: "{{ value_json.pressure | round(2) }}"
unit_of_measurement: "kPa"
device_class: pressure
device_tracker:
# Location Tracking
- name: "iPhone Location"
state_topic: "justsensors/+/location"
json_attributes_topic: "justsensors/+/location"
source_type: gps
Use the sensor data to trigger automations:
automation:
- alias: "Low iPhone Battery Alert"
trigger:
- platform: numeric_state
entity_id: sensor.iphone_battery
below: 20
action:
- service: notify.notify
data:
message: "iPhone battery is low!"
Visualize sensor data over time with Grafana, using Telegraf to collect MQTT data and InfluxDB for storage.
Install Telegraf, InfluxDB, and Grafana. Using Docker:
# docker-compose.yml
version: '3'
services:
influxdb:
image: influxdb:2.7
ports:
- "8086:8086"
volumes:
- influxdb-data:/var/lib/influxdb2
telegraf:
image: telegraf:latest
volumes:
- ./telegraf.conf:/etc/telegraf/telegraf.conf:ro
depends_on:
- influxdb
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
depends_on:
- influxdb
volumes:
influxdb-data:
Create telegraf.conf to subscribe to MQTT topics:
# telegraf.conf
# MQTT Consumer Input
[[inputs.mqtt_consumer]]
servers = ["tcp://your-broker:1883"]
topics = ["justsensors/#"]
data_format = "json"
topic_tag = "topic"
# Parse device_id and sensor from topic
[[inputs.mqtt_consumer.topic_parsing]]
topic = "justsensors/+/+"
tags = "_/device_id/sensor"
# InfluxDB Output
[[outputs.influxdb_v2]]
urls = ["http://influxdb:8086"]
token = "your-token"
organization = "your-org"
bucket = "sensors"
Add InfluxDB as a data source in Grafana, then create panels with Flux queries:
// Battery level over time
from(bucket: "sensors")
|> range(start: -24h)
|> filter(fn: (r) => r.sensor == "battery")
|> filter(fn: (r) => r._field == "level")
|> map(fn: (r) => ({ r with _value: r._value * 100.0 }))
// Accelerometer magnitude
from(bucket: "sensors")
|> range(start: -1h)
|> filter(fn: (r) => r.sensor == "accelerometer")
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(fn: (r) => ({
r with magnitude: math.sqrt(r.x*r.x + r.y*r.y + r.z*r.z)
}))
Just Sensors can publish data from the following sensors via MQTT:
| Sensor | MQTT Topic | Key Fields |
|---|---|---|
| Accelerometer | accelerometer |
x, y, z (g-force) |
| Gyroscope | gyroscope |
x, y, z (rad/s) |
| Magnetometer | magnetometer |
x, y, z (ยตT), heading |
| Barometer | barometer |
pressure (kPa), relativeAltitude (m) |
| Device Motion | device_motion |
pitch, roll, yaw, quaternion |
| Pedometer | pedometer |
steps, distance, floorsAscended |
| Location | location |
latitude, longitude, altitude, speed |
| Battery | battery |
level (0-1), state |
| Sound Level | sound_level |
decibels, peakDecibels |
| Light Meter | light_meter |
estimatedLux, iso, exposureDuration |
| Brightness | brightness |
level (0-1) |
| Proximity | proximity |
isNear (boolean) |
| Orientation | orientation |
orientation (portrait, landscape, etc.) |
justsensors/#) to see all messagesDownload MQTT Explorer to visualize your topic structure and inspect payloads in real-time.