We have moved at community.getvera.com

Author Topic: Power Arithmetic plugin  (Read 24613 times)

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Power Arithmetic plugin
« on: July 28, 2013, 07:28:14 am »
This plugin presents as a power meter device, where the power is computed from a formula.

The formula can contain:
  • Arithmetic operations + - * /
  • Literal numbers
  • If-then-else operator comparison ? true-value : false-value
  • Comparisons < > <= >= == !=
  • Boolean operations and or not
  • Functions abs(x) (absolute value of x), power(d) (current Watts value of device with ID d), time() (current time as a Unix timestamp), switch(d) (1 if Binary Switch device with ID d is on, 0 if it is off), tripped(d) (1 if Security Sensor device with ID d is tripped, 0 if it is not).

There are four files that need to be transferred to your Vera at Apps > Develop Apps > Luup files, inside the attached zip file.

To create a device, go to Apps > Develop apps > Create Device, put D_PowerArithmetic1.xml as the device filename, and assign the device a name and a room.

To edit the formula, go to the device's Advanced tab and edit the Formula variable.  Save.

I'd like to see how people use this.  There are obviously many more functions to add.  What do you want?
« Last Edit: September 13, 2013, 08:18:26 am by futzle »

Offline Da_JoJo

  • Hero Member
  • *****
  • Posts: 1380
  • Karma: +16/-78
  • If something aint work, we can allways try n make
Re: Power Arithmetic plugin
« Reply #1 on: July 28, 2013, 07:30:49 am »
so this can compute overall power usage ? or can it also be used to say like : when device 10 has used about 2KWH then turn it off ?
Vera lite (1.5.622), 2x an-158/2, dead usb pl2302 rs-232, 2x greenwave 6 port, 4x Fibaro FGD211 v1.6, FGBS001, few FGS - 221, etc. AuthomationHD 3 for android :-)
Dutch & German translator http://wiki.micasaverde.com/index.php/Special:AllPages http://support.micasaverde.com http://domotica-shop.nl

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Power Arithmetic plugin
« Reply #2 on: July 28, 2013, 07:45:05 am »
so this can compute overall power usage ?

Use a formula like:
Code: [Select]
power(123) + power(456) + power (789)to add up the power for several independent devices 123, 456 and 789.

Use a formula like:
Code: [Select]
power(999) - power(123) - power (456)to compute the power difference from a whole-house power device (999) and individual devices 123 and 456, telling you how much power is unaccounted for by unmetered devices in your house.

Use a formula like:
Code: [Select]
switch(222) * 1200if you have device 222 connected to a switch that doesn't have power metering, and you know that it draws 1200 W when it is on.

Use a formula like:
Code: [Select]
power(444) >= 100 ? power(444) : 0if device 444 misreports as low nonzero (less than 100 W) power when it is off, and you would like it to show 0.

can it also be used to say like : when device 10 has used about 2KWH then turn it off ?

That's an interesting idea.  Not yet.  The plugin is only for power (watts), not energy (joules or kWh).  But all power meters are integrated over time by Vera anyway, so you should already be able to do this by monitoring the KWH variable with PLEG.
« Last Edit: July 28, 2013, 08:02:15 am by futzle »

Offline Da_JoJo

  • Hero Member
  • *****
  • Posts: 1380
  • Karma: +16/-78
  • If something aint work, we can allways try n make
Re: Power Arithmetic plugin
« Reply #3 on: July 28, 2013, 09:46:57 am »
cool !
pretty neat plugin u made there :-)
Vera lite (1.5.622), 2x an-158/2, dead usb pl2302 rs-232, 2x greenwave 6 port, 4x Fibaro FGD211 v1.6, FGBS001, few FGS - 221, etc. AuthomationHD 3 for android :-)
Dutch & German translator http://wiki.micasaverde.com/index.php/Special:AllPages http://support.micasaverde.com http://domotica-shop.nl

Offline RichardTSchaefer

  • Community Beta
  • Master Member
  • ******
  • Posts: 10091
  • Karma: +764/-143
Re: Power Arithmetic plugin
« Reply #4 on: July 28, 2013, 02:26:59 pm »
If there were a classes of Virtual Measurements (Power in this case) that had an action to set the value ... This could be all done in PLEG.

