A home automation lab with Home Assistant and MQTT

Run Home Assistant and an MQTT broker on your own computer, add simulated devices, and practise automations, dashboards and secure remote access before you buy or connect any real equipment.

  • Time: 1 hour
  • Cost: free software, your own computer

What you need

Home Assistant (home-assistant.io) is a free, open-source home automation platform, and Mosquitto (mosquitto.org) is a free MQTT broker, the message system many sensors and switches use. Together they let you build and test automations entirely on your computer with simulated devices, so you learn the concepts before spending money.

You can run Home Assistant as a virtual machine (the project provides a ready-made image for VirtualBox and similar tools), in a container, or on a Raspberry Pi. The virtual machine route is the closest to the real product and includes its add-on store.

Set it up

  1. Download the Home Assistant OS image for your virtualisation tool from home-assistant.io and create a VM (2 CPUs, 2 to 4 GB of memory, bridged networking so your computer can reach it). Start the VM.
  2. After a few minutes open http://homeassistant.local:8123 and create your account and home location.
  3. Install the Mosquitto broker add-on from Settings, Add-ons, then add the MQTT integration.
  4. Create a simulated device. From any Linux machine with the MQTT tools (sudo apt install mosquitto-clients):
mosquitto_pub -h homeassistant.local -u USER -P PASSWORD -t home/livingroom/temperature -m 24.5
  1. In Home Assistant add an MQTT sensor for that topic (Settings, Devices, MQTT) and watch the value appear.
  2. Create an automation: “when the temperature goes above 28, send a notification”.

Check that it works

  • The dashboard loads and shows your simulated sensor’s last value.
  • Publishing a new value updates the dashboard within a second.
  • Your automation fires when you publish 29, and does not fire for 24.

Practise safely

  • Never connect mains-powered devices by wiring them yourself. Use ready-made, certified smart plugs and bulbs, and have any mains wiring done by a qualified electrician.
  • Secure the system: strong unique passwords, two-factor authentication on your account, and do not expose port 8123 directly to the internet. For remote access use a VPN or the project’s secure remote option.
  • Keep the lab on its own network if you can; smart devices are often poorly protected.
  • Take a backup (Settings, System, Backups) before big changes and after something works.
  • Treat cameras and microphones as private: do not enable them in a lab unless you need to.

Go further

  • Add a second simulated device (a switch) and build an automation across devices with conditions and time-of-day rules.
  • Build a dashboard with history graphs, and use them to tune a rule that was too sensitive.
  • Connect a real low-cost sensor board (see the embedded lab guide) that publishes to your broker, and check that your simulated test still matches reality.
  • Practise failure: stop the broker, see what the dashboard shows, restore it, and make the automation robust to a missing sensor.

Courses that use this lab

Other lab guides

Software changes quickly. Menu names and version numbers may differ a little from what you see; the ideas and the check at the end of each section stay the same. Always download from the project's own website, and read the licence terms for your situation.