New Component - Sonoff S20 running ESPEasy

I’d be glad to try it out…

From what i can tell, i simply add

mqtt:

to my configuration.yaml

from that point on, i’m little lost mainly on the plug settings side of things…

I’m going to have to flash Tasmota to fix this i think…i’ll get back to you.

1 Like

I now understand your confusion, can’t find any concrete info on what you need to do to set the Sonoff up for MQTT using that, it’s appalling documented software.

If you are going to try flashing Tasmota as you suggested to @elRadix let me know because that genuinely is a 30 second job to get MQTT set up then.

The Tasmota wiki will be a breath of fresh air after ESPeasy as it tells you everything you need to know about just about everything and is easy to navigate straight to what you want.

2 Likes

I know it’s easy to setup, but I like having options not being depended on other tools like mqtt.
Direct communication is always better than passing through a middle man.

1 Like

OK, i think i’m configured to flash Tasmota now… but i can’t do it until i get home unfortunately…

Ill let you know how it goes

Lol, again I know what you mean but what exactly do you think this component is :slight_smile:

Anyway, as you can see, my answer was directed to @danmed who is interested in trying it.

Cool, if you want to use the built in component you just need to put…

mqtt:

in your config yaml as you said, if you want to use the hass.io addon instead just install it and start it, then add…

mqtt:
  broker: core-mosquitto

to your config yaml, then add this to your switches or lights…

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

The “sonoff” in the two topic lines lines is what you call the Sonoff in it’s config, either when flashing or in the web interface after, just make sure they match. Adding another just by changing that name.

When you flash it in user_config.h you can prefill the name at #define project, it will default to ‘sonoff’ which is why most people just add a number after for new ones, your wifi ssid at #define STA_SSID1 and password under it at #define STA_PASS1. Scroll down a little bit to the second #define MQTT_HOST and put your Pi’s IP address in. I’ve ringed what you need to change below…

After a successful flash it should just work, nothing else needed, you can tweak the config in the Sonoff’s built in web page if you want to as well as change anything you may have incorrectly entered in the config :slight_smile:

That’s literally it, good luck :+1:

Hey, thanks for this… i got one of my new Sonoffs on Tasmota but i found the response time to the MQTT requests and the basic HTTP requests really slow… in some cases up to 10 seconds response time… i’ve no idea why that would be…

I’ve gone back to ESPEasy and the response times over http are instant again…

Bizarre, my Basics are instantaneous. Really glad your component gets the job done for you, perhaps the S20 is one of the odd not so similar versions.

Possibly.

I’ll probably give it another go some time… but for now i don’t need MQTT… i’m sure i’ll come across a scenario where i do and i’ll be abit more motivated to give it a go.

1 Like

I’ve got 4 of those S20’s and they’re working perfectly with Tasmota firmware and MQTT.

The most important reason is: MQTT doesn’t need to know the ip-address off the device.

Just configure the name and you’re done!

1 Like

Glad it works for you with MQTT… i know the IP’s of all my devices as i set static leases for everything so that’s not a problem for me.

With Bobby_Nobbles pointers I now have got one switch working, but not two at the same time it seems. HA only shows control graphics for Sonoff switch2 currently.

Question that might sort me out. In the configuration.yaml can I do this for two switches.

switch:

  • platform: mqtt
    name: “Sonoff switch1”
    command_topic: “cmnd/sonoff1/power”
    state_topic: “stat/sonoff1/POWER”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true

switch:

  • platform: mqtt
    name: “Sonoff switch2”
    command_topic: “cmnd/sonoff2/power”
    state_topic: “stat/sonoff2/POWER”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true

Is it valid to have two switch: blocks individually, or must I group them under one instance of switch: ?

Nope must be under one. Once you get a bit more into it, follow this doc to tidy things up with separate files for each component group…

Have a read up on groups.yaml too as that is what dictates what shows in the front end and may explain why you can only see one switch…

https://home-assistant.io/docs/configuration/group_visibility/

Cool. That what I needed to do thanks. Actually both those documents didn’t explain it in a way I that could have really worked that out myself. I must be too old for this stuff now…

So my two Sonoff 20’s are now listed and will switch from the HA GUI.

