If it wasn’t for this inexpensive and extremely frustrating to pair unbranded eWeLink 2-way switch, I would never find the API for eWeLink! It takes a pinch of anger, a spoon of frustration and lucky timing, to enter the keywords in Google that will lead you to the revelation you have been looking for for ages.
eWeLink API – kind of…
I will be frank, there is work to be done, but eWeLink has published something that resembles a development guide. It’s a great news for anyone who would like to use eWeLink devices with NodeRED or Home Assistant without flashing the firmware.
Obviously Tasmota is still a very much desired firmware for sonoff devices, but as my journey with this eWeLink unbranded switch shows – this is not always possible.
I don’t have a clue how long this API was available, but the node I’m bout to present is only a couple of months old and works pretty well. While the API aims at developers of other apps, the resources allow to connect to eWeLink account, get information about your linked devices and to take over the control of it.
What’s the benefit of using API over flashing it with Tasmota? You will retain the eWeLink app function, the smart speakers integrations and you will be able to control all eWelink devices from NodeRED and Home Assistant at the same time. Something that was possible before with Shelly devices (Shelly vs Sonoff).
At the moment there is a profound lack of details about how things work, but with a little searching here and there, I was able to figure out controls and set up.
NodeRED and eWeLink API
The best node to use right now is
node-red-contrib-ewelink. If you want to give it a go – install this from palette manager. Before we start, there is a small catch – you will be logged out from your eWeLink app – at the moment the interactions are login based, but I hope that eWeLink will switch to token-based authentication. (UPDATE 11/04/2020: new eWeLink app introduces “deauthorise device” option – which could indicate support for multiple sessions)
The workaround would be to share all devices with another account to use the app and NodeRED at the same time. If you log back in to eWeLink, you will have to re-authenticate the NodeRED config.
This node has it all. I was able to find my RF433 remote linked to the Sonoff RF Bridge (review) as well as the Sonoff Zigbee Bridge (review) and the child device Sonoff Basic R3 Zigbee (review). Whatever you have linked to your eWeLink account will be controllable.
Node instructions are very bare. The configuration will ask you for your eWeLink credentials and region. I’m in the UK and my region is
eu, if you are in the USA – your region can be empty – or use
Controls could use some polish as well. There is a separate node to receive status from the eWeLink device and another one to change that status (why not to merge it into input-output node? But everything works.
I know what’s the next question is going to be – does it work with LAN mode? Not for now. I know it could be a deal-breaker for some, but given time things mat change. From my perspective, a couple of months ago we were not able to control the eWeLink devices outside of the app at all – so this is a step in the right direction. I hope this is not the last step.
To control a eWeLink device you need to get the
msg.payload.deviceid taken from the eWeLink devices node. This ID is used to define each device in other nodes. The device node contains every piece of information you would need about your devices including child devices for Bridges.
There are separate nodes to handle temperature and humidity, power usage and a listener node to monitor changes to individual eWeLink devices. A perfect tool if you want to update the state of the Sonoff.
There is a small delay in execution (less than a second) which isn’t terrible. Let me show you how easy it is to control that unbranded eWeLink 2-way switch I reviewed recently. In any other circumstances, I would not be able to control it from NodeRED
First I need to get the device ID. I know the location is
msg.payload.deviceid but I need to know which device is it. If you look up the
msg.payload.name it will give you the name of the device.
To control the state (on|off) you will need a state node. Fill the node with ID. You will also need the Channel – which I believe is the relay number. For most devices this will be 1 unless you are trying to use something like Sonoff Dual R2.
The state node in this instance takes
on|off|toggle values – sadly no support for
1|0. and once injected – you will receive the confirmation that looks like:
To receive updates from the eWeLink device (as this switch can change the state via wall switch) I need to hook up an event listener node. It’s smart to add the
deviceID to limit the responses to a specific device and add a further filter to decrease the number of payloads. The same info is available from the control node as well – so it’s your choice
The state update is saved in
msg.payload.params.switch and you can update your variables with
Looks like we are one step closer to have a very good solution to take the advantage of eWeLink functions and smart speaker integration and link the devices to our NodeRED server. I know a lot of you want to have LAN mode available, but if you already have eWeLink devices that you can’t flash with Tasmota (hello Tasmotizer) then this is probably the next best thing to play with. Let me know what do you think in this Reddit thread.