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

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

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

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

Smart Home

Remotes aren’t done with us yet: SwitchBot Remote

0
If you hate having 20 remotes hidden in your sofa, or your parents despise talking to Alexa to turn the lights on - SwitchBot Universal Remote is here to deal with all this!

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?