Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Test an MQTT Automation With a Fictional Event Before Relying on It

说明与用途

使用虚构事件测试 MQTT 自动化可确保主题、负载过滤器和操作在投入生产前正常工作。

问题

Verify that an MQTT automation processes a message correctly before relying on it in production.

结果

The automation successfully processed a fictional MQTT message, creating a notification and trace, confirming the topic, payload filter, and action work together.

工作流

  • 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.

证据

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"}.

来源

  • 记录日期: 2026-11-01T19:43:59.556Z