Home / Guide / ESPEasy Home Assistant Integration With MQTT

ESPEasy Home Assistant Integration With MQTT

A clear route from sensor readings on an ESP board to entities and switches inside Home Assistant, using a standard MQTT broker.

ESPEasy devices page with relay and switch tasks ready to publish to Home Assistant over MQTT

ESPEasy and Home Assistant work well together, and MQTT is the bridge that connects them. The firmware publishes sensor readings to an MQTT broker, Home Assistant subscribes to those readings and turns them into entities, and commands can travel back the other way to switch relays or trigger actions on the board.

This article explains how to set up that connection from start to finish: preparing a broker, configuring the controller on the board, defining sensors in Home Assistant and sending commands back to the device.

Why MQTT Is the Usual Route

Home Assistant offers a native API for some firmware projects, but this firmware communicates with it primarily through MQTT. MQTT is a lightweight publish-and-subscribe protocol. Devices publish messages to named topics on a central broker, and any client interested in those topics subscribes to receive them.

The approach has practical advantages. The broker decouples devices from the systems that use their data, so the same readings can feed Home Assistant, Node-RED and a logging database at the same time. It also keeps the firmware simple, since each node only needs to know how to reach the broker.

Setting Up an MQTT Broker

Home Assistant does not include an MQTT broker by default, so you need one running somewhere on your network. The most common choice is Mosquitto. If you run Home Assistant OS or a supervised installation, the Mosquitto broker add-on can be installed from the add-on store and started in a few clicks.

Create a dedicated user account for your ESP nodes rather than reusing your main Home Assistant login. Then add the MQTT integration in Home Assistant and point it at the broker. Once the integration reports that it is connected, the broker is ready to receive messages from your devices.

Configuring the Controller on the Board

Open the board's web interface and go to the Controllers tab. Choose an empty slot and select the Home Assistant (openHAB) MQTT protocol. The project documentation describes this as one of the most standard MQTT controllers, with a basic way of interacting with a broker that is not limited to Home Assistant or openHAB.

Fill in the following details:

  • The broker's IP address or host name.
  • The port, usually 1883 for unencrypted connections.
  • The user name and password you created for your devices.
  • A client ID, which can usually be left as the default as long as each node has a unique name.

Enable the controller and submit. The controller status on the Main or Controllers page should soon show a successful connection.

Understanding the Default Topics

The controller uses two topic templates, one for publishing and one for subscribing. The common defaults look like this:

Publish:   %sysname%/%tskname%/%valname%
Subscribe: %sysname%/#

The placeholders are replaced automatically. The system name is the unit name you set on the Config tab, the task name is the name of each device task and the value name is the name of each value within that task. A node called greenhouse with a task called Climate that reports Temperature and Humidity would therefore publish to topics such as greenhouse/Climate/Temperature and greenhouse/Climate/Humidity.

The controller can also publish a last will message, typically on a topic such as greenhouse/LWT. The broker sends this message automatically if the node disconnects unexpectedly, which allows Home Assistant to mark the device as unavailable.

Sending Task Values to the Controller

Configuring the controller is only half the job. Each task must also be told to send its values. Open the task on the Devices tab and tick the box for the relevant controller in the data acquisition section. Set a sensible interval, such as 60 seconds for room climate readings, and submit.

A free MQTT client, such as MQTT Explorer, is invaluable at this stage. Connect it to the broker and watch the topics appear. Seeing the messages arrive confirms that the board side is working before you begin configuring Home Assistant.

Defining Sensors in Home Assistant

The simplest way to create entities is with MQTT sensor definitions in your Home Assistant configuration. A temperature reading from the example above might be defined like this:

mqtt:
  sensor:
    - name: "Greenhouse Temperature"
      state_topic: "greenhouse/Climate/Temperature"
      unit_of_measurement: "°C"
      device_class: temperature
    - name: "Greenhouse Humidity"
      state_topic: "greenhouse/Climate/Humidity"
      unit_of_measurement: "%"
      device_class: humidity

After reloading the MQTT configuration or restarting Home Assistant, the new entities appear and update each time the board publishes. You can then add them to dashboards, use them in automations or record their history.

Recent firmware builds also include optional support for Home Assistant MQTT discovery, controlled through settings on the controller page, including a discovery trigger topic that defaults to homeassistant/status. Discovery depends on your build and its configuration, so check the controller page on your own node before relying on it. Manual definitions remain a dependable option that works with any build.

Controlling Outputs From Home Assistant

Commands travel from Home Assistant to the board through the subscribe topic. The controller listens for messages on a command topic beneath the system name and executes the payload as a firmware command. Publishing the following message would switch GPIO 12 on:

