MQTT Integration

In the Integrations panel in Configuration, it is showing my MQTT:
image
and if I click on it it says: ‘This Integration has no devices’

In my configuration.yaml, I have this:

# Sonoff Switches
switch:
  - platform: mqtt
    name: "Coffee Maker"
    command_topic: "cmnd/sonoff1/power"
    state_topic: "stat/sonoff1/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false
  - platform: mqtt
    name: "Toothbrush"
    command_topic: "cmnd/sonoff2/power"
    state_topic: "stat/sonoff2/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false
# MQTT
mqtt:
  broker: core-mosquitto
  username: !secret mqtt_user_name
  password: !secret mqtt_password

So should I be changing config yaml so that I can use the integration instead?

I looked at the docs for MQTT Discovery but it doesn’t seem to make any sense to me. I’m using Hass.io and the MQTT broker addon.

Should I comment out the switches and then restart and then use the integration?

1 Like

I have tons of MQTT devices (~50) specified in my switches.yaml, etc. files and the only things that show up in the Configuration -> Integrations -> MQTT are the discovered devices.

None of my manually set devices show up there since they already have a configured status in those yaml files.

Might just need some clarifying in the docs to avoid the confusion.

What confuses me is nothing in the discovery docs remotely maps to my state or command topics… I was just thinking I should go with the flow and switch to the integration instead of manual config

Looking at your sample config above, these devices wouldn’t get discovered. They have to start with “homeassistant” or whatever you set as the Discovery Prefix.

Honestly, the only thing I see the MQTT Integration button is good for is for simplistic integrations and an “easier” way to input your MQTT credentials into.

So I have a couple of ‘spare’ switches… Maybe I should turn on MQTT discovery with:

mqtt:
  discovery: true
  discovery_prefix: homeassistant

and see what the integration discovers and go from there. My switches are just simple switches so the integration would be perfect as long as I can get away with not screwing with the settings in Tasmota…

Looks like in newer versions of Tasmota you can change the prefix. https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Features

Might wanna try that and turn on Discovery.

I’m sure I can but I don’t want to… I think you can change the parameters for discovery too…

If you don’t want to use MQTT Discovery You have to add unique_id to your configuration. unique_id must be unique. It’s best to use the MAC address of the device (without : char). Such configured device is added to the entity registry, so you can edit the entity name and friendly name from the frontend.

Example:

switch:
  - platform: mqtt
    name: "Coffee Maker"
    command_topic: "cmnd/sonoff1/power"
    state_topic: "stat/sonoff1/POWER"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    retain: false
    unique_id: 00112233445566
1 Like

FWIW, the home automation software I’ve being using for the past decade (Premise Home Control) automatically assigns a Globally Unique Identifier (GUID) to every device (also known as Universally Unique Identifier - UUID).

Now that Home Assistant is evolving in the same direction, if you need identifiers for existing devices, you can use Online GUID Generator to crank them out for you. Alternately, you can use a python script to produce GUID/UUID.

I’m using Home Assistant as a frontend for Premise; the two communicate via MQTT. Every MQTT Light, Switch, etc in Home Assistant gets a unique_id that is assigned the same GUID used in Premise. A typical entry for a light looks like this:

  - platform: mqtt
    name: "Foyer"
    unique_id: A7EA6B42-CC34-4566-AC6A-82E14ED8999E
    state_topic: "premise/home/house/first/foyer/foyerlight/powerstate"
    command_topic: "premise/command/home/house/first/foyer/foyerlight/powerstate"
    payload_on: "1" 
    payload_off: "0"
    brightness_scale: 100
    brightness_state_topic: "premise/home/house/first/foyer/foyerlight/brightness"
    brightness_command_topic: "premise/command/home/house/first/foyer/foyerlight/brightness"
    retain: false

