Sonoff basic + tasmota + HA +Mosquito Resolved

I believe have done everything correctly but when I go to home assistant and click the switch it on and turns off within 3 sec’s

configuration.yaml

add mqtt setup

mqtt:
broker: core-mosquitto
username: “devtest”
password: “devtest”

mqtt switches

switch:
platform: mqtt
name: “Sonoff Switch 01”
command_topic: “cmnd/sonoffTT1/power”|
state_topic: “stat/sonoffTT1/POWER”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true

  • and on sonoff tasmota basic r2 running 5.14

MQTT Host 192.168.1.xx
MQTT Port 1883
MQTT Client &
Fallback Topic DVES_0E4108
MQTT User devtest
MQTT Topic sonoffTT1
MQTT Group Topic sonoffs
MQTT Full Topic (cmnd/sonoffTT1/)/
Any assistant would be gratefully appreciated.

I have answered this frequenlty just recently, so I decided to write a faq. Unfortunately, I haven’t had a chance to publish it yet, but perhaps you can try it out

{% linkable_title Switch Button turns back %}

Whenever I press a switch it turns back after a second

This is normally due to the switch not receiving a message with the topic state_topic: to indicate the new state of the switch. The payload of this message must match either the payload_on: or payload_off: parameter.

There are two ways to fix this, depending on your type of switch

Fix the returned status message

This is the ideal solution. The physical switch returns an MQTT message with the topic defined in state_topic: and a payload as defined in payload_on: or payload_off: as appropriate.

To see what message is being sent by the switch, use the tools described in MQTT Testing (such as mqtt_sub) to display all messages being sent to the broker.

If the returned status message has a payload that is formatted in some way (such as in JSON), it can be decoded using a template specified in the value_template: parameter. The result of the template still has to match the payload_on and payload_off parameters.

Set the switch to optimistic

If your physical switch does not return a status message, you can indicate this to Home Assistant by setting the parameter optimistic: true. In this case, Home Assistant does not wait for a response from the switch, so you have no indication that the physical switch actually changed state, which is not ideal.

gpbenton OK I’m confused ( new to Home Assistant + sonoff + tasmota)

I able to connect to mqtt server with mqtt.fx 1.7.0 from my pc which is in the dhcp range 192.168.1.100 -254.

1532107641: New connection from 192.168.1.119 on port 1883.
1532107641: New client connected from 192.168.1.119 as MQTT_FX_Client (c1, k60, u’esp8266’).
1532108014: Client MQTT_FX_Client disconnected.
1532108073: Saving in-memory database to /data/mosquitto.db.

my config

add mqtt setup

mqtt:
broker: core-mosquitto
username: “esp8266”
password: “tasmota”

mqtt switches

switch:
platform: mqtt
name: “Sonoff test”
command_topic: “cmnd/sonoff/power”
state_topic: “stat/sonoff/POWER”
qos: 1
payload_on: “ON”
payload_off: “OFF”
retain: true

***my mqtt looks like
{
“plain”: true,
“plain_websockets”: false,
“ssl”: false,
“ssl_websockets”: false,
“anonymous”: false,
“logins”: [
{
“username”: “esp8266”,
“password”: “tasmota”
}
],
“customize”: {
“active”: false,
“folder”: “mosquitto”
},
“certfile”: “fullchain.pem”,
“keyfile”: “privkey.pem”
}

*** my sonooff is settings is
Program Version 5.14.0
Build Date & Time 2018-05-15T15:29:54
Core/SDK Version 2_3_0/1.5.3(aec24ac9)
Uptime 0T00:16:19
Flash write Count 68 at F8000
Boot Count 46
Restart Reason Software/System restart
Friendly Name 1 Sonoff

AP1 SSId (RSSI) wlan-g (76%)
Hostname TTBasic2
IP Address 192.168.1.62
Gateway 192.168.1.1
Subnet Mask 255.255.255.0
DNS Server 192.168.1.1
MAC Address DC:4F:22:0E:41:08

MQTT Host 192.168.1.49
MQTT Port 1833
MQTT Client &
Fallback Topic DVES_0E4108
MQTT User esp8266
MQTT Topic sonoff
MQTT Group Topic sonoffs
MQTT Full Topic cmnd/sonoff/

Emulation None
mDNS Discovery Enabled
mDNS Advertise Web Server

ESP Chip Id 934152
Flash Chip Id 1327198
Flash Size 1024kB
Program Flash Size 1024kB
Program Size 526kB
Free Program Space 476kB
Free Memory 20kB

but I’m getting
13:50:44 MQT: Attempting connection…
13:50:44 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:50:55 MQT: Attempting connection…
13:50:55 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:51:06 MQT: Attempting connection…
13:51:06 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:51:17 MQT: Attempting connection…
13:51:17 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:51:29 MQT: Attempting connection…
13:51:29 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:51:40 MQT: Attempting connection…
13:51:40 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:51:51 MQT: Attempting connection…
13:51:51 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:52:02 MQT: Attempting connection…
13:52:02 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:52:13 MQT: Attempting connection…
13:52:13 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:52:24 MQT: Attempting connection…
13:52:24 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:52:35 MQT: Attempting connection…
13:52:35 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:52:46 MQT: Attempting connection…
13:52:46 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:52:57 MQT: Attempting connection…
13:52:57 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:53:09 MQT: Attempting connection…
13:53:09 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:53:20 MQT: Attempting connection…
13:53:20 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:53:31 MQT: Attempting connection…
13:53:31 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:53:42 MQT: Attempting connection…
13:53:42 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:53:53 MQT: Attempting connection…
13:53:53 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:54:04 MQT: Attempting connection…
13:54:04 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:54:08 RSL: tele/sonoff/STATE = {“Time”:“2018-07-20T13:54:08”,“Uptime”:“0T00:15:11”,“Vcc”:3.033,“POWER”:“ON”,“Wifi”:{“AP”:1,“SSId”:“wlan-g”,“RSSI”:76,“APMac”:“78:24:AF:D5:40:18”}}
13:54:15 MQT: Attempting connection…
13:54:15 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:54:26 MQT: Attempting connection…
13:54:26 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:54:37 MQT: Attempting connection…
13:54:37 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:54:49 MQT: Attempting connection…
13:54:49 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:55:00 MQT: Attempting connection…
13:55:00 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:55:11 MQT: Attempting connection…
13:55:11 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:55:22 MQT: Attempting connection…
13:55:22 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:55:33 MQT: Attempting connection…
13:55:33 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:55:44 MQT: Attempting connection…
13:55:44 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:55:55 MQT: Attempting connection…
13:55:55 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:56:06 MQT: Attempting connection…
13:56:06 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:56:17 MQT: Attempting connection…
13:56:17 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:56:28 MQT: Attempting connection…
13:56:28 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:56:39 MQT: Attempting connection…
13:56:39 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec
13:56:51 MQT: Attempting connection…
13:56:51 MQT: Connect failed to 192.168.1.49:1833, rc -2. Retry in 10 sec

any assistance is appreciated

Which log is this in? I don’t recognize the format.

sorry for the delay all is working now. The log is a capture from the sonoff console.

I created a new raspberry pi 3 with HA with all new hardware. I built firmware ( atom) with correct ntpserver , mqtt, ssid, password, ip mask, default gateway, and dns, etc. install by espeasy.

1 Like