Källa: Home Assistant | MQTT add-on | Github | MQTT | Beginners video |


MQTT är ett transportlager på TCP/IP som är en pub/sub tjänst

MQTT (även känt som MQ Telemetry Transport) är ett maskin-till-maskin-protokoll eller ”Internet of Things”-protokoll utöver TCP/IP. Det möjliggör extremt lätt publicerings-/prenumerationsöverföring av meddelanden.


  1. Installer MQTT broker på Homeserver
    Skapa användare + lösenord i Home Assistant för MQTT användare som ska används av klienter som vill

Test

Validera Home Assistant MQTT Broker

Note! Fungerar inte
Validate access with browser mqtt(s)://[användarnamn[:lösenord]@]host[:port] .
mqtt://user:pw@homeassistant.local:1883

I’m assuming you are running Home Assistant OS and have mosquito installed as a home assistant addon (otherwise, you would have set up mosquito broker manually and already know the answer).

The answer depends on where you are trying to access mqtt from.

  • If you are trying to connect to it from within HA itself or from some other addon (e.g. NodeRed), then you should use the hostname core-mosquitto and port 1883. This hostname is managed by automatically (by home assistant os/docker) and will always map to the correct addon. But it only works from inside the ha/addon ecosystem so…
  • If you are trying to connect to it from some other machine on your LAN (e.g. from some smart device), the mosquito broker addon is listening on port 1883 on the same IP address and hostname as home assistant itself. For example, if your rPI is on your network as ”homeassistant.local” then your mqtt broker will be homeassistant.local port 1883. Or if your rPI has no hostname and you access it only by IP address like 192.168.1.10, then the broker will be 192.168.1.10 port 1883

The Home Assistant MQTT broker address is typically the local IP address of your Home Assistant instance, with the default port being 1883. If you’re using Home Assistant OS and haven’t changed the default settings, you can also use homeassistant.local as the hostname.

Here’s a breakdown: 

  • IP Address:
    If your Home Assistant instance has the IP address 192.168.1.100, then the MQTT broker address would be mqtt://192.168.1.100:1883.
  • Hostname:
    If you’re using Home Assistant OS, you can also use mqtt://homeassistant.local:1883.
  • Port:
    The default MQTT port is 1883.
  • Authentication:
    If you’ve set up authentication for your MQTT broker (e.g., username and password), you’ll need to include that information in your connection settings as well.

Example:

If your Home Assistant instance has the IP address 192.168.1.100 and you have a username mqtt and password secret, your connection string might look like this (depending on the MQTT client you’re using): mqtt://mqtt:secret@192.168.1.100:1883.

Important Notes:
  • You’ll need to have the MQTT broker integration installed and configured in Home Assistant. 
  • If you’re using a different MQTT broker (not the one included with Home Assistant), you’ll need to use the address and port of that specific broker. 
  • If you’re connecting from outside your local network, you’ll need to ensure your router is properly configured to forward MQTT traffic to your Home Assistant instance. 
  • You may need to adjust the port number if you’ve configured your MQTT broker to use a non-standard port.