Validate a JSON MQTT Payload Before Using It in a Home Assistant Automation
Description and use
Validating JSON MQTT payloads in Home Assistant: select a temporary topic, publish test messages, verify parsing and trigger conditions, use harmless test actions, clean up, and document results.
Problem
An MQTT message can be malformed, arrive on the wrong topic, or be retained from an earlier test, causing Home Assistant automations to react incorrectly.
Outcome
The test confirms that Home Assistant automations only trigger on correctly formatted JSON payloads with the expected event field, and that harmless test actions run as intended.
Workflow
- 1. Choose a temporary topic that no existing publisher or rule uses, e.g. lab/json-payload-check-2026-10-29/event.
- 2. Publish a valid, fictional JSON message with the expected field and value, e.g. {"event":"check","sequence":1}.
- 3. Publish a second valid JSON message with a deliberately different event value, e.g. {"event":"ignore","sequence":2}.
- 4. Optionally publish a malformed string if the diagnostic path can safely display it.
- 5. Record publish time, topic, retain flag, subscriber payload, extracted value, and whether the rule triggered for each message.
- 6. Ensure the automation action is harmless (notification, logbook entry, helper).
- 7. Inspect the automation trace after each test message to confirm the trigger path.
- 8. If no trace, review topic and payload configuration; if trace but no visible result, adjust conditions or action and repeat with a fictional input.
- 9. After testing, disable or remove the temporary automation and clear any retained lab data.
- 10. Keep a non-sensitive record of the topic, sample shape, observation times, and trace results for future reference.
Evidence
An MQTT message can look like JSON and still be unsafe input for an automation. It might be malformed, arrive on the wrong topic, or be retained from an earlier test.
Start with a smaller question than “does MQTT work?”: can a Home Assistant rule receive one controlled JSON message, extract the intended value, and make one harmless change you can observe?
For the first successful match, make the automation action a persistent notification, a logbook entry, or a dedicated helper.
- Record date: 2026-11-01T20:00:01.023Z