Sonoff-Tasmota discovery on Hass.io

According to the Sonoff-Tasmota link, all that should be required is SetOption 19 On in the console of the Sonoff and then a restart of Hassio after the MQTT discover lines have been added to configuration.yaml and any previously configured MQTT switches or lights removed. I am using embedded MQTT and get a configuration error after Hassio starts up. I see the sonoff connecting to MQTT broker fine in the Sonoff console, but no integration added. What did I miss? Inthe MQTT log I see [ERROR] Auth error with… 1541820815: Socket error on client <unknown>, disconnecting.

You need to add credentials to the configuration of the device to be able to use MQTT.

You should use the MQTT broker built into hassio, latest version, remove all MQTT stuff from config yaml including the MQTT: section and any manually configured switches and just use the defaults in the broker. You also need to use a home assistant user (easiest option) you create in the new auth for home assistant and will need to set the username in sonoff to use that user. Note the user CANNOT be homeassistant or ADDONS.

Then your devices will be picked up by discovery.

It is possible to use a local user if you want. What I did was create a new home assistant user that corresponded with the username and password I had in Tasmota. So I didn’t need to change my tasmota settings. Using a home assistant user seems to me to be more future proof.

Thanks David, I may try again today. I have also got the DuckDNS addon installed with ssl and wonder if I should change the MQTT in the sonoffs to 8883 from 1883?

Thanks fabaff,

The MQTT Brokers link you provided is the top of the rabbit hole. It leads you to believe that the MQTT: section is still required in configuration.yaml. The addition of some description about the change to auth users would help lots.