Home Assistant detects the unique_id and adds the light to config/.storage/core.entity_registry. However, I haven’t figured out why “name” isn’t populated:

            {
                "config_entry_id": null,
                "device_id": null,
                "disabled_by": null,
                "entity_id": "light.foyer",
                "name": null,
                "platform": "mqtt",
                "unique_id": "A7EA6B42-CC34-4566-AC6A-82E14ED8999E"
            }
1 Like

Thanks for that - my switches are working fine without the unique_id - I guess a benefit of adding that would be that the entity registry would know about them? Any real reason I need to add this?

I’d be happy to use discovery if I didn’t think it was just going to break everything for no gain and cause me to have to edit stuff in Tasmota as well - and all for nothing.

1 Like

Entity in the registry gives you possibility to edit this entity in frontend.


i have the same MQTT configuration like [DavidFW1960] and i run 0.87 version of HA. i put unique_id on some devices but i can’t see them in Integrations -> MQTT:configurations.yaml. Anyway i see the devices with unique_id in Entity Registry. Any ideas what i’m doing wrong?

1 Like

Sorry, I can’t answer your question. I’m still running 0.80 on my production system and haven’t even experimented with 0.87 on my test system.

I have the same here with 0.88, I see them in the Entity Registry but they don’t appear in the Integrations page at all.

1 Like

I use autodiscovery and just tried updating to .88.0 from .87.1 All of my Tasmota MQTT Sonoffs were incorrectly assigned to their ids after restarting. I am thinking it has something to do with autodiscovery and the two broken “unused entity” old sonoffs that are no longer alive. I was able to roll back to .87.1 and everything went back to normal. I saw no notes that this might break in the release notes. I wonder what broke this?

I use MQTT discovery with the Hass.io core Mosquitto Broker and the MQTT Integration. I have nothing to configure MQTT in my config yaml and no manually defined switches. All my MQTT/Sonoff devices are working perfectly with 0.88.0

There is a new requirement/validation for everything so if you are manually configuring switches, some of the old options are now invalid. Did you check the log to see what might be causing the problems?

@DavidFW1960 I just updated Home Assistant and my MQTT switches and sensors all stopped working. I added the validation between MQTT and Home Assistant (added a new user for mqtt), hopefully successfully as the MQTT add-on log indicates that I have connection(s), to the devices at least… however none of my devices are showing up in Home assistant. I believe I followed the instructions on the help page carefully/ correctly, but still on luck. Would you be willing to share your config settings, minus the passwords of course. If they are just as above, then I don’t know what I am missing.

I don’t have any config settings to share becsause there is no mqtt section in config yaml. The broker is default settings. When I added the MQTT integration I enabled discovery. I am using a home assistant user for the mqtt username and password. You do need to enable discovery on the devices themselves. In Tasmota, setoption19 on in the console. Then they should just pop up. But the MQTT settings on the device need to be configured with the home assistant username and password or you can define a local user in the broker.

I am not using Tasmoto, I wrote my own code using Mongoose OS. Does the device requires a home assistant user or local user as well? I was hoping that if I set “anonymous” to true in the add-on I would not need to do that. I do not have OTA updates enabled, so would have to pull all my devices apart… just loaded MQTT Dash on an Android tablet, and I can connect to the MQTT server, and get the values (temperatures) from the devices. So that part is working, the values are just not getting into Home Assistant! And was just able to send commands to a switch via MQTT Dash via the MQTT server.

You can still use Anonymous login in MQTT but it would be better to set a user.
I have 3 users setup. Switches, sensors and lights. All my sensors use the sensors user, all lights the lights use and switches the switches user. They work as shared accounts. I don’t have any MQTT users setup as such, I just use Home Assistant user accounts. They just work.
You don’t have to use MQTT discovery. Discovery sets a retained message on the discovery topic with the settings for the devices, but you can still define MQTT devices manually in YAML files. See the MQTT documentation for how that is set up.
MQTT devices using discovery will not show in integrations at this stage as it is set using a MQTT retained message to the discovery topic rather than being an actual integration. That’s why you can’t find it anywhere in any files if you use discovery.