Sonoff /eWeLink component for original firmware

The .homeassistant directory is the right place.

@peterbuga I’m wondering if you considered using MQTT as an abstraction layer between Sonoff devices and HA? As a point of reference, Tasmota supports MQTT (see: https://github.com/arendst/Sonoff-Tasmota/wiki/MQTT-Overview). Personally I gave up on using HASS and instead I made a few home automation scripts based on MQTT (and currently I use a very simplified version of your code with websockets). I’m sure support for MQTT would be also appreciated by openhab and domoticz communities.

Peter, want to thank you for this. I already had several Sonoffs installed before discovering HA and did not want to pull them all out to flash. This works perfectly for me. I have TH16 showing as a switch and sensors, several basic, two 3Ts and two off brand dimmers that were e-Welink compatable. They work too, only they show as a switch and I have no dimming capability.
Great work and thanks again!

@Contraption_Maker would you be willing to provide some debug data related to the dimmers so i can integrate them also? someone else “complained” about this missing feature but never follow up :unamused:

i’m sure you have your own reasons to give up on HA but the way i see it in order to have kind of MQTT will mean to run some sort of standalone server to do all this tasks and take care of all the publlish/subscribe states.

also i’m not totally a fan of MQTT, does a great job but it’s a lot of manual configuration which i usually try to avoid and this is why this component was born in the first place :tada:

would you be kind enough to share the scripts you have running so far so i can get an idea how are trying to bring MQTT into this picture? (i work better if i see real life examples and this way maybe we can meet halfway) ps: i have literally no idea how it works/never touched openhab/domoticz software so far, HA does and outstanding job :raised_hands:

ya, would be glad to contribute something, just tell me what you need.
If your interested, I have a video of my Lovelace and Floorplan setup here: Share your Floorplan

I’d just like to say your component has been working great, thanks! One thing I’d like that ask though, is it possible to shorten the scan interval some how? I have a basic switch that’s triggered by a Sonoff RF Bridge, and I can’t seem to get the scan interval any lower than 5 seconds or so and have it pick up the state change of my switch. Any lower than that and it doesn’t seem to update the state of the switch at all. If I set it to 5 seconds, I still end up with an 8-10 second delay between my switch being triggered, and HA picking up the event. If I could somehow get it down to even 2 or 3 seconds it would be perfect for what I need!

websocket branch does exactly what you need with instant changes/updates, but i’ve been lazy to move into master
ps: websocket branch it’s not optimized for HA 0.88+ (yet)

I’m on 0.88.1, will the websocket branch work on this version? I tried installing it, and it seems my sonoff entities aren’t being found now for some reason.

EDIT: Nevermind, it seems the ID’s just changed from “Switch.Sonoff_(ID Number)” to “Switch.(ID Number)”.

I think some changes in API, but i see here some users where it work…ok… any logic explanation.

thanks for the great work :slight_smile:
is it possible to change the entity_id of the sonoff ?

@bastienh from what to what? give me an example

to change switch.sonoff_100057d3b9 to switch.bedroom_plug for exemple

right now, no. i could probably add an optional switch to use the name for a device instead its ID, but i find it safer to have unique entity names, who knows what weird setups people might have where the names start overlapping and cause problems.

if you it makes it easier to edit your automations, you could convert/copy your entities and use the prettier names https://www.home-assistant.io/components/switch.template/#copy-switch

great idea, thanks !

Could you help us with tips on how we should fixs our certificates…we are clueless…

only if i knew myself too :persevere: unfortunately ssl related problems are never my strong suit.
if you’re not very technical the best approach would be to start from scratch and (re)install HA in container/virtual env etc as there are many options available

Apologies for the late reply!

I like HASS in principle (and I prefer it over other home automation systems) but I encountered multiple issues with it. I figured I can either overcome them (and keep overcoming new problems with every consecutive update) or I can just make my own tiny system :slight_smile:

Configuring and using MQTT is super easy and quick (at least if you stick with mosquitto as a broker and paho as a Python client). I have the broker (server) on my Raspberry PI, so the automation scripts connect with it locally. I’m new to MQTT myself and so far I only used this plugin: https://github.com/cflurin/xiaomi-mqtt and my own Sonoff integration for T2 switches (based on your plugin, but way more primitive). So far I really like it.

At this stage my automation scripts using MQTT were made in just two nights so they are messy, but maybe at least they’ll help to illustrate how this protocol may be actually used. Other scripts I’m using are not yet ported to MQTT (but I plan on doing it):

Most of my HA scripts are systemd services and they are started at boot and restart automatically if there is a crash.

Hi. @peterbuga Can you advice how to create fan speed toggle for iFan02 in homeassistant. Right now from the 4 switch entity only 2 works, 1 for light, and other one toggle speed to 3. The rest do not work. Can you share the code used for this on home assistant.

@quarx thanks for sharing the scripts :+1:

i have to admit, the MQTT part is not complicated at all but in the same time is hard to ignore the fact that trying to evolve your idea you will inevitably run in HA-like code rules and here’s why: if you want to keep a good device support you/me will have to split the ewelink login/devices part into a separated library (just like HA requires), after that there’s the devices exposing part to MQTT (again, just like HA) and last but not least you need to write some automation with these new toys (sounds familiar?)
i get why you choose to move everything into simpler scripts, i’ve done it the same for a while (before this i was controlling the ewelink devices with Alexa API but i decided to take it up a notch after i discovered HA, because it was too messy and hard to maintain)
also, i’m pretty sure by now someone else already forked this component for openhab and/or domoticz :thinking: if not, i might take it up as a challenge once i’m content enough of the state of current component.