PLEG has the ability to pass the value of a computation (Condition/Formula) to a luup.call_action for the Actions associated with the (Condition/Formula).

It can do the math ... but does not have functions ... people have asked for these ... I have hesitated. But for the current supported set of functions ... they are not needed.

In PLEG   Power(x)  would be a variable bound to the Power property of device X.

Offline mrcashback

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +0/-0
Re: Power Arithmetic plugin
« Reply #5 on: July 29, 2013, 12:57:36 am »
This is exactly what I've been looking for thanks!
Now, just having a little trouble implementing it!

First step, I'm wanting it to calculate home energy monitor readings, where the primary monitor is device ID22, and then it has 3x clamps which according to the settings page for each clamp, their id's are E1, E2 and E3, but on the advanced tab are 23, 24, and 25..... I thought I'd put power(23)-power(24)-power(25) to get what I'm after, and at first nothing happened, I tried E1/E2/E3, still nothing, I tried some of the other codes, put in switch(10) which was just a day/night plugin's id, at first nothing happened, but, about an hour later it displayed 3823w ??
Now more confused than ever, I changed it back to the first formula, but nothing changed.

Just to add fuel to the fire, I tried to create a 2nd device (just to add 24+25), but there was no formula field created...

I think I'm in over my head!!

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Power Arithmetic plugin
« Reply #6 on: July 29, 2013, 01:20:46 am »
Are you sure you are not using the Z-Wave node ID numbers and not Vera device ID numbers? Go to the device's Advanced tab, it's at the top left.

Edit: the *names* of the devices, E1 etc., are irrelevant. Don't use them.

Edit edit: test that you've created the device correctly by setting a formula of, say, 42.  Save. If you don't get 42 W showing then you have installed the files wrong, or your device file string was wrong when you created the device. D_PowerArithmetic1.xml (exactly as capitalized, one digit, no leading or trailing spaces).
« Last Edit: July 29, 2013, 01:24:40 am by futzle »

Offline mrcashback

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +0/-0
Re: Power Arithmetic plugin
« Reply #7 on: July 30, 2013, 01:12:55 am »
OK, Cool - got it working  (I was using those numbers in the corner at first, but thought I may have got it wrong when nothing happened so started toying with other numbers)
- turns out I had to restart again to get it to add the formula field, and then restart after entering the formula to get it to start implementing the formula.... AAAND my HEM was not configured right added to the difficulty discovering the issue...

Now, Next on the list (I see some quite usefull potential for this nifty plugin)...

I have a clamp on my house usage, and 1x clamp on each of 2x solar arrays, so have set up 2x virtual devices, one to show me net export/import, and one to show me the total solar production.....  just need to get my formula right, and given I have no idea when it comes to luup, I need to know the correct syntax to bracketise the formula to make sure I get correct calculations?
ie can
power(30) >= 180 ? power(30) : 0
+
power(31) >= 180 ? power(31) : 0

be written something like.... (power(30) >= 180 ? power(30) : 0) + (power(31) >= 180 ? power(31) : 0) to show me total solar output while negating low readings on the clamps

and
Power(29)
-
power(30) >= 180 ? power(30) : 0
+
power(31) >= 180 ? power(31) : 0
as...... power(29) - (power(30) >= 180 ? power(30) : 0) - (power(31) >= 180 ? power(31) : 0) to show me net import or feed in (while negating erronius low readings from the inverters)??

I have it input with brackets as above, and it looks as though its working as it should, but, I couldnt say for sure -  but I presume theres a definite right and wrong way so as not to end up with innacurate calculations in the event of more complex formulae??

Assuming all is right with that part (and we all know the result of assumptions!  :-\ )
taking it a step beyond....... I imagine from here I can activate a third "device" to on/off status as to weather I am importing (if the sum is positive) or exporting (if the sum is negative), which I can then use as part of a sceen to automatically power off un-needed devices if I am importing power? would be cool if I could find a way to triger a red or green image to display on the actual device performing the calculation for at a glance feedback (if its positive or negative) and set another variable on that device itself to 1 or zero accordingly to call upon or trigger other switches/sceens later??

Possible, or no?
« Last Edit: July 30, 2013, 01:19:19 am by mrcashback »

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Power Arithmetic plugin
« Reply #8 on: July 30, 2013, 03:30:01 am »
turns out I had to restart again to get it to add the formula field, and then restart after entering the formula to get it to start implementing the formula....