What I’ve found out now though is partly why I had so much trouble. One of the two switches is behaving strangely, it takes 10 seconds or longer to switch outlet from HA, while the other switch is more like half a second very reliably. Also I have real trouble getting into it’s own web GUI, while the other good one is easy (first time every time).
I think the other switch has corrupt settings on the WiFi side or is generally a dud device.

so dumb question i have a switch with ESP_3B1707 do i need to flash it to set it up or is this already esp-easy?

Since deploying them, some of mine are a bit lazy at loading the web interface but switching is still instant.

@Bobby_Nobble

I am trying to get a Sonoff Touch to work using the MQTT broker running on Hass.io
About the MQTT_HOST address…

If I am using Duck DNS then do I still need to use the HA internal IP? or use the DuckDNS url?
Also I am using SSL on Duck DNS. I can only reach hass.io when I use https://hassio.local:8123

Hi

This is my first post here - so Hello everyone :-).

I have Hassbian on Raspberry Pi 2 and Sonoff Basic with Tasmota firmware.
configuration.yaml has:

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

Sonoff is on defaults, the only change is Host set to 10.0.0.7 in MQTT Parameters. Not working with default value ‘domus1’ as well.

Sonoff is visible in HA interface, it chages state to ‘Turned on’ for a 2-3 seconds (actually not toggled becasue I can’t hear the relay ‘click’) and returns to 'Turned Off with no action. It can be toggled by it’s own HTTP interfaces, so I can hear the ‘click’ - I’m sure it is working fine as device.

Tested with mqtt arendst’s Wiki configuration:

mqtt:
   port: 1883
   client_id: home-assistant-1
   keepalive: 60
   protocol: 3.1
   birth_message:
     topic: "tele/sonoff-151/LWT"
     payload: "Online"
     qos: 1
     retain: true
   will_message:
     topic: "tele/sonoff-151/LWT"
     payload: "Offline"
     qos: 1
     retain: true

but behaviour is exactly the same.

2018-02-22 22:25:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1971420752-5, service=turn_on, service_data=entity_id=switch.sonoff151, domain=homeassistant>
2018-02-22 22:25:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1971420752-6, service=turn_on, service_data=entity_id=['switch.sonoff151'], domain=switch>
2018-02-22 22:25:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1971420752-6>
2018-02-22 22:25:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_call_id=1971420752-7, service=publish, service_data=topic=cmnd/sonoff-151/power, retain=True, qos=1, payload=ON, domain=mqtt>
2018-02-22 22:25:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1971420752-5>
2018-02-22 22:25:47 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1971420752-7>
2018-02-22 22:25:47 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1814892176: Sending {'success': True, 'id': 12, 'result': None, 'type': 'result'}
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.broker.plugins.packet_logger_plugin] home-assistant <-in-- PublishPacket(ts=2018-02-22 22:25:47.743196, fixed=MQTTFixedHeader(length=27, flags=0x3), variable=PublishVariableHeader(topic=cmnd/sonoff-151/power, packet_id=3), payload=PublishPayload(data="bytearray(b'ON')"))
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.mqtt.protocol.handler] Add message to delivery
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.mqtt.protocol.handler] Message queue size: 1
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.mqtt.protocol.handler] Delivering message <hbmqtt.session.IncomingApplicationMessage object at 0x5f91c228>
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.broker.plugins.packet_logger_plugin] home-assistant -out-> PubackPacket(ts=2018-02-22 22:25:47.752388, fixed=MQTTFixedHeader(length=2, flags=0x0), variable=PacketIdVariableHeader(packet_id=3), payload=None)
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.broker] home-assistant handling message delivery
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.broker] Retaining message on topic cmnd/sonoff-151/power
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.broker] broadcasting {'topic': 'cmnd/sonoff-151/power', 'session': Session(clientId=home-assistant, state=connected), 'data': bytearray(b'ON')}
2018-02-22 22:25:47 DEBUG (MainThread) [hbmqtt.mqtt.protocol.handler] 0 message(s) available for delivery

Can you help find out what is wrong ?

OK
It is working fine on Hassio with mosquitto, so it was problem specific to Hassbian