Test an MQTT Automation With a Fictional Event Before Relying on It
Description and use
Testing an MQTT automation with a fictional event confirms that the topic, payload filter, and action work together before relying on it in production.
Problem
Verify that an MQTT automation processes a message correctly before relying on it in production.
Outcome
The automation successfully processed a fictional MQTT message, creating a notification and trace, confirming the topic, payload filter, and action work together.
Workflow
- 1. Write a clear claim: a JSON message on lab/automation-test/2026-10-31/event with event_type new_device should create a persistent notification.
- 2. Create a test topic under a controlled prefix, e.g., lab/automation-test/2026-10-31/event.
- 3. Define a Home Assistant automation with a narrow match: trigger on the test topic, value_template extracting event_type, payload condition equals new_device, action persistent_notification.create.
- 4. Publish a fictional JSON payload to the test topic using Home Assistant’s MQTT Publish tool or another publisher: {"event_type":"new_device","name":"Tutorial printer","ip":"192.0.2.42","note":"fictional test data"}.
- 5. Verify the persistent notification appears and check the automation trace for the trigger data and action result.
- 6. Perform a negative test by publishing a message with event_type device_offline to ensure the automation does not run.
- 7. Optionally test restarts by restarting Home Assistant and inspecting trace timestamps to confirm no false positives from retained messages.
- 8. Once tests pass, move the automation to a real integration, keeping the first production action observational.
Evidence
An MQTT automation can look finished before it has processed a single message from a broker.
Use a topic reserved for testing, data that identifies no real person or device, and a harmless action you can see.
Publish once to the exact test topic with this payload: {"event_type":"new_device","name":"Tutorial printer","ip":"192.0.2.42","note":"fictional test data"}.
- Record date: 2026-11-01T19:43:59.556Z