Sonoff not working after switching to

I must be missing something obvious, but I can’t get the Sonoff switch that was working with Hassbian to connect to Mosquitto on

Added Mosquitto add-on on Pi3. Copied the configuration.yaml and switches.yaml from Hassbian. Added username and password to Mosquitto through the Hassio dashboard. But, the switch won’t work in HAss. The Sonoff toggles fine when I go to it’s IP address, so it’s still working, but the log there says it never connects to the MQTT server at my.pi’s.ip.address:1883

#commented out sections were in the Hassbian install and I’ve tried with and without them

  broker: #also tried localhost,, and my pi's ip address on the LAN
# port: 1883 
  client_id: home-assistant-1
# username: !secret same_as_Hassbian
# password: !secret Also_same_as_before
  discovery: true
  discovery_prefix: homeassistant

Mosquitto options

  "plain": true,
  "ssl": false,
  "anonymous": true,
  "logins": [
      "username": "same_as_Hassbian",
      "password": "Also_same_as_before"
  "customize": {
    "active": false,
    "folder": "mosquitto"
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"


platform: mqtt
name: "Power Strip"
command_topic: "cmnd/sonoff/power"
state_topic: "stat/sonoff/POWER"
qos: 1
payload_on: "ON"
payload_off: "OFF"
retain: true

The Mosquitto log in the Hassio panel doesn’t mention the Sonoff trying to connect, though the Sonoff console says it’s trying every 10 seconds. If I type my_pi’s_ip_address:1883 into the address bar in my laptop, then the Mosquitto log shows that it tried to connect.

What am I missing?

Has your IP address changed of the MQTT broker (other device)? The IP address of the broker is often hardcoded in the Sonoff switch. If the address has changed than you have to reprogram the Sonoff or you have to change the IP address of the device on which the MQTT broker runs that match the IP address in the Sonoff.

i’m having the same issue, i cannot control anymore my sonoff device even i change the mqtt host to of my devices and reprogram them still i cannot control them. is there anything we are missing?
is there any possibilty to change this to the ip of my raspberry pi like 192.168.0.XX?

My router is set to keep the pi static at the same 192.168.1.x address on the LAN.

My router doesn’t support NAT loopback (Pace 5268ac that AT&T provides with their gigbit service “gigapower”) . Does yours, @macsito07?

On Hassbian with duckdns & letsencrypt I could only connect to HA through https://192.168.1.x when on the LAN and only through when outside of my network, but not through when on the LAN. I had two shortcuts on my phone for when I was on 4G vs WiFi. But with it’s only and not https://192.168.1.x. No idea why that changed.

Could that be related to the Sonoff not connecting to https://192.168.1.x:1883? Of course, my macbook gets spotted in the Mosquitto log when I put https://192.168.1.x:1883, so it seems like other WiFi connected devices should, too, right?

Got it working. Spent hours on it and it turns out I just needed to reboot the router!

The last post reminded me that this router sometimes acts up. It just won’t allow some devices to see each other and then I restart it and everything communicates again. Sometimes I can SSH into the Pi with the desktop but not the laptop, for instance. My laptop could control the Sonoff but my desktop couldn’t even get a response with ping. Pulled the power plug on the router and when it rebooted the Sonoff switch worked in HAss.

So all the setup you did above remain the same? And the your sonoff device use the broker I already tried to restart my router still i can’t control them from hassio.

Darn. I was hoping it was the same problem. I didn’t change any of the above config and didn’t even restart Hasio, just the router. I just thought to try ping from Hassio to my Sonoff and it works with the limited Hassio SSH.

Can you log in through SSH and ping the IP address of your Sonoff? If you get response times at least we know they can see each other on your LAN, right? And, if not, maybe the router is problem like I encountered? Oh, also looking at the Sonoff console to see if it sees any MQTT brokers or gives any relevant messages when it tries to connect every 10 seconds.

Ok i got it working now, :smile:, i found my mistake. Previously before i migrate hassbian to hassio, my devices were connected to the ip of my wifi raspberry pi and now the wifi of my rpi is inactive as of now so i update them to LAN ip. Thanks.

1 Like