I’m seeing all my clients connect successfully in the MQTT addon log. When adding the MQTT integration, do I use the IP of hassio with no port? Will the SetOption19 = On in console of each Tasmota be equivalent to ```
<discovery_prefix>//[<node_id>/]<object_id>/<>

But first, when I go to integrations, it shows that MQTT has been discovered. When I click it and then the enable discovery checkbox, it reports it is unable to connect to the broker.

The configuration is still needed. You didn’t say a word that you are using Hass.io.

Okay, I put the mqtt: configuration back in configuration yaml

mqtt:
broker: core-mosquitto
username: xxx
password: yyy
discovery: true
discovery_prefix: homeassistant

with the add-on 4.0 configured with

{
“logins”: [
{
“username”: “xxx”,
“password”: “yyy”
}
],
“anonymous”: true,
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}
Reboot and I see all the Sonoffs connect in log of add-on. In integrations, I see MQTT: configuration.yaml
Clicking it and I get

This integration has no devices.

At a Sonoff console entering SetOption19 On, shows:

19:55:15 CMD: SetOption19 On
19:55:15 MQT: homeassistant/switch/sonoff_1/config = (retained)
19:55:15 MQT: homeassistant/light/sonoff_1/config = {“name”:“Sonoff”,“command_topic”:“cmnd/sonoff/POWER1”,“state_topic”:“stat/sonoff/RESULT”,“value_template”:"{{value_json.POWER1}}",“payload_off”:“OFF”,“payload_on”:“ON”,“availability_topic”:“tele/sonoff/LWT”,“payload_available”:“Online”,“payload_not_available”:“Offline”} (retained)
19:55:15 MQT: homeassistant/switch/sonoff_2/config = (retained)
19:55:15 MQT: homeassistant/light/sonoff_2/config = {“name”:“Sonoff2”,“command_topic”:“cmnd/sonoff/POWER2”,“state_topic”:“stat/sonoff/RESULT”,“value_template”:"{{value_json.POWER2}}",“payload_off”:“OFF”,“payload_on”:“ON”,“availability_topic”:“tele/sonoff/LWT”,“payload_available”:“Online”,“payload_not_available”:“Offline”} (retained)
19:55:15 MQT: homeassistant/switch/sonoff_3/config = (retained)
19:55:15 MQT: homeassistant/light/sonoff_3/config = {“name”:“Sonoff3”,“command_topic”:“cmnd/sonoff/POWER3”,“state_topic”:“stat/sonoff/RESULT”,“value_template”:"{{value_json.POWER3}}",“payload_off”:“OFF”,“payload_on”:“ON”,“availability_topic”:“tele/sonoff/LWT”,“payload_available”:“Online”,“payload_not_available”:“Offline”} (retained)
19:55:15 MQT: homeassistant/switch/sonoff_4/config = (retained)
19:55:15 MQT: homeassistant/light/sonoff_4/config = {“name”:“Sonoff4”,“command_topic”:“cmnd/sonoff/POWER4”,“state_topic”:“stat/sonoff/RESULT”,“value_template”:"{{value_json.POWER4}}",“payload_off”:“OFF”,“payload_on”:“ON”,“availability_topic”:“tele/sonoff/LWT”,“payload_available”:“Online”,“payload_not_available”:“Offline”} (retained)
19:55:15 MQT: homeassistant/switch/sonoff_5/config = (retained)
19:55:15 MQT: homeassistant/light/sonoff_5/config = (retained)
19:55:15 MQT: homeassistant/switch/sonoff_6/config = (retained)
19:55:15 MQT: homeassistant/light/sonoff_6/config = (retained)
19:55:15 MQT: homeassistant/switch/sonoff_7/config = (retained)
19:55:15 MQT: homeassistant/light/sonoff_7/config = (retained)
19:55:15 MQT: homeassistant/switch/sonoff_8/config = (retained)
19:55:16 MQT: homeassistant/light/sonoff_8/config = (retained)
19:55:16 MQT: stat/sonoff/RESULT = {“SetOption19”:“ON”}

No entities are added. This appears to be more than I can figure out. It is a 4CH Pro Sonoff and I get the same results with single channel.

You don’t need the MQTT stuff if using hassio and the MQTT addon. Setting the option on mine they just pop right up provided you have the same user and password in the so off and also in the broker. If you don’t define a local user in the broker then it will use a Home Assistant user. The new addon also auto detects ssl. You need to configure the MQTT integration with the IP address of the broker. Localhost might work but I used 127.0.0.1. You could also use the network IP address for the broker. You configure the username and password for the broker in that integration as well. I added a new user in home assistant that matched the old local user I was using.

As you set core-mosquito I am assuming you are using hassio. If you’re not using hassio then you will need a different broker etc. the instructions above are for hassio

1 Like

Thanks Again David,

I do have everything using the same username and password. I think I have an issue with authentication. With another old addon, I had to add
auth_providers:
- type: homeassistant
to the configuration.yaml. I left it in and haven’t taken all the old additions (nest, hue,…) to configuration.yaml out yet. I’ll go back and try to catch-up on auth stuff.

That auth provider key was depreciated a couple of versions ago.

Hmmm… It is gone from my config now and everything is up to date except MQTT. I kept MQTT 2.0 because it works fine with my switches configured in configuration.yaml. Do you have api_password in your configuration.yaml? Mine is removed.

I remove all traces of MQTT and switches configured to use it from configuration.yaml, update MQTT from 2.0 to 4.0, reboot, go to integrations and see:
MQTT Broker via Hass.io add-on

Do you want to configure Home Assistant to connect to the MQTT broker provided by the hass.io add-on 
Mosquitto broker?

Enable discovery

I click the box to answer yes, and then next and I see:
MQTT Broker via Hass.io add-on

Do you want to configure Home Assistant to connect to the MQTT broker provided by the hass.io add-on 
Mosquitto broker?

Unable to connect to the broker.

Enable discovery

The configuration of MQTT was revised when updating from 2.0 to 4.0, but still has the same username and password as everything else.

1 Like

What is the username?

In the addon settings I am using the absolute defaults and I created a Home Assistant user that used the username and password I setup in my sonoff for MQTT.

I do not have legacy_api in my config.

What did you enter as the broker address in the integration? I used 127.0.0.1 but you could use the IP address or localhost and I entered the user details and checked discovery. Then all I had to do was enable discovery in Tasmota and it picked up my switches right away.

I have reverted back to MQTT 2.0. The username and password are the Hassio owner that I’ve always used for everything including the Sonoffs. I left the broker as core-mosquito, but will try again with 127.0.0.1, localhost or IP of Hassio.
My sonoffs are using 1883 are yours?

In integrations, I had a selection up top called MQTT which gave me the broker connection error earlier. With the integrations I now have MQTT: 127-0.0.1 which was successful. It has no integrations though. I’m on tasmota 6.2.0 or 6.2.1 and can find no discovery option in the web UI. The wiki syas to use SetOption19 On, which I’m trying.

yes I use 1883

ok so you need to use the console and execute SetOption 19 On there
I am now using 6.3 Tasmota firmware

There is/was an error using the ‘discovered MQTT’ in the integration which did give an error however if you select MQTT from the lower list it works. Like I said, I only used 127.0.0.1

I have previously had issues (not with Tasmota/MQTT/Sonoff) and sometime you just use either 127.0.0.1 or localhost or the ip address…

When you set the option you should see the switches in the entity list in dev tools.

Here is my add-on setup:

I did originally have a username and password setup in ligins however I created a new Home Assistant user with the same credentials and deleted it!

Here is a sonoff MQTT config page:

Here is my dev-tools discovered devices:
image

Here is my integration… you see 127.0.0.1

I entered the user I created in there as well as the 127.0.0.1 and checked the checkbox for discovery.


there… you see MQTT-User matches tasmota (well you can’t see that as when you screte a user you can use any name… the 'Name was MQTT-User but the user I created was mqttuser)

As I said before, it worked for me using the local user I had before. The only reason you would be required to make a new user NOW is if your previous user was called homeassistant or addon as these are both reserved usernames now and if you did use one of those you MUST use a new user - either local or home assistant. Just be aware, my reading of the addon document for MQTT seems to indicate that ‘local users are allowed FOR NOW’ which makes me thing it’s safer and easier to just make a home assistant user now.

I have NOTHING in config yaml for MQYY it is not needed with the v3 or v4 addon. I have no MQTT switches configured either. everything is done by mqtt discovery.

I do have discovery: in my config yaml file as originally was told that it is needed for mqtt discovery but I think it isn’t needed - does not matter as I have discovery enabled anyway.

Hope this helps. I was away for a few days and only now on a PC to post all this.

1 Like

After a Hasio reboot, one of my tasmotas showed up in entities, but three others did not. Nothing showed up in the integrations. I’m giving up for now as I understand I’d be doing this after every hassio reboot

you shouldn’t need to restart again.
if discovery is only picking up one switch, did you enable discovery on the others? Nothing shows up in the integration on mine either - says the ntegration has no devices or something like that.
I plugged in a couple of ‘spare’ switches yesterday and the second I enabled discovery (SetOption19 On) it picked them up.