HomeHome AutomationeWeLink 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

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

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

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

Sonoff R3 DIY mode & why it sucks

0
Long awaited Sonoff R3 DIY mode is even worse than I expected.

IKEA TRADFRI Wireless dimmer in NodeRED

0
Thanks to NodeRED you can use IKEA TRADFRI Wireless Dimmer to interact with everything

Things they don’t tell you about IKEA Trådfri

0
There are things you should know about IKEA Tradfri before you make your purchase

Flashing Tasmota on Sonoff ZigBee Bridge

0
How to flash Tasmota on Sonoff ZigBee Bridge to enable it for NodeRED and Home Assistant

Flashing ESP with Tasmotizer is a dream come true

0
How to flash Tasmota on ESP devices with new Tasmotizer tool

Smart Home

No more hubs: Aqara G2H

0
Aqara G2H brings the power of ZigBee sensors to an IP camera.

Two cool features of Avatar Smart Bulbs

0
Avatar Smart Bulbs come with 2 cool features I wish more smart bulb manufacturers would include in their products.

Shelly 2.5 vs Sonoff DualR3

0
It's time to pitch similar devices against each other and compare their functions: Shelly 2.5 vs Sonoff DualR3

How to flash Tasmota on Sonoff DualR3

0
Make the device yours by flashing Tasmota on Sonoff DualR3. Now with channel control and power consumption

Shelly Duo – going beyond twice

0
Their #ShellyDuo is a WiFi-enabled lightbulb with colour temperature. Plus it comes with 2 features don't often offered by other smart lights.