Page 1 of 1

Energy Counter based on calculation

Posted: Monday 19 December 2016 17:19
by journeyman
Hello


I have some devices connected to domoticz which have still the same energy usage for example 60W when its on.
Is there any existing solution which will give me energy usage / kwh counter depend only on state of this device and time of work? ;)


Thank you :)

Re: Energy Counter based on calculation

Posted: Monday 19 December 2016 20:41
by Toulon7559
You only need some calculationfunction: see http://www.rapidtables.com/convert/elec ... -to-wh.htm
In your case the factor time is the numeric integration of the time that the device is ON.

Re: Energy Counter based on calculation

Posted: Monday 19 December 2016 21:00
by journeyman
I know that but i don't know how to make it with domoticz :)

Re: Energy Counter based on calculation

Posted: Tuesday 20 December 2016 9:32
by Toulon7559
;-) Is a nice exercise related to a lua-script with application of uservariables and display of such uservariable's value!
;-) Challenge: for the realisation look around for examples at internet (starting with this forum)!!

You might use the following general structure (given just as an example, because there are many ways to setup such calcs):
1) make 3 uservariables:
Time_previous_check
On_time
Cumulative_energy
2) make lua-script with (approx.) following contents:
a. Read Time_previous_check
b. Read On_time
c. Read Cumulative_Energy
d. Check actual_systemtime
e. Check whether device is ON
f. if ON then deltaT = (actual_systemtime - Time_previouscheck) else deltaT = 0
g. On_time = On_time + deltaT
h. Cumulative_Energy = Cumulative_Energy + (deltaT) * (Power)
h1 (alternative for h). Cumulative_Energy = On_time * (Power)
i. Time_previous_check = actual_systemtime
j. Save Time_previous_check
k. Save On_time
l. Save Cumulative_Energy
3) make display for On_time and Cumulative_Energy

Very simplistic explanation for the aspect: Why uservariables?
A script internally applies local variables, which are not saved at the end of the script.
Therefore when starting a new run of the script you cannot call back the values of such local variables as existed at the end of the previous run.
Uservariables are stored outside the schript and can be called back as reference.

Re: Energy Counter based on calculation

Posted: Tuesday 20 December 2016 9:38
by journeyman
Thank you very much. Its look more clear now I will try but without programming expreience it will be dificout. But I try

Thanks!

Re: Energy Counter based on calculation

Posted: Tuesday 20 December 2016 10:03
by journeyman
Toulon7559 wrote:3) make display for On_time and Cumulative_Energy
After all with variables how I can to put it to Domoticz virtual device?

Re: Energy Counter based on calculation

Posted: Tuesday 20 December 2016 10:07
by Toulon7559
;-) Just to aid a bit with the exercise.

For reading and writing a uservariable named value1 you can use script-lines like below

-- Get the global uservariables and transfer to local variables
value1 = tonumber(uservariables['value1'])

-- Save the global values
commandArray['Variable:value1'] = tostring(value1)

Energy is expressed as Wh.
Therefore pay attention that in the algorithm you apply Power expressed in W and deltaT expressed in hours.
DeltaT in hours then to be applied as real number, otherwise you are missing resolution.

Re: Energy Counter based on calculation

Posted: Tuesday 20 December 2016 11:14
by journeyman
Toulon7559 wrote:Energy is expressed as Wh.
Therefore pay attention that in the algorithm you apply Power expressed in W and deltaT expressed in hours.
DeltaT in hours then to be applied as real number, otherwise you are missing resolution.
I understand :) But I'm looking for result like this:
2016-12-20_11h12_31.png
2016-12-20_11h12_31.png (10.43 KiB) Viewed 2752 times
Counter with Current uage in W and cumulative weekly, dayly in Wh/kWh with graps etc


Thank you :oops:

Re: Energy Counter based on calculation

Posted: Tuesday 14 February 2017 15:35
by gajotnt
Virtual energy Meters would be awesome. :D