# Measure the power consumption via a Wemo Insight switch

**URL:** https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288
**Category:** General
**Created:** [17 January 2021 21:40 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288 "2021-01-17T21:40:35Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [17 January 2021 21:40 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/1 "2021-01-17T21:40:36Z")

</div>

Hi folks,

I need to measure power consumption of some of my devices at home. And since I had somewhere an unused brand new _ **Belkin Wemo Insight F7c029 plug** _ lying around, I tried to install it. What a hell... Took me 2 hours, and - after resetting the factory defaults about 12 times - it was finally accessible via the [node/node-red-node-wemo](https://flows.nodered.org/node/node-red-node-wemo) nodes. Major thanks to Dave, Nick and Ben!!!!!!!!!!!!!! Don't know how they managed to implement those nodes, because the official Belkin Android app is still not able to detect and show the damn device 🤬.

Anyway it is working now in Node-RED:

- I can turn the switch on and off.

- I can read the current state:

However this device can also measure the _ **power consumption** _. So I had expected/hoped to have some more information in the output msg (like [here](https://npmdoc.github.io/node-npmdoc-wemo-client/build/apidoc.html#apidoc.element.wemo-client.client.prototype._parseInsightParams)), and not only the binary state of the device:

```auto
binaryState: params[0],
instantPower: params[7],
iinsightParams: {
      ONSince: params[1],
      OnFor: params[2],
      TodayONTime: params[3],
      TodayConsumed: params[8] // power consumer today (mW per minute)
}

```

When looking at the [wemo.js](https://github.com/node-red/node-red-nodes/blob/master/hardware/wemo/lib/wemo.js#L505) it is not clear to me what would be the best/easiest way to add this functionality to this Node-RED node. Does anybody have a tip about which approach I should use?

Thanks !!!  
Bart

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [17 January 2021 22:10 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/2 "2021-01-17T22:10:44Z")

</div>

When I inject a message into the Insight node, a request will be send to the device _ **ONLY** _ to get the binary state of the switch:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6c68ba31e392676a7c5d171e33de485b303a18b.png)

Based on [this](https://chameth.com/monitoring-power-with-wemo/) article, I had hoped to be able to get the power consumption by changing the action via the Chrome debugger:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/5/15e6c99546c0c53e4679500a25de3b8a853743ab.png)

But then then the response contains a soap error 🙄

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [17 January 2021 22:48 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/3 "2021-01-17T22:48:17Z")

</div>

Had forgotton to change other things in the request:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dc3d33def1a4c45b6e8a115d50b93a80d1af772d.png)

And this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/046dc82efd9344bb1aa5f3f5e852519f580a7b4f.png)

But then I still get an Invalid Action response ...

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [17 January 2021 23:17 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/4 "2021-01-17T23:17:59Z")

</div>

My time is up for today. But if I'm not mistaken, [this](https://discourse.nodered.org/t/contribute-improvement-to-node-red-node-wemo-return-insightparams-in-wemolookup/1130) (older) proposal from @jenavarro might have been a solution, if it would have been implemented?

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [18 January 2021 14:01 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/5 "2021-01-18T14:01:34Z")

</div>

Rule number one with these kind of plugs; Get rid of the original firmware and flash them with [Tasmota](https://tasmota.github.io/docs/).

Unfortunately this Belkin plug isn't [Tasmota compatible](https://templates.blakadder.com/plug.html).  
For €10 you can buy on Ali a measuring plug plug with Tasmota pre installed.  
It's not worth the effort to debug wemos.js, however the last is more fun and will give more satisfaction.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [18 January 2021 22:35 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/6 "2021-01-18T22:35:32Z")

</div>

> [@edje11](#):
>
> For €10 you can buy on Ali a measuring plug plug with Tasmota pre installed.

Hi Evert,  
that is interesting. Would appreciate to have some more info about that. But could you please share your info (experiences, links, ...) about those plugs in a new discussion (category "hardware")? Otherwise my developments for the wemo node here will disappear in a large hardware discussion.  
Thanks!

> [@edje11](#):
>
> It's not worth the effort to debug wemos.js, however the last is more fun and will give more satisfaction.

Oh it is absolutely worth the effort. Got two wemo switches a couple of years ago. Never used them, but now I want them to be functional. Otherwise I have thrown away my money ...

Anyway I added a bit of code to the wemo node, and now I get - beside the current state of the switch - a series of statistics about the power consumption 🍾 🥂

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/936f9172fc15d511afa900153727c49f38a03553.png)

Now I will have to test this on my other Wemo switch, which hasn't got a power meter inside. Just to make sure that I don't break existing flows. Hopefully it doesn't take me more time to install that switch, compared to the time that I needed to update the code.

To be continued ...

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [18 January 2021 23:20 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/7 "2021-01-18T23:20:02Z")

</div>

> [@BartButenaers](#):
>
> Now I will have to test this on my other Wemo switch, which hasn't got a power meter inside. Just to make sure that I don't break existing flows.

Damn this node works great. The Belkin app is totally not aware of my second switch, but the wemo node immediately found it:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/c/9c68a9c423b0bbae759dc2777ff2e1fa1fe708fe.png)

However when I call `GetInsightParams` on the classic Wemo Switch (without power meter), it throws an exception. So I should call the original `getSocketStatus` (to only get the current switch status) on those classic switches, like in the original code.

I think I can easily distinguish between both types of switches in the `start` function:

- A classic Wemo Switch (= controllee) is currently mapped to type _ **"socket"** _:

- An Insight Wemo (= insight) is _also_ mapped to the same type _ **"socket"** _:

My time is up for today...

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [19 January 2021 11:51 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/8 "2021-01-19T11:51:00Z")

</div>

> [@BartButenaers](#):
>
> So I think it is better to map those latter devices to type _ **"socket\_insight"** _ .

Quickly implemented this during my lunch break at home ...

At startup the node now detects the correct switch type (insight or classic), and - based on that type - it will only request afterwards the current state or the power consumption as a bonus:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/2448dddc8a7da3e0e25c42e86621e808d499dd3a.png)

@dceejay (and others of course): before I do a pull request tonight, are the power consumption parameters ok (i.e. useful and understandable)?

- `state`: Whether the device is currently ON or OFF (1 or 0)
- `onSince`: The date and time when the device was last turned on or off (as a Unix timestamp)
- `onFor`: How long the device was last ON for (seconds)
- `onToday`: How long the device has been ON today (seconds)
- `onTotal`: How long the device has been ON total (seconds)
- `timespan`: Timespan over which onTotal is relevant (seconds). Typically 2 weeks except when first started up.
- `averagePower`: Average power consumption (Watts)
- `currentPower`: Current power consumption (milliwatts)
- `energyToday`: Energy used today (Watt-hours, or Wh)
- `energyTotal`: Energy used in total (Wh)
- `standbyLimit`: Minimum energy usage to register the insight as switched on ( milliwats, default 8000mW, configurable via WeMo App)

P.S. In case there should be redundant parameters - because the e.g. can be calculated based on other parameters - it would be nice to keep those, for users (like me) that want to keep their flows simple...

Thanks!!

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [19 January 2021 12:12 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/9 "2021-01-19T12:12:06Z")

</div>

Looks good from a really quick look.

It would be good to look at the input node output and seeing if we can make them match up in a backward compatible way. This might mean leaving `msg.payload.state` as the full string and moving the broken out details to under a different key.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [19 January 2021 23:21 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/10 "2021-01-19T23:21:21Z")

</div>

Hi @hardillb, nice that you join this discussion!

I have implemented your change.  
Did I understand it correctly? The output msg of the Input-node now looks like this:

- For a classic _ **Wemo Switch** _:

- For a classic _ **Wemo Insight** _ switch:

I know that backwards compatibility is very important, but the latter message still seems a bit weird to me (although it is now indeed much more aligned with the output of the Lookup-node):

1. There are now two `state` fields, the original as string and mine as number. I used a number, since the Lookup-node already returned a number for the state...
2. The old `power` field contains the same value as my new `currentPower` field, which might be confusing? BTW I have now also converted my `currentPower` field to Watt (instead of milliWatt), since everything else is also expressed in Watt...
3. The `type` is now _"socket\_insight"_ instead of _"socket"_. Perhaps I should use _"socket"_ again in the output message to avoid breaking existing flows?

---

<div class="post-metadata">

### Author: ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)
#### Post date: [20 January 2021 12:59 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/11 "2021-01-20T12:59:31Z")

</div>

There is no need to duplicate any fields, you don't even need the `insightParams` sub object. Everything can live at the `msg.payload` level. Just make sure that the field names and units match when there is overlap.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [20 January 2021 13:10 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/12 "2021-01-20T13:10:19Z")

</div>

though having the insightParams in one block does make it easy to switch on / delete if not required etc - especially if the type does stay as "socket" so you can easily tell them apart later.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [20 January 2021 21:31 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/13 "2021-01-20T21:31:48Z")

</div>

I have now moved everything to the payload, renamed `currentPower` to `power` (for backwards compatibility), and send `type` "socket" instead of "socket\_insight" (for backwards compatibility).

- Input-node:

- Lookup-node:

Now my finger is hanging above the _'submit pull request button'_, to make sure this feature remains a quick win for me 😉

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [21 January 2021 21:07 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/14 "2021-01-21T21:07:56Z")

</div>

For anybody interested in this topic, I have created a [pull request](https://github.com/node-red/node-red-nodes/pull/739).

---

<div class="post-metadata">

### Author: ![Roaders](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/roaders/32/11282_2.png) [@Roaders](https://discourse.nodered.org/u/Roaders)
#### Post date: [24 January 2021 09:54 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/15 "2021-01-24T09:54:14Z")

</div>

Gave up on wemo devices a long time ago. Way more hassle than they are worth!

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [24 January 2021 11:05 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/16 "2021-01-24T11:05:22Z")

</div>

If you have better alternatives, please share which ones and how to read them via Node-RED...

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [24 January 2021 11:14 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/17 "2021-01-24T11:14:01Z")

</div>

I think nowadays I would always recommend the shelly devices.  
They come with mqtt build in and work completely locally.  
I have had only good experiences with them and i am actually in the process of changing my complete setup to shellys.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [24 January 2021 11:28 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/18 "2021-01-24T11:28:52Z")

</div>

Johannes,  
So I assume I could buy a couple of extra [Shelly Plug S](https://shelly.cloud/products/shelly-plug-s-smart-home-automation-device/) devices... Is there a node that I can use to read data from those plugs easily?

---

<div class="post-metadata">

### Author: ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)
#### Post date: [24 January 2021 11:50 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/19 "2021-01-24T11:50:48Z")

</div>

The shelly plug s is great, I think most people here use the very well documented mqtt api with the core mqtt nodes:

[https://shelly-api-docs.shelly.cloud/#shelly-plug-plugs-mqtt](https://shelly-api-docs.shelly.cloud/#shelly-plug-plugs-mqtt)

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [25 March 2021 11:51 UTC](https://discourse.nodered.org/t/measure-the-power-consumption-via-a-wemo-insight-switch/39288/20 "2021-03-25T11:51:46Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
