New Component - Sonoff S20 running ESPEasy

I’m pretty new to HA (only just over a week) but my smart home is made up of very cheap plugs and bulbs… I love HA and the ability to expose these cheap devices to Alexa but it was missing one thing… and hopefully this will fill that gap.

It will allow you to turn on, off and query the status of any Sonoff device running ESPEasy.

Any feedback would be welcome.

Note : This component is a modification of the Kankun smart plug component.

4 Likes

Welcome to our community.

Yes, I love the Sonoff devices as well. I use the Tasmota firmware on all of my Sonoff devices…

1 Like

thanks for the welcome :slight_smile:

Would it be worth me making a component for the Tasmota firmware too?

I beleive it accepts HTTP commands for on/off and state so it should be a simple enough change…

i’d need someone to test it though…

1 Like

I use it with my MQTT broker and it works like a charm :slight_smile:

1 Like

Welcome aboard! :slight_smile:

I can test it if you want, but Tasmota firmware already works great with Home Assistant thought MQTT which many of us already use.

1 Like

I would appreciate the feedback if you wouldn’t mind… i appreciate people use MQTT but it’s not something i currently run (although i’m increasingly thinking i may be missing a trick by not using it)

I’ve updated the github to include one for tasmota aswell as espeasy… the only thing i’m not sure on is the state.

If HA can’t see the state, could you issue this http command to one of your switches and paste me the output?

http://sonoffip//cm?cmnd=Power

I’ve not played with MQTT before but it seems i might be missing out on something by not playing with it…

could you give me a noob explanation of what it acheives and how?

thank you for sharing that piece. And by the was is that also compatible with “sonoff Dual”?

Here is a link to a website with some very good explanations of MQTT and how it works.

www.hivemq.com/blog/mqtt-essentials-part-1-introducing-mqtt

MQTT is a lightweight message protocol very well integrated with Home Assistant.

Here’s some more documentation:

I’d imagine it wouldn’t work with the DUAL seeing as it having 2 devices to control…

trying to to test with my S20 but i have an error:

this is my config

- platform: sonoff_tasmota
  switches:
    bedroom:
      host: sonoff.lan
      username: admin
      password: 12345
      name: Kodi TV



Update for switch.kodi_tv fails
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 199, in async_update_ha_state
    yield from self.async_device_update()
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 306, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/switch/sonoff_tasmota.py", line 102, in update
    self._state = self._query_state()
  File "/home/homeassistant/.homeassistant/custom_components/switch/sonoff_tasmota.py", line 81, in _query_state
    return req.json()['state'] == "On"
  File "/srv/homeassistant/lib/python3.6/site-packages/requests/models.py", line 892, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Interested in following this having literally just gotten into these wonderful things, thanks for sharing.

I went Tasmota and MQTT and have to confess I’m not seeing any immediate advantage with a component like this but as I said I’m still very new to it. MQTT is probably the simplest bit of the setup once it suddenly dawns on you what’s going on and it works instantaneously so no obvious advantage in talking directly other than removing the ‘what’s all this then’ part for total newbs.

Obviously the golden goose egg would be a component that directly controls a factory fresh Sonoff which I have read is possible but a long, long way from simple.

1 Like

Ah ok, you have a username and password set… i’ll need to add that bit in… let me look at it and i’ll get back to you.

I still see a benefit on not being depended on another piece of software ‘mosquitto’ to control my sonoff
I like running just Home-Assistant to control all my devices.

I agree, that it is an advantage not to have to rely on another piece of software (or hardware if you run it on another machine / Pi).

In my case I use MQTT for certain other things as well, so I already have a mosquitto server up and running :slight_smile:

I do know what you mean and would usually agree but you seem to be overlooking the fact MQTT is a tried and tested built in component like all the other components your using already, your not adding anything and you’ll never see it unless you want to. To be fair you are if you use the hass.io add-on version but that is kind of the point, you’re putting it into its own secure environment, independent of HA and it’ll keep running until you stop it or pull the plug, not restart every time you tweak your config and restart HA.

I’m not taking anything away from @danmed’s hard work, just need to find the usp for my own use.

Can you grab the file and try again? Usernames and passwords should work… i think i buggered up the syntax…

I have no working knowledge of MQTT and i’m struggling to get my head around it to be honest… that’s why i came up with this…

Obviously it wont suit everyone though :slight_smile:

still not solved, logged in issue at your github page