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

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
Thuis
Posts: 273
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

How to do a simple calculation P=U*I

Post 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.
I Love Domoticz ! And the community around it :-)
User avatar
gizmocuz
Posts: 2551
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

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

Post 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?
Quality outlives Quantity!
User avatar
Thuis
Posts: 273
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post 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.
I Love Domoticz ! And the community around it :-)
User avatar
Thuis
Posts: 273
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post 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.
I Love Domoticz ! And the community around it :-)
User avatar
waltervl
Posts: 5893
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Thuis
Posts: 273
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post 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 :-)
I Love Domoticz ! And the community around it :-)
User avatar
waltervl
Posts: 5893
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
RonkA
Posts: 115
Joined: Tuesday 14 June 2022 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2025.1
Location: Harlingen
Contact:

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

Post by RonkA »

Dont you read your private messages?
SolarEdge ModbusTCP - Kaku - Synology NAS - Watermeter - ESPEasy - DS18b20
Work in progress = Life in general..
Kedi
Posts: 577
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

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

Post 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
Logic will get you from A to B. Imagination will take you everywhere.
User avatar
Thuis
Posts: 273
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post by Thuis »

RonkA wrote: Thursday 13 June 2024 16:32 Dont you read your private messages?
Yes i do 😁
I Love Domoticz ! And the community around it :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest