Skip to content

Home Assistant

Home Assistant can show a ThingStudio board as a device, with its sensors, switches and controls, over MQTT. A flow places one ha device node and an entity node for each thing Home Assistant should see. Deploy it, and the board appears in Home Assistant: no YAML, and no firmware to build.

This page covers what you need, setting up the broker, the starter flow, and the limits. Each node has its own page in the node reference.

What you need

  • A board with WiFi, set up as the rest of this guide describes.
  • Home Assistant with an MQTT broker.

The nodes are in the palette's home assistant group. Nothing else to install: they ship with ThingStudio.

Set up MQTT in Home Assistant

Skip this if Home Assistant already uses an MQTT broker.

  1. The broker. In Home Assistant, go to Settings → Add-ons → Add-on Store, install Mosquitto broker and start it.
  2. A user for the board. Settings → People → Users → Add user, for example thingstudio, with a password. The Mosquitto add-on accepts Home Assistant users.
  3. The integration. Settings → Devices & services. Home Assistant usually offers the discovered MQTT integration: click Configure. Otherwise add the MQTT integration and point it at the add-on. Discovery is on by default, with the prefix homeassistant.
  4. In ThingStudio, the flow's MQTT broker is the Home Assistant machine's address, port 1883, and the user from step 2.

The starter flow

starter-ha.flow.json is in the tutorials/ folder of an install. It runs on a board with WiFi and nothing wired to it, and switches the board's own LED from Home Assistant. For a Pico W or Pico 2 W, open starter-ha-pico-w.flow.json instead: its LED is on the WiFi chip, so a function node drives it.

  1. File → Open… starter-ha.flow.json.
  2. Select ha device. Its WiFi and MQTT Broker fields are empty. In each, pick a credential you have already saved, or make one with +: your network's name and password, and for the broker the Home Assistant machine's address, port 1883 and the MQTT user. Credentials stay on your computer, in the .thingstudio/credentials/ folder, not in the flow.
  3. Pick your board in the Board menu. Select gpio out and set pin to the board's LED: after Connect, the console names the board's LED pins. Click Compile → Deploy.
  4. In Home Assistant, the board appears under Settings → Devices & services → MQTT, with its uptime, free memory, chip temperature and WiFi signal, an LED switch and a button.

The LED switch turns the board's LED on and off. The button prints to the editor's console, through debug. The chip temperature is the processor's own reading, which runs warmer than the room. A classic ESP32's sensor returns a fixed value, so on that chip the entity stays unknown.

Build your own flow

  1. Put one ha device node in the flow and pick the flow's WiFi and MQTT Broker. Every flow with Home Assistant nodes has exactly one.
  2. Add an entity node for each thing Home Assistant should see, and wire it like any other node: a sensor's value into ha sensor, ha switch's output to what it switches.
  3. Give each entity an on start value, so it shows a known state the moment the flow starts (below).
  4. Deploy. The board appears under Settings → Devices & services → MQTT under the device name you gave ha device, or, with that empty, the board's network name (Network name in Tools → Board settings…).

Each entity node's id becomes part of the entity's id in Home Assistant, so the same node keeps the same entity across deploys, renames and restarts. Deleting a node and adding a new one makes a new entity; the old one is removed on the next deploy.

Showing a value from the start

When a flow starts, each entity shows as unknown in Home Assistant until the flow reports a value. That's deliberate: it stops Home Assistant showing a value left over from the last flow. Set the entity's on start instead of wiring a startup node into it.

  • A switch, number or select that sets something on the board: on start sends the value out once at flow start, as if Home Assistant had sent it, so the downstream flow sets the hardware. Left unwired, the node also publishes it as the state.
  • A binary sensor fed by events, such as a button: set on start to the resting state, off.
  • A sensor shows what the flow reports; there's nothing to start it with.

restore (switch, number and select) starts from the last value the entity showed, kept on the board: after a reboot or a redeploy of the same flow, Home Assistant picks up where it left off. With nothing stored yet it behaves as unknown.

The board doesn't need to be connected when the flow starts: a value is kept and sent once the board reaches the broker.

When to wire the real state back: an entity whose input is unwired confirms each command itself, so Home Assistant shows the value as set whether or not anything happened. That's right when the command is the state, such as an LED. When the real state can differ from the command, such as a relay with a feedback contact or a thermostat, wire the real state back to the entity's input.

Removing a device

A flow without ha device leaves the board's device in Home Assistant. To remove it, open the device in Home Assistant (Settings → Devices & services → MQTT → devices) and delete it. Deleting an entity node from the flow removes that one entity on the next deploy.

Limits

  • One ha device per flow, and every entity node needs it.
  • The discovery message, which describes every entity, can be at most 4 KB: about a dozen entities with long names, more with short ones. The compile says so when a flow goes over.
  • Node ids go into MQTT topics: letters, digits, _ and -, at most 32 characters.
  • Home Assistant to the board covers the board's own entities only: these nodes don't read other Home Assistant entities.

Upgrading from the custom-node bundle

The nodes were a custom-node bundle before. A board that ran it keeps working; to use the built-in nodes:

  1. Delete the folder ~/.thingstudio/custom-nodes/home-assistant/, or the bundle is skipped with a console line naming ts_ha.
  2. Open each saved flow and set its node types from ha/device, ha/sensor and so on to thingstudio/ha_device, thingstudio/ha_sensor and so on. A flow file is JSON: the type is the "type" field of each ha/* node.
  3. Deploy.

The entities in Home Assistant survive: identity comes from the board's chip id and each node's id, not from the node type.