MQTT and Home Assistant - GabeMx5/ESP32-C3-Semaphore GitHub Wiki

MQTT and Home Assistant

Configuration

Configure the broker in the SETTINGS tab of the web interface (MQTT section):

Field Default Description
Broker IP or hostname of the MQTT broker
Port 1883 TCP port
Username / Password Optional credentials
Client ID semaphore MQTT client identifier
Topic prefix semaphore Prefix for all topics

Auto-Discovery (Home Assistant)

On connection, the device publishes Home Assistant MQTT discovery topics automatically. No manual configuration needed.

Lights

One light entity per LED with RGB color and brightness control:

Entity Topic
Bottom LED semaphore/cmd/led/0
Middle LED semaphore/cmd/led/1
Top LED semaphore/cmd/led/2

Commands use the HA JSON light schema (state, color, brightness).

Switches

Entity Description
Cycle Enable / disable cycle effect
Party mode Enable / disable party effect
Rainbow Enable / disable rainbow effect

Buttons

Entity Description
Random Yes/No Trigger the yes/no animation
Weather Color Activate the weather color effect
Air Quality Color Activate the air quality color effect

Sensors

Entity Unit Device class Update interval
Temperature °C temperature Every 30 minutes (weather fetch)
Humidity % humidity Every 30 minutes (weather fetch)
Condition text Every 30 minutes (weather fetch)
PM2.5 µg/m³ Every 30 minutes (air quality fetch)
PM10 µg/m³ Every 30 minutes (air quality fetch)
NO₂ µg/m³ Every 30 minutes (air quality fetch)
RSSI dBm signal_strength Every 60 seconds

Topics

Topic Direction Description
{prefix}/cmd Subscribe JSON command (same format as WebSocket)
{prefix}/status Publish Full device status broadcast
{prefix}/status/led/{n} Publish Individual LED state (retained)
{prefix}/status/switch/{name} Publish Switch state ON/OFF (retained)
{prefix}/status/weather/temperature Publish Temperature in °C (retained)
{prefix}/status/weather/humidity Publish Humidity in % (retained)
{prefix}/status/weather/condition Publish Condition string (retained)
{prefix}/status/airquality/pm2_5 Publish PM2.5 in µg/m³ (retained)
{prefix}/status/airquality/pm10 Publish PM10 in µg/m³ (retained)
{prefix}/status/airquality/no2 Publish NO₂ in µg/m³ (retained)
{prefix}/status/rssi Publish WiFi signal strength in dBm (retained)

Command Format

The command topic accepts the same JSON protocol as WebSocket. Examples:

{ "type": "setLed", "led": 0, "on": true, "r": 255, "g": 0, "b": 0 }
{ "type": "setCycle", "cycle": true }
{ "type": "setParty", "party": true, "partyMadness": 7 }
{ "type": "setRainbow", "rainbow": true }
{ "type": "randomYesNo" }
{ "type": "weatherColor" }
{ "type": "airQualityColor" }
{ "type": "all_off" }

Also accessible via HTTP POST to /cmd.