Energy Counter based on calculation

Moderator: leecollings

Post Reply
journeyman
Posts: 23
Joined: Sunday 04 December 2016 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Poland
Contact:

Energy Counter based on calculation

Post 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 :)
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Energy Counter based on calculation

Post 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.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
journeyman
Posts: 23
Joined: Sunday 04 December 2016 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Poland
Contact:

Re: Energy Counter based on calculation

Post by journeyman »

I know that but i don't know how to make it with domoticz :)
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Energy Counter based on calculation

Post 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.
Last edited by Toulon7559 on Tuesday 20 December 2016 10:10, edited 2 times in total.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
journeyman
Posts: 23
Joined: Sunday 04 December 2016 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Poland
Contact:

Re: Energy Counter based on calculation

Post 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!
journeyman
Posts: 23
Joined: Sunday 04 December 2016 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Poland
Contact:

Re: Energy Counter based on calculation

Post 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?
Toulon7559
Posts: 843
Joined: Sunday 23 February 2014 17:56
Target OS: Raspberry Pi / ODroid
Domoticz version: mixed
Location: Hengelo(Ov)/NL
Contact:

Re: Energy Counter based on calculation

Post 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.
Set1 = RPI-Zero+RFXCom433+S0PCM+Shield for BMP180/DS18B20/RS485+DDS238-1ZNs
Set2 = RPI-3A++RFLinkGTW+ESP8266s+PWS_WS7000
Common = KAKUs+3*PVLogger+PWS_TFA_Nexus
plus series of 'satellites' for dedicated interfacing, monitoring & control.
journeyman
Posts: 23
Joined: Sunday 04 December 2016 16:21
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Poland
Contact:

Re: Energy Counter based on calculation

Post 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 2654 times
Counter with Current uage in W and cumulative weekly, dayly in Wh/kWh with graps etc


Thank you :oops:
gajotnt
Posts: 70
Joined: Monday 06 February 2017 12:48
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.9700
Location: Azores
Contact:

Re: Energy Counter based on calculation

Post by gajotnt »

Virtual energy Meters would be awesome. :D
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest