Power Arithmetic plugin

This plugin presents as a power meter device, where the power is computed from a formula.

The formula can contain:

[ul][li]Arithmetic operations + - * /[/li]
[li]Literal numbers[/li]
[li]If-then-else operator comparison ? true-value : false-value[/li]
[li]Comparisons < > <= >= == !=[/li]
[li]Boolean operations and or not[/li]
[li]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).[/li][/ul]

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?

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 ?

Use a formula like:

power(123) + power(456) + power (789)

to add up the power for several independent devices 123, 456 and 789.

Use a formula like:

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:

switch(222) * 1200

if 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:

power(444) >= 100 ? power(444) : 0

if device 444 misreports as low nonzero (less than 100 W) power when it is off, and you would like it to show 0.

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.

cool !
pretty neat plugin u made there :slight_smile:

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.

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!!

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).

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?

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.

(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.)

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.

Awesome, and thankyou muchly for your help! :slight_smile:

Any ideas on another download point?
There's a link to the zip in the first post of this thread.

I’ve submitted the plugin to apps.mios.com so it should be easier for users to install now.

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.

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.

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:

[ul][li]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[/li]
[li]I know that my air conditioner has to work 200 W harder when the front door is open: 1500 + 200 * tripped(99)[/li][/ul]

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

Just wanted to say thank you again. Version .2 works great with the Ping Sensor. Now I’m able to track energy usage of my TV, Computers, etc.

Thank’s to futzle
but 1 question : i have had a new module and in advanced tab set the formula : power(41) + power(42) + power(19)

plug wall fibaro #41, #42, #19

sometimes the result is good, (example 5+8+0=13W), sometimes il is wrong, (for example when the 3 plug are 0W, i noticed it keep 1 plug power before shut down power… , freeze re calculate the formula ?), how to diagnostic the problem in my vera ?

Savonarole, does this happen only when one of more of the power values is exactly zero? (Or, to put it another way, if all three power values are not zero, do you always get the correct sum?)

Hi Futzle,

don’t know, just observed in datamine plugin (graph tab), that these power value (wall plug fibaro), are sometimes not refreshed, (exclamation mark in red), 1 of the 3, that means calculate for example : 2 + 3 + (?) = 2 (probably the first power value, or a last one calculated before …?)

Hi Futzie

I am looking to use this plugin with Datamine to graph my import/export of power between mains and solar PV, unfortunately the watts output from the FORMULA does not appear to be exposed. Anything that I can do?