Page 1 of 1

How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 13:14
by Thuis
Hello, i try to calculate P=U*I, or Idx95*Idx1417=Idx1714 in W or kW.
But i do not seem to get this simple P=U*I to input in a style that dzvents wants.
And i know this is not correct i have the cos phi of the device the blind and the real power bla bla, but i just want the simplest calculation to work. P=U*I
Could someone give me an example of how i can do this in the most simple way in dzvents, or lua is also fine. P=U*I

Thanks in advance.

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 13:45
by gizmocuz
Can you post your dzVents script here?
Sure you can get the value of a Ampere and voltage sensor, and just multiply them and write the value to the console?

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 14:03
by Thuis
I probably think too simple...

Code: Select all

return {
    on = {
    timer = {'every 5 seconds'}
    },
    
 execute = function(dz)	   
local spanning = dz.devices('Voltage') -- Voltage from p1 meter
local stroom = dz.devices('Onshuis_AC - Stroom opname') -- Opname AC via esp AC
local value = dz.devices('Verbruik MHI Airco') -- Virtuele kwh meter

    value = (spanning * stroom)
end
}
I see no errors in the log also the kwh device stays on zero kwh, perhaps im using wrong device to put the value in? No clue.

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 14:50
by Thuis
And ofcourse im reading https://www.domoticz.com/wiki/DzVents:_ ... _scripting but there are lots of calculations about averages, medians, max, min, sum and delta's but no multiply.

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 15:27
by waltervl
dzvents is built on lua so standard arithmic operators apply https://www.lua.org/pil/3.1.html

But to update a kwh device you have to use

Code: Select all

dz.devices('Verbruik MHI Airco').updateEnergy(spanning * stroom)
https://www.domoticz.com/wiki/DzVents:_ ... tric_usage

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 16:16
by Thuis
updateEnergy(energy) Aha.
Ok im doing it wrong its not updating, no errors in log, but ill keep on trying.
Thanks for the steering me in a direction :-)

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 16:24
by waltervl
What you were doing ( value = (spanning * stroom) ) is from a scripting point of view not wrong only it is not doing anything with the device..... That is why you did not get an error.
You never can change a domoticz device with only setting a value. You always have to use a function.

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 16:32
by RonkA
Dont you read your private messages?

Re: How to do a simple calculation P=U*I

Posted: Thursday 13 June 2024 17:06
by Kedi
You also have to use

Code: Select all

 execute = function(dz)	   
local spanning = dz.devices('Voltage').voltage -- Voltage from p1 meter
local stroom = dz.devices('Onshuis_AC - Stroom opname').current -- Opname AC via esp AC

Re: How to do a simple calculation P=U*I  [Solved]

Posted: Thursday 13 June 2024 21:51
by Thuis
RonkA wrote: Thursday 13 June 2024 16:32 Dont you read your private messages?
Yes i do 😁