New WeMo Nodes for Node-RED

Based on my previous playing with a set of Belkin WeMo sockets and lightbulbs I decided to have a go at improving support in Node-RED.

I’ve built 2 new nodes, control and event nodes.

WeMo Control Node
WeMo Control Node

The control node accepts the following values in the msg.payload

  • on/off
  • 1/0
  • true/false
  • A JSON object like this
      state: 'on'
      brightness: 255
      color: '255,0,0'
WeMo Event node
WeMo Event node

The input (event) node now uses uPNP events rather than polling status from the devices every 2 seconds. This means you won’t get the “nc” no change messages but you will get events when lights change brightness or colour as well as on/off messages.

Both nodes use a shared config node that uses uPNP discovery to locate WeMo devices on your local network so you don’t have to work out what IP address and port number they are using.

WeMo Device discovery
WeMo Device discovery

Discovery runs once a minute to ensure all devices are found and any change in IP address or port number are quickly picked up. First discovery may take a little while so please allow a little time if you don’t see all the devices you expect listed when you look in the config node.

All the code is up on github here, I’ll push them to npmjs after people have given them a bit more of a test and I’ll have a chat with the Node-RED guys about maybe swapping out the original WeMo node. There is basic backwards compatibility with the original WeMo node, but the nodes work better if after upgrading you use the configuration dialog to pick a discovered device from the list.

25 thoughts on “New WeMo Nodes for Node-RED”

  1. Leaving a comment to subscribe to follow ups. Please leave a comment when you add this to npm.

    1. I need to find time to roll it into the node-red-nodes package to replace the existing wemo node.

      In the mean time you can install it directly from github with npm:

      npm install hardillb/node-red-contrib-wemo-ng

  2. Man, you did a great job, thank you !
    I’m subscribing too to be notified when it is pushed to the “official” module 🙂

  3. Hi there I have been using the Wemo node-red nodes and they are working great. I do have one problem with the Wemo motion sensor. I wish to send the output which is json thing with state as a boolean and send it to the ui node “chart” which needs a number. If I extract the state and make it a number the chart node still does not accept it.

    Also I noted sometimes my router fails in a strange way and the wemos are lost. After a restart of the router the wemos did not get found so after an hour I restarted the node-red and they were found

    1. If you have bugs please raise them as issues onthe appropriate github project.

      And you’ll do better discussing how things work on the mailing list rather than here

    2. You mention converting the output of the wemo input node configured as a wemo motion sensor… Does that mean that you are getting output from the wemo motion sensor node? I just added a wemo input node to a workflow, but it doesn’t seem to work. I have it connected to a debug node and I get no output when I trigger the motion sensor. What did you have to do to get your motion sensor node to work? Does it give you any output at all?

      1. As mentioned in the other comments, I never had a motion sensor so could never test it. A quick look at the code suggests it just ignores subscriptions from anything not a light or a socket. If you can get me the XML I asked for in the issue I might be able to update it.

        1. Yeah, no problem. I had posted here before I ended up on the repo & posted on the issue. I didn’t even realize the blog and the repo both belonged to the same person. And I was still trying to figure out whether the motion sensor was “supported”. Sorry for the duplicate messages.

  4. Curious if you know the uPNP ports Wemo uses. I can open specific ufw ports, but can’t disable ufw altogether. My NR install isn’t discovering my Wemo devices. Left a DM on Slack as well, so pardon the dupes.

    1. There are 2 separate problems here:

      1. Discovery, this uses SSDP which sends a broadcast UDP packet from which any device can respond. Because it’s UDP it’s stateless so you can’t easily use connection tracking to work out who is responding. The outgoing packet is on port 1900 and responses should come from the same port, but I’m sure I’ve seen cases of random reply source ports. There is supposed to be a iptables plugin to support this, but I’ve never been able to find a system with it enabled. The closest I’ve seen is this
      2. The second problem is the UPnP notifications, these should just be HTTP and will be delivered to the same port that Node-RED is running on, so should be ok as long as you’ve allowed your network access to 1880
  5. Hi Ben. Great work and fascinating things! I am trying to emulate wemo lights using nodejs, as this is an easy way for Alexa/Echo to control devices over the local network without using custom smarthome skills, which already works great for setBinaryState on/off. Now I would like to also add functionality to emulate brightness / dimming. Unfortunately I don’t own any wemo hardware to reverse engineer and also can’t find any information about how the devices announce their capabilities for brightness adjustment to upnp discovery requests. From looking at the sources of various wemo remote control libraries, I guess brightness can be set using a setDeviceStatus call with option 10008 to set brightness of a lamp. Do you happen to have a wemo device which supports dimming? it would be very helpful to see how that device responds to upnp discovery broadcasts. thanks!

    1. You don’t uPnP discover bulbs, you discover the bridge then you need to query the bridge for what bulbs it can see.

      Details about how to discover bulbs is in my other blog post about the wemo control script. When you get the Paired Device list it includes the list of capabilities each device supports.

  6. Looks very interesting and I’m thinking of trying it. Just have a few questions. Does it support the motion sensor as well? And will this stop working in case there is a firmware upgrade pending? I know a python lib I used before had troubles with this and updates are rather frequent with Wemo… 🙁

    1. I don’t have motion sensor so really can’t say. If it uses the basic event notification then it should do. As for firmware updates it’s been working for well over a year for me but who can say what Belkin will change in the future.

  7. I have tried it out now and the output nodes work fine. But it seems that after a while my input node stops working (connected to a motion sensor). I trigger the motion sensor, but doesn’t get anything from the node. The icon says is is connected, but I don’t know if I can get any more debug? Please help me figure this out. I am a developer myself, but I’m not familiar with how node-red debugging is done…

    1. The problem is that the wemos seam to forget the upnp subscription from time to time for no obvious reason. The latest version reduced the time between renewing the subscriptions to renew at about a third of the period before it would expire and it got better, but can sometimes still be flaky. The code should try to subscribe again if the resubscribe fails, but it may miss events in between. It may also be related to if the wemo device drops off the wifi (even very briefly). I’ve tried to debug it but due to how infrequently it happens for me I’ve not got to the bottom of it. The code is all here if you want to have a look.

  8. Firstly, thanks for putting this together.

    Has there been any progress on adding a dimming function for lights?

    The readme outlines JSON object, but mentions it’s coming soon.

    1. Yes, I’ve got an update that adds dimming support and a few other bits. I’ll try and get the pull request to the node-red-nodes project in some time this weekend.

    1. I’m a bit busy with other things at the moment, a pull request to the github project would be likely to be accepted

  9. Hi Ben, have been trying to use your code as a replacement for home automation software like HA and OpenHAB to control/report from my WeMo insight switches.

    One query I have, insights report power usage on the device whenever polled, however your nodes only seem to poll them if there is a state change, so I am unable to refresh the power value to output regularly to a UI element or graph.

    Is there workaround, or a way to trigger the update?

    1. The nodes don’t do any polling, they use the uPnP event mechanism. At the moment the nodes only subscribe to the action events which cover on/off and in the case of the insight moving from standby to active (when a configurable power draw threshold is crossed). As only the insight devices support a different event for power usage it wasn’t implemented and it would be a pretty major change to support it. Feel free to submit a pull request on github if you want to get it working.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.