Topic:   greenhouse/cmd
Payload: GPIO,12,1

In Home Assistant, an MQTT switch can wrap this behaviour neatly:

mqtt:
  switch:
    - name: "Greenhouse Fan"
      command_topic: "greenhouse/cmd"
      payload_on: "GPIO,12,1"
      payload_off: "GPIO,12,0"

For a switch that also reports its true state, add a task on the board that monitors the relay pin and publishes its value, then use that topic as the switch's state topic. This keeps Home Assistant accurate even if the relay changes state through a local button or a rule.

Combining Home Assistant With Local Rules

One of the firmware's strengths is that rules run directly on the board. A physical button can switch a relay instantly through a rule, even if Home Assistant or the broker is temporarily unavailable, while MQTT keeps Home Assistant informed of the change.

This hybrid approach gives you the best of both worlds. Time-critical or safety-related behaviour happens locally, while Home Assistant handles dashboards, notifications and automations that depend on information from several devices.

Using Multiple Controllers

Each node can run up to three controllers at once, and each task can send its values to any combination of them. You might, for example, send readings to Home Assistant through MQTT and also log them to a separate service such as ThingSpeak or Emoncms. Choose the controllers that suit your project and tick the relevant boxes in each task.

Troubleshooting the Integration

  • The controller never connects: check the broker address, port and credentials, and confirm the broker is running.
  • Topics never appear: make sure each task has its controller box ticked and is enabled.
  • Entities show as unknown: compare the state topic in Home Assistant with the actual topic seen in an MQTT client, character for character.
  • Commands have no effect: confirm the subscribe topic, the exact command topic and the payload syntax.
  • Values arrive with unexpected formatting: check the number of decimals and any formula configured in the task.

Securing the MQTT Connection

An MQTT broker carries every reading and command in your system, so it deserves sensible protection. Always require a user name and password on the broker, and give each group of devices its own account where practical. Avoid exposing the broker port directly to the internet; if remote access is needed, reach your network through a VPN instead.

Access control lists, supported by Mosquitto and other brokers, can restrict which topics each account may publish or subscribe to. A sensor node, for example, only needs to publish its readings and receive commands on its own topics. Limiting it to those topics means a compromised device cannot interfere with the rest of your system.

Recent firmware builds include support for TLS on MQTT connections in some configurations, which encrypts traffic between the board and the broker. Encryption adds processing overhead and needs careful certificate handling, so check whether your build and board support it before planning around it. On a well-secured home network, authenticated but unencrypted MQTT is a common and reasonable compromise.

Organising Topics as Your System Grows

A clear topic structure makes a growing installation far easier to manage. Choose unit names that describe location or purpose, such as kitchen, garage or greenhouse, and keep task names short and consistent. If you prefer to group devices beneath a common prefix, adjust the publish and subscribe templates on each controller, for example by placing every node under a home prefix.

Consistency matters more than the exact scheme. When every node follows the same pattern, Home Assistant definitions become predictable, troubleshooting becomes quicker and new devices can be added by copying an existing definition and changing a single name. Record your chosen structure somewhere, so that future additions follow the same rules.

Before adding new nodes, test the complete path with a single sensor. Confirm that readings appear in an MQTT client, then in Home Assistant, and finally that a command from Home Assistant reaches the board. Once that path works end to end, adding further devices becomes a matter of repetition rather than investigation.

Frequently Asked Questions

Does ESPEasy work with Home Assistant?

Yes. The most common method is MQTT, using the Home Assistant (openHAB) MQTT controller on the board and the MQTT integration in Home Assistant.

Do I need a separate MQTT broker?

Yes. A broker such as Mosquitto must run on your network. Home Assistant OS users can install it as an add-on.

Which controller should I choose on the board?

Choose the Home Assistant (openHAB) MQTT controller, which the documentation describes as the most standard MQTT option.

How do I switch a relay from Home Assistant?

Publish a command such as GPIO,12,1 to the node's cmd topic, ideally through an MQTT switch entity.

Will my automations keep working if Home Assistant goes offline?

Rules stored on the board continue to run locally. Automations that live in Home Assistant will pause until it returns.

Does ESPEasy support MQTT discovery?

Recent builds include optional discovery settings on the controller page. Support depends on your build, so check your node's controller options.

Conclusion

ESPEasy and Home Assistant form a practical partnership through MQTT. Set up a broker, configure the controller on each node, define entities that match your topics and use the command topic to control outputs. Add local rules for anything that must keep working when the network does not, and you have a resilient smart home built on inexpensive, flexible hardware.