Setup Problems with Sonoff S20

Hello together,

my setup consists of

  • Raspberry Pi 3 with Hassio 063.2
  • Sonoff S20 Smart Socket with Tasmota 5.12.0a

The Sonoff S20 works together with MQTT (Power on/off with mosquitto_pub) but the integration with HA doesn’t work. In the HA Web GUI the Switch is displayed as “unavailable” instead of the expected button to switch the power:

Sonoff S20-1 unavailable

Trying to understand the configuration.yaml files on Github didn’t help to fix the problem. I believe the failure can be found in my configuration.yaml but I don’t get it.

Do you have an idea whats wrong with my setup?

Here are the relevant configuration details:

Sonoff S20

MQTT topic: sons20-1
MQTT full topic: %prefix%/%topic%/

configuration.yaml

# MQTT
mqtt:
  broker: 192.168.1.134
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  username: !secret mqtt_username
  password: !secret mqtt_password
  # protocol: 3.1
  birth_message:
    topic: 'tele/hass1/LWT'
    payload: 'Online'
    qos: 1
    retain: true
  will_message:
    topic: 'tele/hass1/LWT'
    payload: 'Offline'
    qos: 1
    retain: true

# Sonoff S20-1
# https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Features
switch:
  - platform: mqtt
    name: "Sonoff S20-1"
    state_topic: "stat/sons20-1/POWER"
    command_topic: "cmnd/sons20-1/POWER"
    availability_topic: "tele/sons20-1/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: true

Do you have other MQTT devices that already work with Hassio?

Only a Logitech Harmony Hub and a Yamaha Receiver but these devices are discovered automatically.

Please try this configuration:

mqtt:
  broker: core-mosquitto
  client_id: hassio
  username: !secret mqtt_username
  password: !secret mqtt_password

I’ll check this now.

This is all I have for my sonoff.

  - platform: mqtt
    name: Basement Hall Light
    state_topic: "stat/basement_light/POWER"
    command_topic: "cmnd/basement_light/POWER"
    payload_on: "ON"
    payload_off: "OFF"
    retain: true

I made two changes and it works!!! Thanks for you help.

  1. switching to the internal MQTT server (Yevgeny)
  2. stripping the config (RobDYI)

Now I try to change back to Mosquitto and report the result in 5-10 minutes.

Is it really necessary to restart HA (Control-Server Management)? Painfully slow on my PI3…

Regards
Michael

About making changes in the configuration files you can read here:

I have now the following working configuration.yaml

mqtt:
  # broker: core-mosquitto
  # client_id: hassio
  broker: 192.168.1.134
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  username: !secret mqtt_username
  password: !secret mqtt_password
  protocol: 3.1
  birth_message:
    topic: 'tele/hass1/LWT'
    payload: 'Online'
    qos: 1
    retain: true
  will_message:
    topic: 'tele/hass1/LWT'
    payload: 'Offline'
    qos: 1
    retain: true

# Sonoff S20-1
# https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Features
switch:
  - platform: mqtt
    name: "Sonoff S20-1"
    state_topic: "stat/sons20-1/POWER"
    command_topic: "cmnd/sons20-1/POWER"
    # availability_topic: "tele/sons20-1/LWT"
    # qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    # payload_available: "Online"
    # payload_not_available: "Offline"
    retain: true

The console of the Sonoff S20 shows:

15:41:41 MQT: stat/sons20-1/RESULT = {“POWER”:“ON”}
15:41:41 MQT: stat/sons20-1/POWER = ON
15:42:02 MQT: stat/sons20-1/RESULT = {“POWER”:“OFF”}
15:42:02 MQT: stat/sons20-1/POWER = OFF

Restarting the HA GUI shows correctly the last state of the S20 (e.g. ON) so everything seems to work. The difference are now the commented lines in the switch section (4 lines).

The fix was to comment out this two lines:

payload_available: “Online”
payload_not_available: “Offline”

No glue why but anyway it works now. Many thanks for the help!

 - platform: mqtt
    name: "Sonoff S20-1"
    state_topic: "stat/sons20-1/POWER"
    command_topic: "cmnd/sons20-1/POWER"
    availability_topic: "tele/sons20-1/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    # payload_available: "Online"
    # payload_not_available: "Offline"
    retain: true
1 Like