Home Home Automation eWeLink API in NodeRED- why are you silent about your API?

eWeLink API in NodeRED- why are you silent about your API?

We have more options to connect eWeLink devices now!

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.

API?

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.

node-red-contrib-ewelink

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 us.

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.

LAN mode?

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.

In action

To control a eWeLink device you need to get the msg.payload[0].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[0].deviceid but I need to know which device is it. If you look up the msg.payload[0].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 true|false or 1|0. and once injected – you will receive the confirmation that looks like:

{"status":"ok","state":"off"}

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 on|off.

Conclusion

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.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

ESP8266 WIFI lights under $5

0
Your Sonoff device can't do this!

Free wireless doorbell (Amazon Dash button hack)

0
The most terrifying situation I can imagine* is missing a parcel

New Amazon Dash Buttons

0
You can teach new buttons old tricks!

ESP8266 ceiling light – demo

0
Testing the ESP8266 as a WIFI light controller

Try Tasker and Raspberry Pi for your home automation needs!

0
Raspberry Pi can help you with your Tasker profiles

Smart Home

Sonoff Micro PLUS (USB-C hardware mod)

0
Sonoff Micro PLUS is a small modification that adds an USB-C port to Sonoff Micro - to make it even more useful!

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

“Inching” like a PRO (nodeRED edition)

0
Learn how to add inching to anything in NodeRED

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile

Sonoff Micro – IoT switch with more than one secret

0
Sonoff Micro is the smallest member of the ITEAD family and it comes with a secret.