We call it the Save Dance. You end up pressing that button a lot. Also reloading your browser to clear the cache. It's so ingrained that I didn't explicitly mention it. Sorry.

Quote
(power(30) >= 180 ? power(30) : 0) + (power(31) >= 180 ? power(31) : 0)
...
power(29) - (power(30) >= 180 ? power(30) : 0) - (power(31) >= 180 ? power(31) : 0)

Spot on. (The parentheses are needed, because the ?: operator has really low precedence.)

Quote
I can activate a third "device" to on/off status as to weather I am importing (if the sum is positive) or exporting (if the sum is negative), which I can then use as part of a sceen to automatically power off un-needed devices if I am importing power?

Easy. In fact, you have a choice of how to do it.  Let's say for the sake of argument that you want to turn a light off when you stop exporting (when the formula goes positive).  In all cases you will have a scene that has this light-off action. Just how it is triggered is what changes.

One is to have a trigger for the Arithmetic device, using the event "Power goes over n watts" (paraphrased, I am mobile and can't check the actual wording). Enter a value of zero, or maybe 100 if you want some hysteresis. (Save Dance.) the scene will fire whenever the Arithmetic device power exceeds the threshold.

Two is to use the Combination Switch plugin, and add a condition to it, checking the power of the Arithmetic device. The Combination Switch will turn on when you import, off when you export. You can use this as a trigger for the scene. The advantage over Option One is that you have a handy visual guide to whether you are importing or exporting, one that will also appear in mobile Vera controllers like HomeWave or AutHomation.

Three is to use the Swiss Army Chainsaw of plugins, PLEG (it has its own forum section). It has much more complexity (and hence power) over mere Combination Switches. If you take the time to learn how it works you won't regret it.

Offline mrcashback

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +0/-0
Re: Power Arithmetic plugin
« Reply #9 on: July 30, 2013, 03:52:24 am »
Awesome, and thankyou muchly for your help!  :)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: Power Arithmetic plugin
« Reply #10 on: August 11, 2013, 07:42:55 am »
Quote
Any ideas on another download point?
There's a link to the zip in the first post of this thread.

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Power Arithmetic plugin
« Reply #11 on: August 20, 2013, 05:36:40 pm »
I've submitted the plugin to apps.mios.com so it should be easier for users to install now.

Offline FireBird

  • Jr. Member
  • **
  • Posts: 94
  • Karma: +2/-0
Re: Power Arithmetic plugin
« Reply #12 on: September 12, 2013, 01:12:27 pm »
Love this app by the way, thank you so much for making it! I'm wondering if there is anyway to do a total run time of the devices running? Would make it much easier to calculate daily power usage or even KWH usage for total devices in Vera. I have been thinking about buying the Aeon Labs Home Energy Meter, but after reading about all of the issues people are having with it I'm not sure if I want to waste the $$$ on it.

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Power Arithmetic plugin
« Reply #13 on: September 12, 2013, 06:01:55 pm »
I'm wondering if there is anyway to do a total run time of the devices running? Would make it much easier to calculate daily power usage or even KWH usage for total devices in Vera.

I'd probably do that as a separate plugin so that it can apply to all kinds of power devices and not just Power Arithmetic devices.  There's already some rudimentary support for integrating power over time in the Log variable that LuaUPnP adds to any device that registers Watts; it's how information is sent up to the ERGY service.  I will experiment with piggybacking off that process.

Offline futzle

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3260
  • Karma: +192/-9
Re: Power Arithmetic plugin
« Reply #14 on: September 13, 2013, 08:27:25 am »
Version 0.2 has beet submitted to apps.mios.com, with a new function tripped(d).  This function checks the status of security sensor device d, and returns 1 if device d is tripped, 0 if it is not tripped.

While this function was requested specifically for the Ping Sensor plugin, you could also use it for any other security sensor such as a door or window sensor.

Possible uses:
  • I know that a computer uses 50 W when it is on, so I'll ping it and count 50 W when it is on: tripped(123) * 50
  • I know that my air conditioner has to work 200 W harder when the front door is open: 1500 + 200 * tripped(99)

(Does anyone use this plugin and the Google Calendar plugin?  That might be an interesting combination.)